2014-05-07 22:51:01 +04:00
|
|
|
#ifndef coord_hh_INCLUDED
|
|
|
|
#define coord_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "units.hh"
|
2011-09-17 18:13:33 +04:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-10-11 02:41:48 +04:00
|
|
|
template<typename EffectiveType, typename LineType, typename ColumnType>
|
2011-09-17 18:13:33 +04:00
|
|
|
struct LineAndColumn
|
|
|
|
{
|
2012-10-11 02:41:48 +04:00
|
|
|
LineType line;
|
|
|
|
ColumnType column;
|
2011-09-17 18:13:33 +04:00
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2012-10-11 02:41:48 +04:00
|
|
|
constexpr LineAndColumn(LineType line = 0, ColumnType column = 0)
|
2011-09-17 18:13:33 +04:00
|
|
|
: line(line), column(column) {}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr EffectiveType operator+(EffectiveType other) const
|
2011-09-17 18:13:33 +04:00
|
|
|
{
|
|
|
|
return EffectiveType(line + other.line, column + other.column);
|
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
EffectiveType& operator+=(EffectiveType other)
|
2011-09-17 18:13:33 +04:00
|
|
|
{
|
|
|
|
line += other.line;
|
|
|
|
column += other.column;
|
2011-09-20 01:55:58 +04:00
|
|
|
return *static_cast<EffectiveType*>(this);
|
2011-09-17 18:13:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr EffectiveType operator-(EffectiveType other) const
|
2011-09-17 18:13:33 +04:00
|
|
|
{
|
2011-10-15 08:42:28 +04:00
|
|
|
return EffectiveType(line - other.line, column - other.column);
|
2011-09-17 18:13:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
EffectiveType& operator-=(EffectiveType other)
|
2011-09-17 18:13:33 +04:00
|
|
|
{
|
2011-10-15 08:42:28 +04:00
|
|
|
line -= other.line;
|
|
|
|
column -= other.column;
|
2011-09-20 01:55:58 +04:00
|
|
|
return *static_cast<EffectiveType*>(this);
|
2011-09-17 18:13:33 +04:00
|
|
|
}
|
2011-10-15 08:42:28 +04:00
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr bool operator< (EffectiveType other) const
|
2011-10-15 08:42:28 +04:00
|
|
|
{
|
2012-09-05 01:54:10 +04:00
|
|
|
return (line != other.line) ? line < other.line
|
|
|
|
: column < other.column;
|
2011-10-15 08:42:28 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr bool operator<= (EffectiveType other) const
|
2011-10-15 08:42:28 +04:00
|
|
|
{
|
2012-09-05 01:54:10 +04:00
|
|
|
return (line != other.line) ? line < other.line
|
|
|
|
: column <= other.column;
|
2011-10-15 08:42:28 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr bool operator> (EffectiveType other) const
|
2012-03-21 18:13:26 +04:00
|
|
|
{
|
2012-09-05 01:54:10 +04:00
|
|
|
return (line != other.line) ? line > other.line
|
|
|
|
: column > other.column;
|
2012-03-21 18:13:26 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr bool operator>= (EffectiveType other) const
|
2012-03-21 18:13:26 +04:00
|
|
|
{
|
2012-09-05 01:54:10 +04:00
|
|
|
return (line != other.line) ? line > other.line
|
|
|
|
: column >= other.column;
|
2012-03-21 18:13:26 +04:00
|
|
|
}
|
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr bool operator== (EffectiveType other) const
|
2011-10-15 08:42:28 +04:00
|
|
|
{
|
|
|
|
return line == other.line and column == other.column;
|
|
|
|
}
|
2012-03-21 18:13:26 +04:00
|
|
|
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 02:44:00 +04:00
|
|
|
constexpr bool operator!= (EffectiveType other) const
|
2012-03-21 18:13:26 +04:00
|
|
|
{
|
|
|
|
return line != other.line or column != other.column;
|
|
|
|
}
|
2011-09-17 18:13:33 +04:00
|
|
|
};
|
|
|
|
|
2014-05-07 22:51:01 +04:00
|
|
|
struct ByteCoord : LineAndColumn<ByteCoord, LineCount, ByteCount>
|
|
|
|
{
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2014-05-07 22:51:01 +04:00
|
|
|
constexpr ByteCoord(LineCount line = 0, ByteCount column = 0)
|
|
|
|
: LineAndColumn(line, column) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CharCoord : LineAndColumn<CharCoord, LineCount, CharCount>
|
|
|
|
{
|
2014-05-17 13:17:28 +04:00
|
|
|
[[gnu::always_inline]]
|
2014-05-07 22:51:01 +04:00
|
|
|
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
|
|
|
|
: LineAndColumn(line, column) {}
|
|
|
|
};
|
|
|
|
|
2011-09-17 18:13:33 +04:00
|
|
|
}
|
|
|
|
|
2014-05-07 22:51:01 +04:00
|
|
|
#endif // coord_hh_INCLUDED
|