ccls/src/position.h

58 lines
1.3 KiB
C
Raw Normal View History

2017-04-05 08:06:18 +00:00
#pragma once
#include "maybe.h"
#include "utils.h"
2017-05-19 07:02:01 +00:00
#include <stdint.h>
#include <string>
2017-04-05 08:06:18 +00:00
struct Position {
int16_t line = -1;
int16_t column = -1;
2017-04-05 08:06:18 +00:00
static Position FromString(const std::string& encoded);
2017-04-05 08:06:18 +00:00
bool Valid() const { return line >= 0; }
2017-04-05 08:06:18 +00:00
std::string ToString();
// Compare two Positions and check if they are equal. Ignores the value of
// |interesting|.
bool operator==(const Position& o) const {
return line == o.line && column == o.column;
}
bool operator<(const Position& o) const {
if (line != o.line)
return line < o.line;
return column < o.column;
}
2017-04-05 08:06:18 +00:00
};
MAKE_HASHABLE(Position, t.line, t.column);
2017-04-05 08:06:18 +00:00
struct Range {
Position start;
Position end;
static Range FromString(const std::string& encoded);
2017-04-05 08:06:18 +00:00
bool Valid() const { return start.Valid(); }
bool Contains(int line, int column) const;
Range RemovePrefix(Position position) const;
2017-04-05 08:06:18 +00:00
std::string ToString();
bool operator==(const Range& o) const {
return start == o.start && end == o.end;
}
bool operator<(const Range& o) const {
return !(start == o.start) ? start < o.start : end < o.end;
}
2017-05-19 07:02:01 +00:00
};
// Reflection
class Reader;
class Writer;
2017-05-19 07:02:01 +00:00
void Reflect(Reader& visitor, Position& value);
void Reflect(Writer& visitor, Position& value);
void Reflect(Reader& visitor, Range& value);
void Reflect(Writer& visitor, Range& value);