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()
57 List::iterator it
= list_
.begin();
58 List::iterator end
= list_
.end();
59 for (; it
!= end
; ++it
)
64 void InsetList::setBuffer(Buffer
& b
)
66 List::iterator it
= list_
.begin();
67 List::iterator end
= list_
.end();
68 for (; it
!= end
; ++it
)
69 it
->inset
->setBuffer(b
);
73 InsetList::iterator
InsetList::insetIterator(pos_type pos
)
75 InsetTable
search_elem(pos
, 0);
76 return lower_bound(list_
.begin(), list_
.end(), search_elem
,
81 InsetList::const_iterator
InsetList::insetIterator(pos_type pos
) const
83 InsetTable
search_elem(pos
, 0);
84 return lower_bound(list_
.begin(), list_
.end(), search_elem
,
89 void InsetList::insert(Inset
* inset
, pos_type pos
)
91 List::iterator end
= list_
.end();
92 List::iterator it
= insetIterator(pos
);
93 if (it
!= end
&& it
->pos
== pos
) {
94 LYXERR0("ERROR (InsetList::insert): "
95 << "There is an inset in position: " << pos
);
97 list_
.insert(it
, InsetTable(pos
, inset
));
102 void InsetList::erase(pos_type pos
)
104 List::iterator end
= list_
.end();
105 List::iterator it
= insetIterator(pos
);
106 if (it
!= end
&& it
->pos
== pos
) {
113 Inset
* InsetList::release(pos_type pos
)
115 List::iterator end
= list_
.end();
116 List::iterator it
= insetIterator(pos
);
117 if (it
!= end
&& it
->pos
== pos
) {
118 Inset
* tmp
= it
->inset
;
126 Inset
* InsetList::get(pos_type pos
) const
128 List::const_iterator end
= list_
.end();
129 List::const_iterator it
= insetIterator(pos
);
130 if (it
!= end
&& it
->pos
== pos
)
136 void InsetList::increasePosAfterPos(pos_type pos
)
138 List::iterator end
= list_
.end();
139 List::iterator it
= insetIterator(pos
);
140 for (; it
!= end
; ++it
)
145 void InsetList::decreasePosAfterPos(pos_type pos
)
147 List::iterator end
= list_
.end();
148 List::iterator it
= insetIterator(pos
);
149 for (; it
!= end
; ++it
)
154 pos_type
InsetList::find(InsetCode code
, pos_type startpos
) const
156 List::const_iterator it
= insetIterator(startpos
);
157 List::const_iterator end
= list_
.end();
158 for (; it
!= end
; ++it
) {
159 if (it
->inset
->lyxCode() == code
)
166 int InsetList::count(InsetCode code
, pos_type startpos
) const
169 List::const_iterator it
= insetIterator(startpos
);
170 List::const_iterator end
= list_
.end();
171 for (; it
!= end
; ++it
) {
172 if (it
->inset
->lyxCode() == code
)