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"
17 #include "BufferParams.h"
18 #include "BranchList.h"
19 #include "support/debug.h"
21 #include "insets/InsetBranch.h"
30 typedef InsetList::InsetTable Table;
32 struct InsetTablePosLess
34 bool operator()(Table const & t1, Table const & t2) const
36 return t1.pos < t2.pos;
43 InsetList::InsetList(InsetList const & il)
46 List::iterator it = list_.begin();
47 List::iterator end = list_.end();
48 for (; it != end; ++it)
49 it->inset = it->inset->clone();
53 InsetList::~InsetList()
55 List::iterator it = list_.begin();
56 List::iterator end = list_.end();
57 for (; it != end; ++it)
62 InsetList::iterator InsetList::insetIterator(pos_type pos)
64 InsetTable search_elem(pos, 0);
65 return lower_bound(list_.begin(), list_.end(), search_elem,
70 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
72 InsetTable search_elem(pos, 0);
73 return lower_bound(list_.begin(), list_.end(), search_elem,
78 void InsetList::insert(Inset * inset, pos_type pos)
80 List::iterator end = list_.end();
81 List::iterator it = insetIterator(pos);
82 if (it != end && it->pos == pos) {
83 LYXERR0("ERROR (InsetList::insert): "
84 << "There is an inset in position: " << pos);
86 list_.insert(it, InsetTable(pos, inset));
91 void InsetList::erase(pos_type pos)
93 List::iterator end = list_.end();
94 List::iterator it = insetIterator(pos);
95 if (it != end && it->pos == pos) {
102 Inset * InsetList::release(pos_type pos)
104 List::iterator end = list_.end();
105 List::iterator it = insetIterator(pos);
106 if (it != end && it->pos == pos) {
107 Inset * tmp = it->inset;
115 Inset * InsetList::get(pos_type pos) const
117 List::const_iterator end = list_.end();
118 List::const_iterator it = insetIterator(pos);
119 if (it != end && it->pos == pos)
125 void InsetList::increasePosAfterPos(pos_type pos)
127 List::iterator end = list_.end();
128 List::iterator it = insetIterator(pos);
129 for (; it != end; ++it)
134 void InsetList::decreasePosAfterPos(pos_type pos)
136 List::iterator end = list_.end();
137 List::iterator it = insetIterator(pos);
138 for (; it != end; ++it)
143 pos_type InsetList::find(InsetCode code, pos_type startpos) const
145 List::const_iterator it = insetIterator(startpos);
146 List::const_iterator end = list_.end();
147 for (; it != end ; ++it) {
148 if (it->inset->lyxCode() == code)
155 int InsetList::count(InsetCode code, pos_type startpos) const
158 List::const_iterator it = insetIterator(startpos);
159 List::const_iterator end = list_.end();
160 for (; it != end ; ++it) {
161 if (it->inset->lyxCode() == code)