diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-03-31 13:49:56 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-03-31 14:53:32 +0200 |
| commit | 22c34b79f6e41fbb755c5b8cf8ae16b85c0b13bc (patch) | |
| tree | e57a892f9782cb6e517a625beb1ef07e677a1771 /src/dynamic_selection_list.cc | |
| parent | dbbe455eb1ccc9985c3c4965d0f96859242d9d88 (diff) | |
Move change listener registration to BufferChangeListener_AutoRegister
DynamicSelectionList now just inherit from this class, so that
the registration logic can be shared.
Diffstat (limited to 'src/dynamic_selection_list.cc')
| -rw-r--r-- | src/dynamic_selection_list.cc | 50 |
1 files changed, 4 insertions, 46 deletions
diff --git a/src/dynamic_selection_list.cc b/src/dynamic_selection_list.cc index bca16293..a258ddd7 100644 --- a/src/dynamic_selection_list.cc +++ b/src/dynamic_selection_list.cc @@ -5,55 +5,12 @@ namespace Kakoune DynamicSelectionList::DynamicSelectionList(const Buffer& buffer, SelectionList selections) - : m_buffer(&buffer), SelectionList(std::move(selections)) + : SelectionList(std::move(selections)), + BufferChangeListener_AutoRegister(buffer) { - m_buffer->change_listeners().insert(this); check_invariant(); } -DynamicSelectionList::~DynamicSelectionList() -{ - m_buffer->change_listeners().erase(this); -} - -DynamicSelectionList::DynamicSelectionList(const DynamicSelectionList& other) - : SelectionList(other), m_buffer(other.m_buffer) -{ - m_buffer->change_listeners().insert(this); -} - -DynamicSelectionList& DynamicSelectionList::operator=(const DynamicSelectionList& other) -{ - SelectionList::operator=((const SelectionList&)other); - if (m_buffer != other.m_buffer) - { - m_buffer->change_listeners().erase(this); - m_buffer = other.m_buffer; - m_buffer->change_listeners().insert(this); - } - check_invariant(); - return *this; -} - -DynamicSelectionList::DynamicSelectionList(DynamicSelectionList&& other) - : SelectionList(std::move(other)), m_buffer(other.m_buffer) -{ - m_buffer->change_listeners().insert(this); -} - -DynamicSelectionList& DynamicSelectionList::operator=(DynamicSelectionList&& other) -{ - SelectionList::operator=(std::move(other)); - if (m_buffer != other.m_buffer) - { - m_buffer->change_listeners().erase(this); - m_buffer = other.m_buffer; - m_buffer->change_listeners().insert(this); - } - check_invariant(); - return *this; -} - DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections) { SelectionList::operator=(std::move(selections)); @@ -64,9 +21,10 @@ DynamicSelectionList& DynamicSelectionList::operator=(SelectionList selections) void DynamicSelectionList::check_invariant() const { #ifdef KAK_DEBUG + const Buffer* buf = &buffer(); for (auto& sel : *this) { - assert(m_buffer == &sel.buffer()); + assert(buf == &sel.buffer()); sel.check_invariant(); } #endif |
