From 34c9b0d30fe157b52b302a71e2ef73ceba86fab0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 17 Sep 2011 14:13:33 +0000 Subject: [PATCH] =?UTF-8?q?LineAndColumn:=20move=20to=20it's=20own=20heade?= =?UTF-8?q?r=20and=20add=20operator[+-]=3D=3F?= LineAndColumn is now a template so that WindowCoords and BufferCoords cannot be added together. --- src/buffer.cc | 1 + src/buffer.hh | 4 ++-- src/display_buffer.cc | 5 ----- src/display_buffer.hh | 4 ---- src/line_and_column.hh | 43 ++++++++++++++++++++++++++++++++++++++++++ src/utils.hh | 9 --------- src/window.hh | 4 ++-- 7 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 src/line_and_column.hh 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 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 #include -#include "utils.hh" +#include "line_and_column.hh" namespace Kakoune { @@ -19,7 +19,7 @@ typedef int BufferSize; typedef char BufferChar; typedef std::basic_string BufferString; -struct BufferCoord : LineAndColumn +struct BufferCoord : LineAndColumn { 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 #include -#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 +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 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 -#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(int line = 0, int column = 0) : LineAndColumn(line, column) {}