BufferIterator: move methods implementation to buffer_iterator.inl.h

This commit is contained in:
Maxime Coste 2011-10-17 22:05:06 +00:00
parent 1c6eef08f1
commit d48a2bd325
3 changed files with 131 additions and 116 deletions

View File

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

View File

@ -171,8 +171,12 @@ private:
std::list<std::unique_ptr<Window>> m_windows;
std::vector<UndoGroup>::iterator m_last_save_undo_group;
std::vector<BufferModificationListener*> m_modification_listeners;
};
}
#include "buffer_iterator.inl.h"
#endif // buffer_hh_INCLUDED

127
src/buffer_iterator.inl.h Normal file
View File

@ -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