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"
20 #include "insets/InsetBranch.h"
22 #include "support/debug.h"
31 typedef InsetList::InsetTable Table;
33 struct InsetTablePosLess
35 bool operator()(Table const & t1, Table const & t2) const
37 return t1.pos < t2.pos;
44 InsetList::InsetList(InsetList const & il)
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()
56 List::iterator it = list_.begin();
57 List::iterator end = list_.end();
58 for (; it != end; ++it)
63 InsetList::iterator InsetList::insetIterator(pos_type pos)
65 InsetTable search_elem(pos, 0);
66 return lower_bound(list_.begin(), list_.end(), search_elem,
71 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
73 InsetTable search_elem(pos, 0);
74 return lower_bound(list_.begin(), list_.end(), search_elem,
79 void InsetList::insert(Inset * inset, pos_type pos)
81 List::iterator end = list_.end();
82 List::iterator it = insetIterator(pos);
83 if (it != end && it->pos == pos) {
84 LYXERR0("ERROR (InsetList::insert): "
85 << "There is an inset in position: " << pos);
87 list_.insert(it, InsetTable(pos, inset));
92 void InsetList::erase(pos_type pos)
94 List::iterator end = list_.end();
95 List::iterator it = insetIterator(pos);
96 if (it != end && it->pos == pos) {
103 Inset * InsetList::release(pos_type pos)
105 List::iterator end = list_.end();
106 List::iterator it = insetIterator(pos);
107 if (it != end && it->pos == pos) {
108 Inset * tmp = it->inset;
116 Inset * InsetList::get(pos_type pos) const
118 List::const_iterator end = list_.end();
119 List::const_iterator it = insetIterator(pos);
120 if (it != end && it->pos == pos)
126 void InsetList::increasePosAfterPos(pos_type pos)
128 List::iterator end = list_.end();
129 List::iterator it = insetIterator(pos);
130 for (; it != end; ++it)
135 void InsetList::decreasePosAfterPos(pos_type pos)
137 List::iterator end = list_.end();
138 List::iterator it = insetIterator(pos);
139 for (; it != end; ++it)
144 pos_type InsetList::find(InsetCode code, pos_type startpos) const
146 List::const_iterator it = insetIterator(startpos);
147 List::const_iterator end = list_.end();
148 for (; it != end ; ++it) {
149 if (it->inset->lyxCode() == code)
156 int InsetList::count(InsetCode code, pos_type startpos) const
159 List::const_iterator it = insetIterator(startpos);
160 List::const_iterator end = list_.end();
161 for (; it != end ; ++it) {
162 if (it->inset->lyxCode() == code)