DisplayBuffer: deinline insert method and add atom_containing method

This commit is contained in:
Maxime Coste 2011-10-17 19:00:38 +00:00
parent 88e31d8cce
commit 79ee27dae7
2 changed files with 23 additions and 2 deletions

View File

@ -79,17 +79,36 @@ DisplayBuffer::DisplayBuffer()
{ {
} }
DisplayBuffer::iterator DisplayBuffer::insert(iterator where, const DisplayAtom& atom)
{
check_invariant();
iterator res = m_atoms.insert(where, atom);
check_invariant();
return res;
}
DisplayBuffer::iterator DisplayBuffer::atom_containing(const BufferIterator& where)
{
for (iterator it = m_atoms.begin(); it != m_atoms.end(); ++it)
{
if (it->end() > where)
return it;
}
return end();
}
DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator& pos) DisplayBuffer::iterator DisplayBuffer::split(iterator atom, const BufferIterator& pos)
{ {
assert(atom < end()); assert(atom < end());
assert(pos > atom->begin()); assert(pos > atom->begin());
assert(pos < atom->end()); assert(pos < atom->end());
check_invariant();
DisplayAtom new_atom(atom->coord(), atom->begin(), pos, DisplayAtom new_atom(atom->coord(), atom->begin(), pos,
atom->fg_color(), atom->bg_color(), atom->attribute()); atom->fg_color(), atom->bg_color(), atom->attribute());
atom->m_begin = pos; atom->m_begin = pos;
atom->m_coord = new_atom.end_coord(); atom->m_coord = new_atom.end_coord();
iterator res = insert(atom, std::move(new_atom)); iterator res = m_atoms.insert(atom, std::move(new_atom));
check_invariant(); check_invariant();
return res; return res;
} }

View File

@ -99,7 +99,7 @@ public:
void clear() { m_atoms.clear(); } void clear() { m_atoms.clear(); }
void append(const DisplayAtom& atom) { m_atoms.push_back(atom); } void append(const DisplayAtom& atom) { m_atoms.push_back(atom); }
iterator insert(iterator where, const DisplayAtom& atom) { return m_atoms.insert(where, atom); } iterator insert(iterator where, const DisplayAtom& atom);
iterator split(iterator atom, const BufferIterator& pos); iterator split(iterator atom, const BufferIterator& pos);
void replace_atom_content(iterator atom, const BufferString& replacement); void replace_atom_content(iterator atom, const BufferString& replacement);
@ -110,6 +110,8 @@ public:
const_iterator begin() const { return m_atoms.begin(); } const_iterator begin() const { return m_atoms.begin(); }
const_iterator end() const { return m_atoms.end(); } const_iterator end() const { return m_atoms.end(); }
iterator atom_containing(const BufferIterator& where);
const DisplayAtom& front() const { return m_atoms.front(); } const DisplayAtom& front() const { return m_atoms.front(); }
const DisplayAtom& back() const { return m_atoms.back(); } const DisplayAtom& back() const { return m_atoms.back(); }