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.
14 #include "InsetList.h"
16 #include "insets/Inset.h"
18 #include "support/debug.h"
29 typedef InsetList::InsetTable Table;
31 struct InsetTablePosLess
33 bool operator()(Table const & t1, Table const & t2) const
35 return t1.pos < t2.pos;
42 InsetList::InsetList(InsetList const & il) : list_(il.list_)
44 List::iterator it = list_.begin();
45 List::iterator end = list_.end();
46 for (; it != end; ++it)
47 it->inset = it->inset->clone();
51 InsetList::InsetList(InsetList const & il, pos_type beg, pos_type end)
53 InsetList::const_iterator cit = il.begin();
54 InsetList::const_iterator cend = il.end();
55 for (; cit != cend; ++cit) {
60 // Add a new entry in the insetlist_.
61 insert(cit->inset->clone(), cit->pos - beg);
66 InsetList::~InsetList()
68 List::iterator it = list_.begin();
69 List::iterator end = list_.end();
70 for (; it != end; ++it)
75 void InsetList::setBuffer(Buffer & b)
77 List::iterator it = list_.begin();
78 List::iterator end = list_.end();
79 for (; it != end; ++it)
80 it->inset->setBuffer(b);
84 void InsetList::resetBuffer()
86 List::iterator it = list_.begin();
87 List::iterator end = list_.end();
88 for (; it != end; ++it)
89 it->inset->resetBuffer();
93 InsetList::iterator InsetList::insetIterator(pos_type pos)
95 InsetTable search_elem(pos, 0);
96 return lower_bound(list_.begin(), list_.end(), search_elem,
101 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
103 InsetTable search_elem(pos, 0);
104 return lower_bound(list_.begin(), list_.end(), search_elem,
105 InsetTablePosLess());
109 void InsetList::insert(Inset * inset, pos_type pos)
111 List::iterator end = list_.end();
112 List::iterator it = insetIterator(pos);
113 if (it != end && it->pos == pos) {
114 LYXERR0("ERROR (InsetList::insert): "
115 << "There is an inset in position: " << pos);
117 list_.insert(it, InsetTable(pos, inset));
122 void InsetList::erase(pos_type pos)
124 List::iterator end = list_.end();
125 List::iterator it = insetIterator(pos);
126 if (it != end && it->pos == pos) {
133 Inset * InsetList::release(pos_type pos)
135 List::iterator end = list_.end();
136 List::iterator it = insetIterator(pos);
137 if (it != end && it->pos == pos) {
138 Inset * tmp = it->inset;
146 Inset * InsetList::get(pos_type pos) const
148 List::const_iterator end = list_.end();
149 List::const_iterator it = insetIterator(pos);
150 if (it != end && it->pos == pos)
156 void InsetList::increasePosAfterPos(pos_type pos)
158 List::iterator end = list_.end();
159 List::iterator it = insetIterator(pos);
160 for (; it != end; ++it)
165 void InsetList::decreasePosAfterPos(pos_type pos)
167 List::iterator end = list_.end();
168 List::iterator it = insetIterator(pos);
169 for (; it != end; ++it)
174 pos_type InsetList::find(InsetCode code, pos_type startpos) const
176 List::const_iterator it = insetIterator(startpos);
177 List::const_iterator end = list_.end();
178 for (; it != end ; ++it) {
179 if (it->inset->lyxCode() == code)
186 int InsetList::count(InsetCode code, pos_type startpos) const
189 List::const_iterator it = insetIterator(startpos);
190 List::const_iterator end = list_.end();
191 for (; it != end ; ++it) {
192 if (it->inset->lyxCode() == code)