diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-09-17 14:13:33 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-09-17 14:13:33 +0000 |
| commit | 34c9b0d30fe157b52b302a71e2ef73ceba86fab0 (patch) | |
| tree | 313788609d3de768d2b5e5bab86ea2861cf64688 /src | |
| parent | 49fce28dec18cb5b0af3e169e3b2ef31b99a6aa6 (diff) | |
LineAndColumn: move to it's own header and add operator[+-]=?
LineAndColumn is now a template so that WindowCoords and BufferCoords
cannot be added together.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer.cc | 1 | ||||
| -rw-r--r-- | src/buffer.hh | 4 | ||||
| -rw-r--r-- | src/display_buffer.cc | 5 | ||||
| -rw-r--r-- | src/display_buffer.hh | 4 | ||||
| -rw-r--r-- | src/line_and_column.hh | 43 | ||||
| -rw-r--r-- | src/utils.hh | 9 | ||||
| -rw-r--r-- | src/window.hh | 4 |
7 files changed, 48 insertions, 22 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 1997cf81..2adb1b2c 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -3,6 +3,7 @@ #include "buffer_manager.hh" #include "window.hh" #include "assert.hh" +#include "utils.hh" #include <algorithm> diff --git a/src/buffer.hh b/src/buffer.hh index 67b374e1..a45c68ea 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -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) {} diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 8a033318..ea5342bc 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -7,9 +7,4 @@ DisplayBuffer::DisplayBuffer() { } -LineAndColumn DisplayBuffer::dimensions() const -{ - return LineAndColumn(); -} - } diff --git a/src/display_buffer.hh b/src/display_buffer.hh index bde04bed..37c5cbfc 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -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); } diff --git a/src/line_and_column.hh b/src/line_and_column.hh new file mode 100644 index 00000000..fb09223b --- /dev/null +++ b/src/line_and_column.hh @@ -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 diff --git a/src/utils.hh b/src/utils.hh index 5b219b2e..5f6e93a5 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -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 { diff --git a/src/window.hh b/src/window.hh index 4c8a3243..f134cb71 100644 --- a/src/window.hh +++ b/src/window.hh @@ -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) {} |
