]> git.lyx.org Git - lyx.git/blob - src/InsetList.cpp
remove unused code
[lyx.git] / src / InsetList.cpp
1 /**
2  * \file InsetList.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Martin Vermeer
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13 #include <algorithm>
14
15 #include "InsetList.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "BranchList.h"
20
21 #include "insets/InsetBranch.h"
22
23 #include "support/debug.h"
24
25 using namespace std;
26
27 namespace lyx {
28
29
30 namespace {
31
32 typedef InsetList::InsetTable Table;
33
34 struct InsetTablePosLess
35 {
36         bool operator()(Table const & t1, Table const & t2) const
37         {
38                 return t1.pos < t2.pos;
39         }
40 };
41
42 } // namespace anon
43
44
45 InsetList::InsetList(InsetList const & il)
46 {
47         list_ = il.list_;
48         List::iterator it = list_.begin();
49         List::iterator end = list_.end();
50         for (; it != end; ++it)
51                 it->inset = it->inset->clone();
52 }
53
54
55 InsetList::~InsetList()
56 {
57         List::iterator it = list_.begin();
58         List::iterator end = list_.end();
59         for (; it != end; ++it)
60                 delete it->inset;
61 }
62
63
64 InsetList::iterator InsetList::insetIterator(pos_type pos)
65 {
66         InsetTable search_elem(pos, 0);
67         return lower_bound(list_.begin(), list_.end(), search_elem,
68                            InsetTablePosLess());
69 }
70
71
72 InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
73 {
74         InsetTable search_elem(pos, 0);
75         return lower_bound(list_.begin(), list_.end(), search_elem,
76                            InsetTablePosLess());
77 }
78
79
80 void InsetList::insert(Inset * inset, pos_type pos)
81 {
82         List::iterator end = list_.end();
83         List::iterator it = insetIterator(pos);
84         if (it != end && it->pos == pos) {
85                 LYXERR0("ERROR (InsetList::insert): "
86                        << "There is an inset in position: " << pos);
87         } else {
88                 list_.insert(it, InsetTable(pos, inset));
89         }
90 }
91
92
93 void InsetList::erase(pos_type pos)
94 {
95         List::iterator end = list_.end();
96         List::iterator it = insetIterator(pos);
97         if (it != end && it->pos == pos) {
98                 delete it->inset;
99                 list_.erase(it);
100         }
101 }
102
103
104 Inset * InsetList::release(pos_type pos)
105 {
106         List::iterator end = list_.end();
107         List::iterator it = insetIterator(pos);
108         if (it != end && it->pos == pos) {
109                 Inset * tmp = it->inset;
110                 it->inset = 0;
111                 return tmp;
112         }
113         return 0;
114 }
115
116
117 Inset * InsetList::get(pos_type pos) const
118 {
119         List::const_iterator end = list_.end();
120         List::const_iterator it = insetIterator(pos);
121         if (it != end && it->pos == pos)
122                 return it->inset;
123         return 0;
124 }
125
126
127 void InsetList::increasePosAfterPos(pos_type pos)
128 {
129         List::iterator end = list_.end();
130         List::iterator it = insetIterator(pos);
131         for (; it != end; ++it)
132                 ++it->pos;
133 }
134
135
136 void InsetList::decreasePosAfterPos(pos_type pos)
137 {
138         List::iterator end = list_.end();
139         List::iterator it = insetIterator(pos);
140         for (; it != end; ++it)
141                 --it->pos;
142 }
143
144
145 pos_type InsetList::find(InsetCode code, pos_type startpos) const
146 {
147         List::const_iterator it = insetIterator(startpos);
148         List::const_iterator end = list_.end();
149         for (; it != end ; ++it) {
150                 if (it->inset->lyxCode() == code)
151                         return it->pos;
152         }
153         return -1;
154 }
155
156
157 int InsetList::count(InsetCode code, pos_type startpos) const
158 {
159         int num = 0;
160         List::const_iterator it = insetIterator(startpos);
161         List::const_iterator end = list_.end();
162         for (; it != end ; ++it) {
163                 if (it->inset->lyxCode() == code)
164                         ++num;
165         }
166         return num;
167 }
168
169 } // namespace lyx