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"
15 #include "BufferView.h"
19 #include "insets/insetbranch.h"
24 using std::lower_bound;
25 using std::upper_bound;
31 /// used by lower_bound and upper_bound
33 int operator()(InsetList::InsetTable const & a,
34 InsetList::InsetTable const & b) const
43 InsetList::~InsetList()
45 // If we begin storing a shared_ptr in the List
46 // this code can be removed. (Lgb)
47 List::iterator it = list.begin();
48 List::iterator end = list.end();
49 for (; it != end; ++it) {
55 InsetList::iterator InsetList::begin()
61 InsetList::iterator InsetList::end()
67 InsetList::const_iterator InsetList::begin() const
73 InsetList::const_iterator InsetList::end() const
80 InsetList::insetIterator(pos_type pos)
82 InsetTable search_elem(pos, 0);
83 List::iterator it = lower_bound(list.begin(),
85 search_elem, MatchIt());
90 void InsetList::insert(InsetOld * inset, lyx::pos_type pos)
92 InsetTable search_elem(pos, 0);
93 List::iterator end = list.end();
94 List::iterator it = lower_bound(list.begin(),
96 search_elem, MatchIt());
97 if (it != end && it->pos == pos) {
98 lyxerr << "ERROR (InsetList::insert): "
99 << "There is an inset in position: " << pos << endl;
101 list.insert(it, InsetTable(pos, inset));
106 void InsetList::erase(pos_type pos)
108 InsetTable search_elem(pos, 0);
109 List::iterator end = list.end();
111 lower_bound(list.begin(),
113 search_elem, MatchIt());
114 if (it != end && it->pos == pos) {
121 InsetOld * InsetList::release(pos_type pos)
123 InsetTable search_elem(pos, 0);
124 List::iterator end = list.end();
126 lower_bound(list.begin(),
128 search_elem, MatchIt());
129 if (it != end && it->pos == pos) {
130 InsetOld * tmp = it->inset;
138 InsetOld * InsetList::get(pos_type pos) const
140 InsetTable search_elem(pos, 0);
141 List::const_iterator end = list.end();
142 List::const_iterator it =
143 lower_bound(list.begin(),
145 search_elem, MatchIt());
146 if (it != end && it->pos == pos)
152 void InsetList::increasePosAfterPos(pos_type pos)
154 InsetTable search_elem(pos, 0);
155 List::iterator end = list.end();
156 List::iterator it = lower_bound(list.begin(),
158 search_elem, MatchIt());
159 for (; it != end; ++it) {
165 void InsetList::decreasePosAfterPos(pos_type pos)
167 InsetTable search_elem(pos, 0);
168 List::iterator end = list.end();
169 List::iterator it = upper_bound(list.begin(),
171 search_elem, MatchIt());
172 for (; it != end; ++it) {
178 void InsetList::deleteInsetsLyXText(BufferView * bv)
180 List::iterator it = list.begin();
181 List::iterator end = list.end();
182 for (; it != end; ++it) {
184 if (it->inset->isTextInset()) {
185 static_cast<UpdatableInset*>
186 (it->inset)->deleteLyXText(bv, true);
193 void InsetList::insetsOpenCloseBranch(BufferView * bv)
195 BufferParams bp = bv->buffer()->params;
196 List::iterator it = list.begin();
197 List::iterator end = list.end();
198 for (; it != end; ++it) {
199 if (it->inset && it->inset->lyxCode() == InsetOld::BRANCH_CODE) {
200 InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
201 if (bp.branchlist.selected(inset->params().branch)) {