2014-05-07 20:51:01 +02:00
|
|
|
#ifndef coord_hh_INCLUDED
|
|
|
|
#define coord_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "units.hh"
|
2014-12-16 19:57:19 +01:00
|
|
|
#include "hash.hh"
|
2011-09-17 16:13:33 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2012-10-11 00:41:48 +02:00
|
|
|
template<typename EffectiveType, typename LineType, typename ColumnType>
|
2011-09-17 16:13:33 +02:00
|
|
|
struct LineAndColumn
|
|
|
|
{
|
2017-09-01 12:21:50 +02:00
|
|
|
LineType line = 0;
|
|
|
|
ColumnType column = 0;
|
2011-09-17 16:13:33 +02:00
|
|
|
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 00:44:00 +02:00
|
|
|
constexpr EffectiveType operator+(EffectiveType other) const
|
2011-09-17 16:13:33 +02:00
|
|
|
{
|
2015-03-05 14:52:54 +01:00
|
|
|
return {line + other.line, column + other.column};
|
2011-09-17 16:13:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 00:44:00 +02:00
|
|
|
EffectiveType& operator+=(EffectiveType other)
|
2011-09-17 16:13:33 +02:00
|
|
|
{
|
|
|
|
line += other.line;
|
|
|
|
column += other.column;
|
2011-09-19 23:55:58 +02:00
|
|
|
return *static_cast<EffectiveType*>(this);
|
2011-09-17 16:13:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 00:44:00 +02:00
|
|
|
constexpr EffectiveType operator-(EffectiveType other) const
|
2011-09-17 16:13:33 +02:00
|
|
|
{
|
2015-03-05 14:52:54 +01:00
|
|
|
return {line - other.line, column - other.column};
|
2011-09-17 16:13:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 00:44:00 +02:00
|
|
|
EffectiveType& operator-=(EffectiveType other)
|
2011-09-17 16:13:33 +02:00
|
|
|
{
|
2011-10-15 06:42:28 +02:00
|
|
|
line -= other.line;
|
|
|
|
column -= other.column;
|
2011-09-19 23:55:58 +02:00
|
|
|
return *static_cast<EffectiveType*>(this);
|
2011-09-17 16:13:33 +02:00
|
|
|
}
|
2011-10-15 06:42:28 +02:00
|
|
|
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2020-11-14 22:57:19 +01:00
|
|
|
constexpr auto operator<=> (EffectiveType other) const
|
2011-10-15 06:42:28 +02:00
|
|
|
{
|
2020-11-14 22:57:19 +01:00
|
|
|
return (line != other.line) ? line <=> other.line
|
|
|
|
: column <=> other.column;
|
2012-03-21 15:13:26 +01:00
|
|
|
}
|
|
|
|
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2013-07-26 00:44:00 +02:00
|
|
|
constexpr bool operator== (EffectiveType other) const
|
2011-10-15 06:42:28 +02:00
|
|
|
{
|
|
|
|
return line == other.line and column == other.column;
|
|
|
|
}
|
2012-03-21 15:13:26 +01:00
|
|
|
|
2017-10-17 16:45:17 +02:00
|
|
|
friend constexpr size_t hash_value(const EffectiveType& val)
|
2015-03-11 14:59:25 +01:00
|
|
|
{
|
|
|
|
return hash_values(val.line, val.column);
|
|
|
|
}
|
2011-09-17 16:13:33 +02:00
|
|
|
};
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
struct BufferCoord : LineAndColumn<BufferCoord, LineCount, ByteCount>
|
2014-05-07 20:51:01 +02:00
|
|
|
{
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr BufferCoord(LineCount line = 0, ByteCount column = 0)
|
2017-09-01 12:21:50 +02:00
|
|
|
: LineAndColumn{line, column} {}
|
2014-05-07 20:51:01 +02:00
|
|
|
};
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
struct DisplayCoord : LineAndColumn<DisplayCoord, LineCount, ColumnCount>
|
2014-05-07 20:51:01 +02:00
|
|
|
{
|
2014-05-17 11:17:28 +02:00
|
|
|
[[gnu::always_inline]]
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr DisplayCoord(LineCount line = 0, ColumnCount column = 0)
|
2017-09-01 12:21:50 +02:00
|
|
|
: LineAndColumn{line, column} {}
|
2016-08-06 10:05:50 +02:00
|
|
|
|
|
|
|
static constexpr const char* option_type_name = "coord";
|
2014-05-07 20:51:01 +02:00
|
|
|
};
|
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
struct BufferCoordAndTarget : BufferCoord
|
2014-09-09 20:35:54 +02:00
|
|
|
{
|
|
|
|
[[gnu::always_inline]]
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr BufferCoordAndTarget(LineCount line = 0, ByteCount column = 0, ColumnCount target = -1)
|
2017-09-01 12:21:50 +02:00
|
|
|
: BufferCoord{line, column}, target{target} {}
|
2014-09-09 20:35:54 +02:00
|
|
|
|
|
|
|
[[gnu::always_inline]]
|
2016-09-22 21:36:26 +02:00
|
|
|
constexpr BufferCoordAndTarget(BufferCoord coord, ColumnCount target = -1)
|
2017-09-01 12:21:50 +02:00
|
|
|
: BufferCoord{coord}, target{target} {}
|
2014-09-09 20:35:54 +02:00
|
|
|
|
2016-09-22 21:36:26 +02:00
|
|
|
ColumnCount target;
|
2014-09-09 20:35:54 +02:00
|
|
|
};
|
|
|
|
|
2017-10-17 16:45:17 +02:00
|
|
|
constexpr size_t hash_value(const BufferCoordAndTarget& val)
|
2014-12-16 19:57:19 +01:00
|
|
|
{
|
|
|
|
return hash_values(val.line, val.column, val.target);
|
|
|
|
}
|
|
|
|
|
2011-09-17 16:13:33 +02:00
|
|
|
}
|
|
|
|
|
2014-05-07 20:51:01 +02:00
|
|
|
#endif // coord_hh_INCLUDED
|