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"
21 #include "insets/InsetBranch.h"
24 using std::lower_bound;
32 typedef InsetList::InsetTable Table;
34 class InsetTablePosLess : public std::binary_function<Table, Table, bool> {
36 bool operator()(Table const & t1, Table const & t2) const
38 return t1.pos < t2.pos;
46 InsetList::~InsetList()
48 // If we begin storing a shared_ptr in the List
49 // this code can be removed. (Lgb)
50 List::iterator it = list_.begin();
51 List::iterator end = list_.end();
52 for (; it != end; ++it) {
58 InsetList::iterator InsetList::insetIterator(pos_type pos)
60 InsetTable search_elem(pos, 0);
61 return lower_bound(list_.begin(), list_.end(), search_elem,
66 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
68 InsetTable search_elem(pos, 0);
69 return lower_bound(list_.begin(), list_.end(), search_elem,
74 void InsetList::insert(Inset * inset, pos_type pos)
76 List::iterator end = list_.end();
77 List::iterator it = insetIterator(pos);
78 if (it != end && it->pos == pos) {
79 lyxerr << "ERROR (InsetList::insert): "
80 << "There is an inset in position: " << pos << endl;
82 list_.insert(it, InsetTable(pos, inset));
87 void InsetList::erase(pos_type pos)
89 List::iterator end = list_.end();
90 List::iterator it = insetIterator(pos);
91 if (it != end && it->pos == pos) {
98 Inset * InsetList::release(pos_type pos)
100 List::iterator end = list_.end();
101 List::iterator it = insetIterator(pos);
102 if (it != end && it->pos == pos) {
103 Inset * tmp = it->inset;
111 Inset * InsetList::get(pos_type pos) const
113 List::const_iterator end = list_.end();
114 List::const_iterator it = insetIterator(pos);
115 if (it != end && it->pos == pos)
121 void InsetList::increasePosAfterPos(pos_type pos)
123 List::iterator end = list_.end();
124 List::iterator it = insetIterator(pos);
125 for (; it != end; ++it) {
131 void InsetList::decreasePosAfterPos(pos_type pos)
133 List::iterator end = list_.end();
134 List::iterator it = insetIterator(pos);
135 for (; it != end; ++it) {
141 InsetList::InsetList(InsetList const & il)
144 List::iterator it = list_.begin();
145 List::iterator end = list_.end();
146 for (; it != end; ++it)
147 it->inset = it->inset->clone();
151 pos_type InsetList::find(InsetCode code, pos_type startpos) const
153 List::const_iterator it = insetIterator(startpos);
154 List::const_iterator end = list_.end();
155 for (; it != end ; ++it) {
156 if (it->inset->lyxCode() == code)
163 int InsetList::count(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)