make Buffer::{add,remove}_change_listener const and the listener list mutable

This commit is contained in:
Maxime Coste 2012-11-12 20:11:27 +01:00
parent 489621cf58
commit 77272db0fd
3 changed files with 9 additions and 9 deletions

View File

@ -415,13 +415,13 @@ void Buffer::notify_saved()
m_last_save_undo_index = history_cursor_index;
}
void Buffer::add_change_listener(BufferChangeListener& listener)
void Buffer::add_change_listener(BufferChangeListener& listener) const
{
assert(not contains(m_change_listeners, &listener));
m_change_listeners.push_back(&listener);
}
void Buffer::remove_change_listener(BufferChangeListener& listener)
void Buffer::remove_change_listener(BufferChangeListener& listener) const
{
auto it = std::find(m_change_listeners.begin(),
m_change_listeners.end(),

View File

@ -156,8 +156,8 @@ public:
// notify the buffer that it was saved in the current state
void notify_saved();
void add_change_listener(BufferChangeListener& listener);
void remove_change_listener(BufferChangeListener& listener);
void add_change_listener(BufferChangeListener& listener) const;
void remove_change_listener(BufferChangeListener& listener) const;
// returns an iterator pointing to the first character of the line
// iterator is on
@ -224,7 +224,9 @@ private:
size_t m_last_save_undo_index;
size_t m_timestamp;
std::vector<BufferChangeListener*> m_change_listeners;
// this mutable as adding or removing listeners is not muting the buffer
// observable state.
mutable std::vector<BufferChangeListener*> m_change_listeners;
OptionManager m_option_manager;
HookManager m_hook_manager;

View File

@ -86,14 +86,12 @@ void Selection::on_erase(const BufferIterator& begin, const BufferIterator& end)
void Selection::register_with_buffer()
{
Buffer& buffer = const_cast<Buffer&>(m_first.buffer());
buffer.add_change_listener(*this);
m_first.buffer().add_change_listener(*this);
}
void Selection::unregister_with_buffer()
{
Buffer& buffer = const_cast<Buffer&>(m_first.buffer());
buffer.remove_change_listener(*this);
m_first.buffer().remove_change_listener(*this);
}
void Selection::check_invariant() const