home/src/line_and_column.hh

78 lines
2.0 KiB
C++
Raw Normal View History

#ifndef line_and_column_hh_INCLUDED
#define line_and_column_hh_INCLUDED
namespace Kakoune
{
template<typename EffectiveType, typename LineType, typename ColumnType>
struct LineAndColumn
{
LineType line;
ColumnType column;
constexpr LineAndColumn(LineType line = 0, ColumnType column = 0)
: line(line), column(column) {}
2013-07-26 00:44:00 +02:00
constexpr EffectiveType operator+(EffectiveType other) const
{
return EffectiveType(line + other.line, column + other.column);
}
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);
}
2013-07-26 00:44:00 +02:00
constexpr EffectiveType operator-(EffectiveType other) const
{
return EffectiveType(line - other.line, column - other.column);
}
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);
}
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;
}
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;
}
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;
}
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;
}
2013-07-26 00:44:00 +02:00
constexpr bool operator== (EffectiveType other) const
{
return line == other.line and column == other.column;
}
2013-07-26 00:44:00 +02:00
constexpr bool operator!= (EffectiveType other) const
{
return line != other.line or column != other.column;
}
};
}
#endif // line_and_column_hh_INCLUDED