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;
31 class InsetTablePosLess : public std::binary_function<InsetList::InsetTable, InsetList::InsetTable, bool> {
33 bool operator()(InsetList::InsetTable const & t1,
34 InsetList::InsetTable const & t2) const
36 return t1.pos < t2.pos;
42 InsetList::~InsetList()
44 // If we begin storing a shared_ptr in the List
45 // this code can be removed. (Lgb)
46 List::iterator it = list.begin();
47 List::iterator end = list.end();
48 for (; it != end; ++it) {
54 InsetList::iterator InsetList::insetIterator(pos_type pos)
56 InsetTable search_elem(pos, 0);
57 return lower_bound(list.begin(), list.end(), search_elem,
62 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
64 InsetTable search_elem(pos, 0);
65 return lower_bound(list.begin(), list.end(), search_elem,
70 void InsetList::insert(InsetOld * inset, lyx::pos_type pos)
72 List::iterator end = list.end();
73 List::iterator it = insetIterator(pos);
74 if (it != end && it->pos == pos) {
75 lyxerr << "ERROR (InsetList::insert): "
76 << "There is an inset in position: " << pos << endl;
78 list.insert(it, InsetTable(pos, inset));
83 void InsetList::erase(pos_type pos)
85 List::iterator end = list.end();
86 List::iterator it = insetIterator(pos);
87 if (it != end && it->pos == pos) {
94 InsetOld * InsetList::release(pos_type pos)
96 List::iterator end = list.end();
97 List::iterator it = insetIterator(pos);
98 if (it != end && it->pos == pos) {
99 InsetOld * tmp = it->inset;
107 InsetOld * InsetList::get(pos_type pos) const
109 List::const_iterator end = list.end();
110 List::const_iterator it = insetIterator(pos);
111 if (it != end && it->pos == pos)
117 void InsetList::increasePosAfterPos(pos_type pos)
119 List::iterator end = list.end();
120 List::iterator it = insetIterator(pos);
121 for (; it != end; ++it) {
127 void InsetList::decreasePosAfterPos(pos_type pos)
129 List::iterator end = list.end();
130 List::iterator it = insetIterator(pos);
131 for (; it != end; ++it) {
137 void InsetList::insetsOpenCloseBranch(Buffer const & buf)
139 List::iterator it = list.begin();
140 List::iterator end = list.end();
141 for (; it != end; ++it) {
143 it->inset->lyxCode() != InsetOld::BRANCH_CODE)
146 InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
147 if (inset->isBranchSelected(buf.params().branchlist())) {