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::Element Table;
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 for (auto & i : list_)
45 i.inset = i.inset->clone();
49 InsetList::InsetList(InsetList const & il, pos_type beg, pos_type end)
51 for (auto const & ci : il) {
56 // Add a new entry in the insetlist_.
57 insert(ci.inset->clone(), ci.pos - beg);
62 InsetList::~InsetList()
64 for (auto & i : list_)
69 void InsetList::setBuffer(Buffer & b)
71 for (auto & i : list_)
72 i.inset->setBuffer(b);
76 void InsetList::resetBuffer()
78 for (auto & i : list_)
79 i.inset->resetBuffer();
83 InsetList::iterator InsetList::insetIterator(pos_type pos)
85 Element search_elem(pos, nullptr);
86 return lower_bound(list_.begin(), list_.end(), search_elem,
91 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
93 Element search_elem(pos, nullptr);
94 return lower_bound(list_.begin(), list_.end(), search_elem,
99 void InsetList::insert(Inset * inset, pos_type pos)
101 List::iterator end = list_.end();
102 List::iterator it = insetIterator(pos);
103 if (it != end && it->pos == pos) {
104 LYXERR0("ERROR (InsetList::insert): "
105 << "There is an inset in position: " << pos);
107 list_.insert(it, Element(pos, inset));
112 void InsetList::erase(pos_type pos)
114 List::iterator end = list_.end();
115 List::iterator it = insetIterator(pos);
116 if (it != end && it->pos == pos) {
123 Inset * InsetList::release(pos_type pos)
125 List::iterator end = list_.end();
126 List::iterator it = insetIterator(pos);
127 if (it != end && it->pos == pos) {
128 Inset * tmp = it->inset;
136 Inset * InsetList::get(pos_type pos) const
138 List::const_iterator end = list_.end();
139 List::const_iterator it = insetIterator(pos);
140 if (it != end && it->pos == pos)
146 void InsetList::increasePosAfterPos(pos_type pos)
148 List::iterator end = list_.end();
149 List::iterator it = insetIterator(pos);
150 for (; it != end; ++it)
155 void InsetList::decreasePosAfterPos(pos_type pos)
157 List::iterator end = list_.end();
158 List::iterator it = insetIterator(pos);
159 for (; it != end; ++it)
164 pos_type InsetList::find(InsetCode code, pos_type startpos) const
166 List::const_iterator it = insetIterator(startpos);
167 List::const_iterator end = list_.end();
168 for (; it != end ; ++it) {
169 if (it->inset->lyxCode() == code)
176 int InsetList::count(InsetCode code, pos_type startpos) const
179 List::const_iterator it = insetIterator(startpos);
180 List::const_iterator end = list_.end();
181 for (; it != end ; ++it) {
182 if (it->inset->lyxCode() == code)