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)
48 List::iterator it = list_.begin();
49 List::iterator end = list_.end();
50 for (; it != end; ++it)
51 it->inset = it->inset->clone();
55 InsetList::~InsetList()
57 List::iterator it = list_.begin();
58 List::iterator end = list_.end();
59 for (; it != end; ++it)
64 InsetList::iterator InsetList::insetIterator(pos_type pos)
66 InsetTable search_elem(pos, 0);
67 return lower_bound(list_.begin(), list_.end(), search_elem,
72 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
74 InsetTable search_elem(pos, 0);
75 return lower_bound(list_.begin(), list_.end(), search_elem,
80 void InsetList::insert(Inset * inset, pos_type pos)
82 List::iterator end = list_.end();
83 List::iterator it = insetIterator(pos);
84 if (it != end && it->pos == pos) {
85 LYXERR0("ERROR (InsetList::insert): "
86 << "There is an inset in position: " << pos);
88 list_.insert(it, InsetTable(pos, inset));
93 void InsetList::erase(pos_type pos)
95 List::iterator end = list_.end();
96 List::iterator it = insetIterator(pos);
97 if (it != end && it->pos == pos) {
104 Inset * InsetList::release(pos_type pos)
106 List::iterator end = list_.end();
107 List::iterator it = insetIterator(pos);
108 if (it != end && it->pos == pos) {
109 Inset * tmp = it->inset;
117 Inset * InsetList::get(pos_type pos) const
119 List::const_iterator end = list_.end();
120 List::const_iterator it = insetIterator(pos);
121 if (it != end && it->pos == pos)
127 void InsetList::increasePosAfterPos(pos_type pos)
129 List::iterator end = list_.end();
130 List::iterator it = insetIterator(pos);
131 for (; it != end; ++it)
136 void InsetList::decreasePosAfterPos(pos_type pos)
138 List::iterator end = list_.end();
139 List::iterator it = insetIterator(pos);
140 for (; it != end; ++it)
145 pos_type InsetList::find(InsetCode code, pos_type startpos) const
147 List::const_iterator it = insetIterator(startpos);
148 List::const_iterator end = list_.end();
149 for (; it != end ; ++it) {
150 if (it->inset->lyxCode() == code)
157 int InsetList::count(InsetCode code, pos_type startpos) const
160 List::const_iterator it = insetIterator(startpos);
161 List::const_iterator end = list_.end();
162 for (; it != end ; ++it) {
163 if (it->inset->lyxCode() == code)