kakoune/src/coord.hh

118 lines
3.1 KiB
C++
Raw Normal View History

#ifndef coord_hh_INCLUDED
#define coord_hh_INCLUDED
#include "units.hh"
namespace Kakoune
{
template<typename EffectiveType, typename LineType, typename ColumnType>
struct LineAndColumn
{
LineType line;
ColumnType column;
[[gnu::always_inline]]
constexpr LineAndColumn(LineType line = 0, ColumnType column = 0)
: line(line), column(column) {}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr EffectiveType operator+(EffectiveType other) const
{
return EffectiveType(line + other.line, column + other.column);
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
EffectiveType& operator+=(EffectiveType other)
{
line += other.line;
column += other.column;
2011-09-19 23:55:58 +02:00
return *static_cast<EffectiveType*>(this);
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr EffectiveType operator-(EffectiveType other) const
{
return EffectiveType(line - other.line, column - other.column);
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
EffectiveType& operator-=(EffectiveType other)
{
line -= other.line;
column -= other.column;
2011-09-19 23:55:58 +02:00
return *static_cast<EffectiveType*>(this);
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr bool operator< (EffectiveType other) const
{
2012-09-04 23:54:10 +02:00
return (line != other.line) ? line < other.line
: column < other.column;
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr bool operator<= (EffectiveType other) const
{
2012-09-04 23:54:10 +02:00
return (line != other.line) ? line < other.line
: column <= other.column;
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr bool operator> (EffectiveType other) const
{
2012-09-04 23:54:10 +02:00
return (line != other.line) ? line > other.line
: column > other.column;
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr bool operator>= (EffectiveType other) const
{
2012-09-04 23:54:10 +02:00
return (line != other.line) ? line > other.line
: column >= other.column;
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr bool operator== (EffectiveType other) const
{
return line == other.line and column == other.column;
}
[[gnu::always_inline]]
2013-07-26 00:44:00 +02:00
constexpr bool operator!= (EffectiveType other) const
{
return line != other.line or column != other.column;
}
};
struct ByteCoord : LineAndColumn<ByteCoord, LineCount, ByteCount>
{
[[gnu::always_inline]]
constexpr ByteCoord(LineCount line = 0, ByteCount column = 0)
: LineAndColumn(line, column) {}
};
struct CharCoord : LineAndColumn<CharCoord, LineCount, CharCount>
{
[[gnu::always_inline]]
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
: LineAndColumn(line, column) {}
};
struct ByteCoordAndTarget : ByteCoord
{
[[gnu::always_inline]]
constexpr ByteCoordAndTarget(LineCount line = 0, ByteCount column = 0, CharCount target = -1)
: ByteCoord(line, column), target(target) {}
[[gnu::always_inline]]
constexpr ByteCoordAndTarget(ByteCoord coord, CharCount target = -1)
: ByteCoord(coord), target(target) {}
CharCount target;
};
}
#endif // coord_hh_INCLUDED