LineAndColumn: move to it's own header and add operator[+-]=?
LineAndColumn is now a template so that WindowCoords and BufferCoords cannot be added together.
This commit is contained in:
parent
49fce28dec
commit
34c9b0d30f
|
@ -3,6 +3,7 @@
|
|||
#include "buffer_manager.hh"
|
||||
#include "window.hh"
|
||||
#include "assert.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "utils.hh"
|
||||
#include "line_and_column.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ typedef int BufferSize;
|
|||
typedef char BufferChar;
|
||||
typedef std::basic_string<BufferChar> BufferString;
|
||||
|
||||
struct BufferCoord : LineAndColumn
|
||||
struct BufferCoord : LineAndColumn<BufferCoord>
|
||||
{
|
||||
BufferCoord(int line = 0, int column = 0)
|
||||
: LineAndColumn(line, column) {}
|
||||
|
|
|
@ -7,9 +7,4 @@ DisplayBuffer::DisplayBuffer()
|
|||
{
|
||||
}
|
||||
|
||||
LineAndColumn DisplayBuffer::dimensions() const
|
||||
{
|
||||
return LineAndColumn();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "buffer.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
|
@ -36,8 +34,6 @@ public:
|
|||
|
||||
DisplayBuffer();
|
||||
|
||||
LineAndColumn dimensions() const;
|
||||
|
||||
void clear() { m_atoms.clear(); }
|
||||
void append(const DisplayAtom& atom) { m_atoms.push_back(atom); }
|
||||
|
||||
|
|
43
src/line_and_column.hh
Normal file
43
src/line_and_column.hh
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef line_and_column_hh_INCLUDED
|
||||
#define line_and_column_hh_INCLUDED
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
template<typename EffectiveType>
|
||||
struct LineAndColumn
|
||||
{
|
||||
int line;
|
||||
int column;
|
||||
|
||||
LineAndColumn(int line = 0, int column = 0)
|
||||
: line(line), column(column) {}
|
||||
|
||||
EffectiveType operator+(const EffectiveType& other) const
|
||||
{
|
||||
return EffectiveType(line + other.line, column + other.column);
|
||||
}
|
||||
|
||||
EffectiveType& operator+=(const EffectiveType& other)
|
||||
{
|
||||
line += other.line;
|
||||
column += other.column;
|
||||
return *this;
|
||||
}
|
||||
|
||||
EffectiveType operator-(const EffectiveType& other) const
|
||||
{
|
||||
return EffectiveType(line + other.line, column + other.column);
|
||||
}
|
||||
|
||||
EffectiveType& operator-=(const EffectiveType& other)
|
||||
{
|
||||
line += other.line;
|
||||
column += other.column;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // line_and_column_hh_INCLUDED
|
|
@ -8,15 +8,6 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
struct LineAndColumn
|
||||
{
|
||||
int line;
|
||||
int column;
|
||||
|
||||
LineAndColumn(int line = 0, int column = 0)
|
||||
: line(line), column(column) {}
|
||||
};
|
||||
|
||||
template<typename Container>
|
||||
struct ReversedContainer
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#include "utils.hh"
|
||||
#include "line_and_column.hh"
|
||||
|
||||
#include "buffer.hh"
|
||||
#include "display_buffer.hh"
|
||||
|
@ -11,7 +11,7 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
struct WindowCoord : LineAndColumn
|
||||
struct WindowCoord : LineAndColumn<WindowCoord>
|
||||
{
|
||||
WindowCoord(int line = 0, int column = 0)
|
||||
: LineAndColumn(line, column) {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user