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 "BufferView.h"
22 #include "insets/insetbranch.h"
27 using std::lower_bound;
33 /// used by lower_bound
35 int operator()(InsetList::InsetTable const & a,
36 InsetList::InsetTable const & b) const
45 InsetList::~InsetList()
47 // If we begin storing a shared_ptr in the List
48 // this code can be removed. (Lgb)
49 List::iterator it = list.begin();
50 List::iterator end = list.end();
51 for (; it != end; ++it) {
57 InsetList::iterator InsetList::insetIterator(pos_type pos)
59 InsetTable search_elem(pos, 0);
60 return lower_bound(list.begin(), list.end(), search_elem, MatchIt());
64 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
66 InsetTable search_elem(pos, 0);
67 return lower_bound(list.begin(), list.end(), search_elem, MatchIt());
71 void InsetList::insert(InsetOld * inset, lyx::pos_type pos)
73 List::iterator end = list.end();
74 List::iterator it = insetIterator(pos);
75 if (it != end && it->pos == pos) {
76 lyxerr << "ERROR (InsetList::insert): "
77 << "There is an inset in position: " << pos << endl;
79 list.insert(it, InsetTable(pos, inset));
84 void InsetList::erase(pos_type pos)
86 List::iterator end = list.end();
87 List::iterator it = insetIterator(pos);
88 if (it != end && it->pos == pos) {
95 InsetOld * InsetList::release(pos_type pos)
97 List::iterator end = list.end();
98 List::iterator it = insetIterator(pos);
99 if (it != end && it->pos == pos) {
100 InsetOld * tmp = it->inset;
108 InsetOld * InsetList::get(pos_type pos) const
110 List::const_iterator end = list.end();
111 List::const_iterator it = insetIterator(pos);
112 if (it != end && it->pos == pos)
118 void InsetList::increasePosAfterPos(pos_type pos)
120 List::iterator end = list.end();
121 List::iterator it = insetIterator(pos);
122 for (; it != end; ++it) {
128 void InsetList::decreasePosAfterPos(pos_type pos)
130 List::iterator end = list.end();
131 List::iterator it = insetIterator(pos);
132 for (; it != end; ++it) {
138 void InsetList::insetsOpenCloseBranch(Buffer const & buf)
140 List::iterator it = list.begin();
141 List::iterator end = list.end();
142 for (; it != end; ++it) {
144 it->inset->lyxCode() != InsetOld::BRANCH_CODE)
147 InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
148 if (inset->isBranchSelected(buf.params().branchlist())) {