3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Martin Vermeer
9 * Full author contact details are available in file CREDITS.
15 #include "InsetList.h"
18 #include "BufferParams.h"
19 #include "BranchList.h"
21 #include "insets/InsetBranch.h"
23 #include "support/debug.h"
32 typedef InsetList::InsetTable Table;
34 struct InsetTablePosLess
36 bool operator()(Table const & t1, Table const & t2) const
38 return t1.pos < t2.pos;
45 InsetList::InsetList(InsetList const & il) : list_(il.list_)
47 List::iterator it = list_.begin();
48 List::iterator end = list_.end();
49 for (; it != end; ++it)
50 it->inset = it->inset->clone();
54 InsetList::InsetList(InsetList const & il, pos_type beg, pos_type end)
56 InsetList::const_iterator cit = il.begin();
57 InsetList::const_iterator cend = il.end();
58 for (; cit != cend; ++cit) {
63 // Add a new entry in the insetlist_.
64 insert(cit->inset->clone(), cit->pos - beg);
69 InsetList::~InsetList()
71 List::iterator it = list_.begin();
72 List::iterator end = list_.end();
73 for (; it != end; ++it)
78 void InsetList::setBuffer(Buffer & b)
80 List::iterator it = list_.begin();
81 List::iterator end = list_.end();
82 for (; it != end; ++it)
83 it->inset->setBuffer(b);
87 InsetList::iterator InsetList::insetIterator(pos_type pos)
89 InsetTable search_elem(pos, 0);
90 return lower_bound(list_.begin(), list_.end(), search_elem,
95 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
97 InsetTable search_elem(pos, 0);
98 return lower_bound(list_.begin(), list_.end(), search_elem,
103 void InsetList::insert(Inset * inset, pos_type pos)
105 List::iterator end = list_.end();
106 List::iterator it = insetIterator(pos);
107 if (it != end && it->pos == pos) {
108 LYXERR0("ERROR (InsetList::insert): "
109 << "There is an inset in position: " << pos);
111 list_.insert(it, InsetTable(pos, inset));
116 void InsetList::erase(pos_type pos)
118 List::iterator end = list_.end();
119 List::iterator it = insetIterator(pos);
120 if (it != end && it->pos == pos) {
127 Inset * InsetList::release(pos_type pos)
129 List::iterator end = list_.end();
130 List::iterator it = insetIterator(pos);
131 if (it != end && it->pos == pos) {
132 Inset * tmp = it->inset;
140 Inset * InsetList::get(pos_type pos) const
142 List::const_iterator end = list_.end();
143 List::const_iterator it = insetIterator(pos);
144 if (it != end && it->pos == pos)
150 void InsetList::increasePosAfterPos(pos_type pos)
152 List::iterator end = list_.end();
153 List::iterator it = insetIterator(pos);
154 for (; it != end; ++it)
159 void InsetList::decreasePosAfterPos(pos_type pos)
161 List::iterator end = list_.end();
162 List::iterator it = insetIterator(pos);
163 for (; it != end; ++it)
168 pos_type InsetList::find(InsetCode code, pos_type startpos) const
170 List::const_iterator it = insetIterator(startpos);
171 List::const_iterator end = list_.end();
172 for (; it != end ; ++it) {
173 if (it->inset->lyxCode() == code)
180 int InsetList::count(InsetCode code, pos_type startpos) const
183 List::const_iterator it = insetIterator(startpos);
184 List::const_iterator end = list_.end();
185 for (; it != end ; ++it) {
186 if (it->inset->lyxCode() == code)