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;
32 typedef InsetList::InsetTable Table;
34 struct InsetTablePosLess : public std::binary_function<Table, Table, bool> {
35 bool operator()(Table const & t1, Table const & t2) const
37 return t1.pos < t2.pos;
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,
65 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
67 InsetTable search_elem(pos, 0);
68 return lower_bound(list_.begin(), list_.end(), search_elem,
73 void InsetList::insert(InsetBase * inset, lyx::pos_type pos)
75 List::iterator end = list_.end();
76 List::iterator it = insetIterator(pos);
77 if (it != end && it->pos == pos) {
78 lyxerr << "ERROR (InsetList::insert): "
79 << "There is an inset in position: " << pos << endl;
81 list_.insert(it, InsetTable(pos, inset));
86 void InsetList::erase(pos_type pos)
88 List::iterator end = list_.end();
89 List::iterator it = insetIterator(pos);
90 if (it != end && it->pos == pos) {
97 InsetBase * InsetList::release(pos_type pos)
99 List::iterator end = list_.end();
100 List::iterator it = insetIterator(pos);
101 if (it != end && it->pos == pos) {
102 InsetBase * tmp = it->inset;
110 InsetBase * InsetList::get(pos_type pos) const
112 List::const_iterator end = list_.end();
113 List::const_iterator it = insetIterator(pos);
114 if (it != end && it->pos == pos)
120 void InsetList::increasePosAfterPos(pos_type pos)
122 List::iterator end = list_.end();
123 List::iterator it = insetIterator(pos);
124 for (; it != end; ++it) {
130 void InsetList::decreasePosAfterPos(pos_type pos)
132 List::iterator end = list_.end();
133 List::iterator it = insetIterator(pos);
134 for (; it != end; ++it) {