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.
15 #include "InsetList.h"
18 #include "BufferParams.h"
19 #include "BranchList.h"
21 #include "insets/InsetBranch.h"
23 #include "support/debug.h"
32 typedef InsetList::InsetTable Table
;
34 struct InsetTablePosLess
36 bool operator()(Table
const & t1
, Table
const & t2
) const
38 return t1
.pos
< t2
.pos
;
45 InsetList::InsetList(InsetList
const & il
)
48 List::iterator it
= list_
.begin();
49 List::iterator end
= list_
.end();
50 for (; it
!= end
; ++it
)
51 it
->inset
= it
->inset
->clone();
55 InsetList::InsetList(InsetList
const & il
, pos_type beg
, pos_type end
)
57 InsetList::const_iterator cit
= il
.begin();
58 InsetList::const_iterator cend
= il
.end();
59 for (; cit
!= cend
; ++cit
) {
64 // Add a new entry in the insetlist_.
65 insert(cit
->inset
->clone(), cit
->pos
- beg
);
70 InsetList::~InsetList()
72 List::iterator it
= list_
.begin();
73 List::iterator end
= list_
.end();
74 for (; it
!= end
; ++it
)
79 void InsetList::setBuffer(Buffer
& b
)
81 List::iterator it
= list_
.begin();
82 List::iterator end
= list_
.end();
83 for (; it
!= end
; ++it
)
84 it
->inset
->setBuffer(b
);
88 InsetList::iterator
InsetList::insetIterator(pos_type pos
)
90 InsetTable
search_elem(pos
, 0);
91 return lower_bound(list_
.begin(), list_
.end(), search_elem
,
96 InsetList::const_iterator
InsetList::insetIterator(pos_type pos
) const
98 InsetTable
search_elem(pos
, 0);
99 return lower_bound(list_
.begin(), list_
.end(), search_elem
,
100 InsetTablePosLess());
104 void InsetList::insert(Inset
* inset
, pos_type pos
)
106 List::iterator end
= list_
.end();
107 List::iterator it
= insetIterator(pos
);
108 if (it
!= end
&& it
->pos
== pos
) {
109 LYXERR0("ERROR (InsetList::insert): "
110 << "There is an inset in position: " << pos
);
112 list_
.insert(it
, InsetTable(pos
, inset
));
117 void InsetList::erase(pos_type pos
)
119 List::iterator end
= list_
.end();
120 List::iterator it
= insetIterator(pos
);
121 if (it
!= end
&& it
->pos
== pos
) {
128 Inset
* InsetList::release(pos_type pos
)
130 List::iterator end
= list_
.end();
131 List::iterator it
= insetIterator(pos
);
132 if (it
!= end
&& it
->pos
== pos
) {
133 Inset
* tmp
= it
->inset
;
141 Inset
* InsetList::get(pos_type pos
) const
143 List::const_iterator end
= list_
.end();
144 List::const_iterator it
= insetIterator(pos
);
145 if (it
!= end
&& it
->pos
== pos
)
151 void InsetList::increasePosAfterPos(pos_type pos
)
153 List::iterator end
= list_
.end();
154 List::iterator it
= insetIterator(pos
);
155 for (; it
!= end
; ++it
)
160 void InsetList::decreasePosAfterPos(pos_type pos
)
162 List::iterator end
= list_
.end();
163 List::iterator it
= insetIterator(pos
);
164 for (; it
!= end
; ++it
)
169 pos_type
InsetList::find(InsetCode code
, pos_type startpos
) const
171 List::const_iterator it
= insetIterator(startpos
);
172 List::const_iterator end
= list_
.end();
173 for (; it
!= end
; ++it
) {
174 if (it
->inset
->lyxCode() == code
)
181 int InsetList::count(InsetCode code
, pos_type startpos
) const
184 List::const_iterator it
= insetIterator(startpos
);
185 List::const_iterator end
= list_
.end();
186 for (; it
!= end
; ++it
) {
187 if (it
->inset
->lyxCode() == code
)