From 834e2d2fe3d9a67497dd34e6551e80df90c00458 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 29 Sep 2011 09:10:27 +0000 Subject: [PATCH] DisplayBuffer: check_invariant method to assert atoms consistency --- src/display_buffer.cc | 12 +++++++++++- src/display_buffer.hh | 2 ++ src/window.cc | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/display_buffer.cc b/src/display_buffer.cc index 03cc5b18..0865211a 100644 --- a/src/display_buffer.cc +++ b/src/display_buffer.cc @@ -1,6 +1,6 @@ #include "display_buffer.hh" -#include "assert.h" +#include "assert.hh" namespace Kakoune { @@ -22,4 +22,14 @@ DisplayBuffer::iterator DisplayBuffer::split(iterator atom, size_t pos_in_atom) return insert(atom, std::move(new_atom)); } +void DisplayBuffer::check_invariant() const +{ + for (size_t i = 0; i < m_atoms.size(); ++i) + { + assert(m_atoms[i].end > m_atoms[i].begin); + if (i > 0) + assert(m_atoms[i-1].end == m_atoms[i].begin); + } +} + } diff --git a/src/display_buffer.hh b/src/display_buffer.hh index e422e38a..62b4731c 100644 --- a/src/display_buffer.hh +++ b/src/display_buffer.hh @@ -75,6 +75,8 @@ public: const_iterator begin() const { return m_atoms.begin(); } const_iterator end() const { return m_atoms.end(); } + + void check_invariant() const; private: AtomList m_atoms; }; diff --git a/src/window.cc b/src/window.cc index e94394c9..122767ee 100644 --- a/src/window.cc +++ b/src/window.cc @@ -309,7 +309,10 @@ void Window::update_display_buffer() m_display_buffer.append(DisplayAtom(begin, end, m_buffer.string(begin, end))); for (auto& filter : m_filters) + { filter(m_display_buffer); + m_display_buffer.check_invariant(); + } } void Window::set_dimensions(const WindowCoord& dimensions)