DynamicBufferIterator: use const_cast instead of having a mutable field in Buffer

This commit is contained in:
Maxime Coste 2011-11-28 18:55:17 +00:00
parent 46a01b5a0b
commit 51ee0b61f4
3 changed files with 7 additions and 7 deletions

View File

@ -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(),

View File

@ -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<BufferModificationListener*> m_modification_listeners;
std::vector<BufferModificationListener*> m_modification_listeners;
};
}

View File

@ -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&>(buffer()).register_modification_listener(this);
}
void DynamicBufferIterator::unregister_ifn()
{
if (is_valid())
buffer().unregister_modification_listener(this);
const_cast<Buffer&>(buffer()).unregister_modification_listener(this);
}
}