summaryrefslogtreecommitdiff
path: root/src/display_buffer.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-04-23 21:38:45 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-04-23 21:38:45 +0100
commit045272ab8a0448281b017633c0d2794c3d61c177 (patch)
tree36b35e6acccfabae47c9c2d4c4c2d21f0fa31c84 /src/display_buffer.hh
parent840e58e0b1d3ca977a411b3d048009eff5f4bdd5 (diff)
Use a struct for BufferRange rather than std::pair
Diffstat (limited to 'src/display_buffer.hh')
-rw-r--r--src/display_buffer.hh26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/display_buffer.hh b/src/display_buffer.hh
index 9f0e0fb7..35381058 100644
--- a/src/display_buffer.hh
+++ b/src/display_buffer.hh
@@ -2,6 +2,7 @@
#define display_buffer_hh_INCLUDED
#include "face.hh"
+#include "hash.hh"
#include "coord.hh"
#include "string.hh"
#include "vector.hh"
@@ -10,6 +11,18 @@ namespace Kakoune
{
class Buffer;
+struct BufferRange{ ByteCoord begin, end; };
+
+inline bool operator==(const BufferRange& lhs, const BufferRange& rhs)
+{
+ return lhs.begin == rhs.begin and lhs.end == rhs.end;
+}
+
+inline
+size_t hash_value(const BufferRange& range)
+{
+ return hash_values(range.begin, range.end);
+}
struct DisplayAtom : public UseMemoryDomain<MemoryDomain::Display>
{
@@ -17,7 +30,7 @@ public:
enum Type { BufferRange, ReplacedBufferRange, Text };
DisplayAtom(const Buffer& buffer, ByteCoord begin, ByteCoord end)
- : m_type(BufferRange), m_buffer(&buffer), m_begin(begin), m_end(end)
+ : m_type(BufferRange), m_buffer(&buffer), m_range{begin, end}
{ check_invariant(); }
DisplayAtom(String str, Face face = Face{})
@@ -30,13 +43,13 @@ public:
const ByteCoord& begin() const
{
kak_assert(has_buffer_range());
- return m_begin;
+ return m_range.begin;
}
const ByteCoord& end() const
{
kak_assert(has_buffer_range());
- return m_end;
+ return m_range.end;
}
void replace(String text)
@@ -62,7 +75,8 @@ public:
bool operator==(const DisplayAtom& other) const
{
- return face == other.face and content() == other.content();
+ return face == other.face and type() == other.type() and
+ content() == other.content();
}
public:
@@ -74,12 +88,10 @@ private:
Type m_type;
const Buffer* m_buffer = nullptr;
- ByteCoord m_begin;
- ByteCoord m_end;
+ Kakoune::BufferRange m_range;
String m_text;
};
-using BufferRange = std::pair<ByteCoord, ByteCoord>;
using AtomList = Vector<DisplayAtom>;
class DisplayLine : public UseMemoryDomain<MemoryDomain::Display>