mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Position.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <mutable/util/fn.hpp>
5#include <iostream>
6#include <sstream>
7
8
9namespace m {
10
12{
13 const char *name;
14 unsigned line;
15 unsigned column;
16
17 explicit Position(const char *name)
18 : name(name)
19 , line(0)
20 , column(0)
21 { }
22
23 explicit Position(const char *name, const size_t line, const size_t column)
24 : name(name)
25 , line(line)
26 , column(column)
27 { }
28
29 bool operator==(Position other) const {
30 return streq(this->name, other.name) and this->line == other.line and this->column == other.column;
31 }
32 bool operator!=(Position other) const { return not operator==(other); }
33
35 friend std::string to_string(const Position &pos) {
36 std::ostringstream os;
37 os << pos;
38 return os.str();
39 }
40
41 friend std::ostream & operator<<(std::ostream &os, const Position &pos) {
42 return os << pos.name << ":" << pos.line << ":" << pos.column;
43 }
44
45 void dump(std::ostream &out) const { out << *this << std::endl; }
46 void dump() const;
48};
49
50}
‍mutable namespace
Definition: Backend.hpp:10
bool streq(const char *first, const char *second)
Definition: fn.hpp:29
and
Definition: enum_ops.hpp:12
Position(const char *name)
Definition: Position.hpp:17
void dump(std::ostream &out) const
Definition: Position.hpp:45
bool operator==(Position other) const
Definition: Position.hpp:29
unsigned line
Definition: Position.hpp:14
M_LCOV_EXCL_START friend std::string to_string(const Position &pos)
Definition: Position.hpp:35
bool operator!=(Position other) const
Definition: Position.hpp:32
void dump() const
Definition: Position.cpp:7
unsigned column
Definition: Position.hpp:15
friend std::ostream & operator<<(std::ostream &os, const Position &pos)
Definition: Position.hpp:41
Position(const char *name, const size_t line, const size_t column)
Definition: Position.hpp:23
const char * name
Definition: Position.hpp:13