Enable more invariant checking in selection lists

This commit is contained in:
Maxime Coste 2015-08-03 11:23:40 +01:00
parent d49f48afe0
commit d19df5d5de

View File

@ -17,21 +17,28 @@ void Selection::merge_with(const Selection& range)
SelectionList::SelectionList(Buffer& buffer, Selection s, size_t timestamp) SelectionList::SelectionList(Buffer& buffer, Selection s, size_t timestamp)
: m_buffer(&buffer), m_selections({ std::move(s) }), m_timestamp(timestamp) : m_buffer(&buffer), m_selections({ std::move(s) }), m_timestamp(timestamp)
{} {
check_invariant();
}
SelectionList::SelectionList(Buffer& buffer, Selection s) SelectionList::SelectionList(Buffer& buffer, Selection s)
: SelectionList(buffer, std::move(s), buffer.timestamp()) : SelectionList(buffer, std::move(s), buffer.timestamp())
{} {
check_invariant();
}
SelectionList::SelectionList(Buffer& buffer, Vector<Selection> s, size_t timestamp) SelectionList::SelectionList(Buffer& buffer, Vector<Selection> s, size_t timestamp)
: m_buffer(&buffer), m_selections(std::move(s)), m_timestamp(timestamp) : m_buffer(&buffer), m_selections(std::move(s)), m_timestamp(timestamp)
{ {
kak_assert(size() > 0); kak_assert(size() > 0);
check_invariant();
} }
SelectionList::SelectionList(Buffer& buffer, Vector<Selection> s) SelectionList::SelectionList(Buffer& buffer, Vector<Selection> s)
: SelectionList(buffer, std::move(s), buffer.timestamp()) : SelectionList(buffer, std::move(s), buffer.timestamp())
{} {
check_invariant();
}
namespace namespace
{ {
@ -371,6 +378,13 @@ void SelectionList::check_invariant() const
auto& buffer = this->buffer(); auto& buffer = this->buffer();
kak_assert(size() > 0); kak_assert(size() > 0);
kak_assert(m_main < size()); kak_assert(m_main < size());
const size_t timestamp = buffer.timestamp();
kak_assert(timestamp >= m_timestamp);
// cannot check further in that case
if (timestamp != m_timestamp)
return;
for (size_t i = 0; i < size(); ++i) for (size_t i = 0; i < size(); ++i)
{ {
auto& sel = (*this)[i]; auto& sel = (*this)[i];