From ccec35f88cf58f61d08dc4aa8801aa8b2f5b75de Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 25 Jun 2012 19:05:32 +0200 Subject: [PATCH] code cleanups in buffer --- src/buffer.cc | 4 ++-- src/buffer.hh | 13 +++++++++---- src/buffer_iterator.inl.hh | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/buffer.cc b/src/buffer.cc index eab38d92..30cf6d38 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -69,7 +69,7 @@ BufferSize Buffer::line_length(BufferPos line) const { assert(line < line_count()); BufferPos end = (line < m_lines.size() - 1) ? - m_lines[line + 1].start : length(); + m_lines[line + 1].start : character_count(); return end - m_lines[line].start; } @@ -108,7 +108,7 @@ BufferIterator Buffer::end() const return BufferIterator(*this, { (int)line_count()-1, (int)m_lines.back().length() }); } -BufferSize Buffer::length() const +BufferSize Buffer::character_count() const { if (m_lines.empty()) return 0; diff --git a/src/buffer.hh b/src/buffer.hh index cd86737f..30cc2af9 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -123,11 +123,13 @@ public: Buffer& operator= (const Buffer&) = delete; ~Buffer(); - void begin_undo_group(); - void end_undo_group(); + Type type() const { return m_type; } + // apply given modification to buffer. void modify(Modification&& modification); + void begin_undo_group(); + void end_undo_group(); bool undo(); bool redo(); @@ -136,7 +138,7 @@ public: BufferIterator begin() const; BufferIterator end() const; - BufferSize length() const; + BufferSize character_count() const; BufferSize line_count() const; BufferIterator iterator_at(const BufferCoord& line_and_column) const; @@ -150,8 +152,11 @@ public: Window* get_or_create_window(); void delete_window(Window* window); + // returns true if the buffer is in a different state than + // the last time it was saved bool is_modified() const; - Type type() const { return m_type; } + + // notify the buffer that it was saved in the current state void notify_saved(); void add_iterator_to_update(BufferIterator& iterator); diff --git a/src/buffer_iterator.inl.hh b/src/buffer_iterator.inl.hh index 65ed3c04..bcb83ab0 100644 --- a/src/buffer_iterator.inl.hh +++ b/src/buffer_iterator.inl.hh @@ -133,7 +133,7 @@ inline BufferIterator BufferIterator::operator+(BufferSize size) const assert(m_buffer); if (size >= 0) { - BufferSize o = std::min(m_buffer->length(), offset() + size); + BufferSize o = std::min(m_buffer->character_count(), offset() + size); for (int i = line() + 1; i < m_buffer->line_count(); ++i) { if (m_buffer->m_lines[i].start > o) @@ -209,7 +209,7 @@ inline bool BufferIterator::is_begin() const inline bool BufferIterator::is_end() const { assert(m_buffer); - return offset() == m_buffer->length(); + return offset() == m_buffer->character_count(); } }