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 "BufferView.h"
21 #include "insets/insetbranch.h"
26 using std::lower_bound;
32 /// used by lower_bound
34 int operator()(InsetList::InsetTable const & a,
35 InsetList::InsetTable const & b) const
44 InsetList::~InsetList()
46 // If we begin storing a shared_ptr in the List
47 // this code can be removed. (Lgb)
48 List::iterator it = list.begin();
49 List::iterator end = list.end();
50 for (; it != end; ++it) {
56 InsetList::iterator InsetList::begin()
62 InsetList::iterator InsetList::end()
68 InsetList::const_iterator InsetList::begin() const
74 InsetList::const_iterator InsetList::end() const
80 InsetList::iterator InsetList::insetIterator(pos_type pos)
82 InsetTable search_elem(pos, 0);
83 return lower_bound(list.begin(), list.end(), search_elem, MatchIt());
87 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
89 InsetTable search_elem(pos, 0);
90 return lower_bound(list.begin(), list.end(), search_elem, MatchIt());
94 void InsetList::insert(InsetOld * inset, lyx::pos_type pos)
96 List::iterator end = list.end();
97 List::iterator it = insetIterator(pos);
98 if (it != end && it->pos == pos) {
99 lyxerr << "ERROR (InsetList::insert): "
100 << "There is an inset in position: " << pos << endl;
102 list.insert(it, InsetTable(pos, inset));
107 void InsetList::erase(pos_type pos)
109 List::iterator end = list.end();
110 List::iterator it = insetIterator(pos);
111 if (it != end && it->pos == pos) {
118 InsetOld * InsetList::release(pos_type pos)
120 List::iterator end = list.end();
121 List::iterator it = insetIterator(pos);
122 if (it != end && it->pos == pos) {
123 InsetOld * tmp = it->inset;
131 InsetOld * InsetList::get(pos_type pos) const
133 List::const_iterator end = list.end();
134 List::const_iterator it = insetIterator(pos);
135 if (it != end && it->pos == pos)
141 void InsetList::increasePosAfterPos(pos_type pos)
143 List::iterator end = list.end();
144 List::iterator it = insetIterator(pos);
145 for (; it != end; ++it) {
151 void InsetList::decreasePosAfterPos(pos_type pos)
153 List::iterator end = list.end();
154 List::iterator it = insetIterator(pos);
155 for (; it != end; ++it) {
161 void InsetList::insetsOpenCloseBranch(Buffer const & buf)
163 List::iterator it = list.begin();
164 List::iterator end = list.end();
165 for (; it != end; ++it) {
166 if (it->inset && it->inset->lyxCode() == InsetOld::BRANCH_CODE) {
167 InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
168 if (buf.params().branchlist().selected(inset->params().branch)) {