From 51ee0b61f4b477768135f7427ffc3ed6ca061420 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 28 Nov 2011 18:55:17 +0000 Subject: [PATCH] DynamicBufferIterator: use const_cast instead of having a mutable field in Buffer --- src/buffer.cc | 4 ++-- src/buffer.hh | 6 +++--- src/dynamic_buffer_iterator.cc | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index 33f2ae3b..81e63b95 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -249,14 +249,14 @@ void Buffer::notify_saved() m_last_save_undo_index = history_cursor_index; } -void Buffer::register_modification_listener(BufferModificationListener* listener) const +void Buffer::register_modification_listener(BufferModificationListener* listener) { assert(listener); assert(not contains(m_modification_listeners, listener)); m_modification_listeners.push_back(listener); } -void Buffer::unregister_modification_listener(BufferModificationListener* listener) const +void Buffer::unregister_modification_listener(BufferModificationListener* listener) { assert(listener); auto it = std::find(m_modification_listeners.begin(), diff --git a/src/buffer.hh b/src/buffer.hh index be0e0d47..35572a2d 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -146,8 +146,8 @@ public: Type type() const { return m_type; } void notify_saved(); - void register_modification_listener(BufferModificationListener* listener) const; - void unregister_modification_listener(BufferModificationListener* listener) const; + void register_modification_listener(BufferModificationListener* listener); + void unregister_modification_listener(BufferModificationListener* listener); private: BufferChar at(BufferPos position) const; @@ -180,7 +180,7 @@ private: size_t m_last_save_undo_index; - mutable std::vector m_modification_listeners; + std::vector m_modification_listeners; }; } diff --git a/src/dynamic_buffer_iterator.cc b/src/dynamic_buffer_iterator.cc index 42c9d39c..fac3cd39 100644 --- a/src/dynamic_buffer_iterator.cc +++ b/src/dynamic_buffer_iterator.cc @@ -59,13 +59,13 @@ void DynamicBufferIterator::on_modification(const BufferModification& modificati void DynamicBufferIterator::register_ifp() { if (is_valid()) - buffer().register_modification_listener(this); + const_cast(buffer()).register_modification_listener(this); } void DynamicBufferIterator::unregister_ifn() { if (is_valid()) - buffer().unregister_modification_listener(this); + const_cast(buffer()).unregister_modification_listener(this); } }