2011-09-17 16:13:33 +02:00
|
|
|
#ifndef line_and_column_hh_INCLUDED
|
|
|
|
#define line_and_column_hh_INCLUDED
|
|
|
|
|
2012-08-22 23:33:52 +02:00
|
|
|
#include "units.hh"
|
|
|
|
|
2011-09-17 16:13:33 +02:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename EffectiveType>
|
|
|
|
struct LineAndColumn
|
|
|
|
{
|
2012-08-22 23:33:52 +02:00
|
|
|
LineCount line;
|
2012-08-23 23:56:35 +02:00
|
|
|
CharCount column;
|
2011-09-17 16:13:33 +02:00
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr LineAndColumn(LineCount line = 0, CharCount column = 0)
|
2011-09-17 16:13:33 +02:00
|
|
|
: line(line), column(column) {}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr EffectiveType operator+(const EffectiveType& other) const
|
2011-09-17 16:13:33 +02:00
|
|
|
{
|
|
|
|
return EffectiveType(line + other.line, column + other.column);
|
|
|
|
}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr EffectiveType& operator+=(const 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
|
|
|
}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr EffectiveType operator-(const EffectiveType& other) const
|
2011-09-17 16:13:33 +02:00
|
|
|
{
|
2011-10-15 06:42:28 +02:00
|
|
|
return EffectiveType(line - other.line, column - other.column);
|
2011-09-17 16:13:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EffectiveType& operator-=(const EffectiveType& other)
|
|
|
|
{
|
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
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr bool operator< (const EffectiveType& other) const
|
2011-10-15 06:42:28 +02:00
|
|
|
{
|
2012-09-04 23:54:10 +02:00
|
|
|
return (line != other.line) ? line < other.line
|
|
|
|
: column < other.column;
|
2011-10-15 06:42:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr bool operator<= (const EffectiveType& other) const
|
2011-10-15 06:42:28 +02:00
|
|
|
{
|
2012-09-04 23:54:10 +02:00
|
|
|
return (line != other.line) ? line < other.line
|
|
|
|
: column <= other.column;
|
2011-10-15 06:42:28 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr bool operator> (const EffectiveType& other) const
|
2012-03-21 15:13:26 +01:00
|
|
|
{
|
2012-09-04 23:54:10 +02:00
|
|
|
return (line != other.line) ? line > other.line
|
|
|
|
: column > other.column;
|
2012-03-21 15:13:26 +01:00
|
|
|
}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr bool operator>= (const EffectiveType& other) const
|
2012-03-21 15:13:26 +01:00
|
|
|
{
|
2012-09-04 23:54:10 +02:00
|
|
|
return (line != other.line) ? line > other.line
|
|
|
|
: column >= other.column;
|
2012-03-21 15:13:26 +01:00
|
|
|
}
|
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr bool operator== (const 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
|
|
|
|
2012-09-04 23:54:10 +02:00
|
|
|
constexpr bool operator!= (const EffectiveType& other) const
|
2012-03-21 15:13:26 +01:00
|
|
|
{
|
|
|
|
return line != other.line or column != other.column;
|
|
|
|
}
|
2011-09-17 16:13:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // line_and_column_hh_INCLUDED
|