From d48a2bd32584b3de815b691ac3adb0554281650c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 17 Oct 2011 22:05:06 +0000 Subject: [PATCH] BufferIterator: move methods implementation to buffer_iterator.inl.h --- src/buffer.cc | 116 ---------------------------------- src/buffer.hh | 4 ++ src/buffer_iterator.inl.h | 127 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 116 deletions(-) create mode 100644 src/buffer_iterator.inl.h diff --git a/src/buffer.cc b/src/buffer.cc index e1ea7f6b..1ea5b571 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -20,122 +20,6 @@ T clamp(T min, T max, T val) return val; } -BufferIterator::BufferIterator(const Buffer& buffer, BufferPos position) : m_buffer(&buffer), - m_position(std::max(0, std::min(position, (BufferPos)buffer.length()))) -{ -} - -const Buffer& BufferIterator::buffer() const -{ - assert(m_buffer); - return *m_buffer; -} - -BufferIterator& BufferIterator::operator=(const BufferIterator& iterator) -{ - m_buffer = iterator.m_buffer; - m_position = iterator.m_position; -} - -bool BufferIterator::operator==(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return (m_position == iterator.m_position); -} - -bool BufferIterator::operator!=(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return (m_position != iterator.m_position); -} - -bool BufferIterator::operator<(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return (m_position < iterator.m_position); -} - -bool BufferIterator::operator<=(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return (m_position <= iterator.m_position); -} - -bool BufferIterator::operator>(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return (m_position > iterator.m_position); -} - -bool BufferIterator::operator>=(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return (m_position >= iterator.m_position); -} - -BufferChar BufferIterator::operator*() const -{ - assert(m_buffer); - return m_buffer->at(m_position); -} - -BufferSize BufferIterator::operator-(const BufferIterator& iterator) const -{ - assert(m_buffer == iterator.m_buffer); - return static_cast(m_position) - - static_cast(iterator.m_position); -} - -BufferIterator BufferIterator::operator+(BufferSize size) const -{ - assert(m_buffer); - return BufferIterator(*m_buffer, m_position + size); -} - -BufferIterator BufferIterator::operator-(BufferSize size) const -{ - assert(m_buffer); - return BufferIterator(*m_buffer, m_position - size); -} - -BufferIterator& BufferIterator::operator+=(BufferSize size) -{ - assert(m_buffer); - m_position = std::max(0, std::min((BufferSize)m_position + size, - m_buffer->length())); - return *this; -} - -BufferIterator& BufferIterator::operator-=(BufferSize size) -{ - assert(m_buffer); - m_position = std::max(0, std::min((BufferSize)m_position - size, - m_buffer->length())); - return *this; -} - -BufferIterator& BufferIterator::operator++() -{ - return (*this += 1); -} - -BufferIterator& BufferIterator::operator--() -{ - return (*this -= 1); -} - -bool BufferIterator::is_begin() const -{ - assert(m_buffer); - return m_position == 0; -} - -bool BufferIterator::is_end() const -{ - assert(m_buffer); - return m_position == m_buffer->length(); -} - Buffer::Buffer(const std::string& name, Type type, const BufferString& initial_content) : m_name(name), m_type(type), diff --git a/src/buffer.hh b/src/buffer.hh index d860b9d4..84526b42 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -171,8 +171,12 @@ private: std::list> m_windows; std::vector::iterator m_last_save_undo_group; + + std::vector m_modification_listeners; }; } +#include "buffer_iterator.inl.h" + #endif // buffer_hh_INCLUDED diff --git a/src/buffer_iterator.inl.h b/src/buffer_iterator.inl.h new file mode 100644 index 00000000..db59a8b4 --- /dev/null +++ b/src/buffer_iterator.inl.h @@ -0,0 +1,127 @@ +#ifndef buffer_iterator_inl_h_INCLUDED +#define buffer_iterator_inl_h_INCLUDED + +#include "assert.hh" + +namespace Kakoune +{ + +inline BufferIterator::BufferIterator(const Buffer& buffer, BufferPos position) + : m_buffer(&buffer), + m_position(std::max(0, std::min(position, (BufferPos)buffer.length()))) +{ +} + +inline const Buffer& BufferIterator::buffer() const +{ + assert(m_buffer); + return *m_buffer; +} + +inline BufferIterator& BufferIterator::operator=(const BufferIterator& iterator) +{ + m_buffer = iterator.m_buffer; + m_position = iterator.m_position; + return *this; +} + +inline bool BufferIterator::operator==(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return (m_position == iterator.m_position); +} + +inline bool BufferIterator::operator!=(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return (m_position != iterator.m_position); +} + +inline bool BufferIterator::operator<(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return (m_position < iterator.m_position); +} + +inline bool BufferIterator::operator<=(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return (m_position <= iterator.m_position); +} + +inline bool BufferIterator::operator>(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return (m_position > iterator.m_position); +} + +inline bool BufferIterator::operator>=(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return (m_position >= iterator.m_position); +} + +inline BufferChar BufferIterator::operator*() const +{ + assert(m_buffer); + return m_buffer->at(m_position); +} + +inline BufferSize BufferIterator::operator-(const BufferIterator& iterator) const +{ + assert(m_buffer == iterator.m_buffer); + return m_position - iterator.m_position; +} + +inline BufferIterator BufferIterator::operator+(BufferSize size) const +{ + assert(m_buffer); + return BufferIterator(*m_buffer, m_position + size); +} + +inline BufferIterator BufferIterator::operator-(BufferSize size) const +{ + assert(m_buffer); + return BufferIterator(*m_buffer, m_position - size); +} + +inline BufferIterator& BufferIterator::operator+=(BufferSize size) +{ + assert(m_buffer); + m_position = std::max(0, std::min((BufferSize)m_position + size, + m_buffer->length())); + return *this; +} + +inline BufferIterator& BufferIterator::operator-=(BufferSize size) +{ + assert(m_buffer); + m_position = std::max(0, std::min((BufferSize)m_position - size, + m_buffer->length())); + return *this; +} + +inline BufferIterator& BufferIterator::operator++() +{ + return (*this += 1); +} + +inline BufferIterator& BufferIterator::operator--() +{ + return (*this -= 1); +} + +inline bool BufferIterator::is_begin() const +{ + assert(m_buffer); + return m_position == 0; +} + +inline bool BufferIterator::is_end() const +{ + assert(m_buffer); + return m_position == m_buffer->length(); +} + +} +#endif // buffer_iterator_inl_h_INCLUDED