bump product version to 4.1.6.2
[LibreOffice.git] / include / cosv / tpl / swelist.hxx
blob5c64efc29cc2489820aba579dac750b73d8a9b0d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef CSV_SWELIST_HXX
21 #define CSV_SWELIST_HXX
23 // USED SERVICES
24 // BASE CLASSES
25 // COMPONENTS
26 // PARAMETERS
27 #include <cosv/tpl/dyn.hxx>
30 namespace csv
34 template <class XX>
35 class SweListElement
37 public:
38 typedef SweListElement<XX> self;
40 SweListElement(
41 const XX & in_aObj )
42 : aObj(in_aObj), pNext(0) {}
44 const XX & Obj() const { return aObj; }
45 XX & Obj() { return aObj; }
46 self * Next() const { return pNext; }
48 void SetNext(
49 self * i_pNext )
50 { pNext = i_pNext; }
51 private:
52 XX aObj;
53 self * pNext;
58 template <class XX> class SweListIterator;
59 template <class XX> class SweListCIterator;
62 template <class XX>
63 class SweList
65 public:
66 // TYPES
67 typedef SweList<XX> self;
68 typedef XX value_type;
69 typedef SweListIterator<XX> iterator;
70 typedef SweListCIterator<XX> const_iterator;
71 private:
72 typedef SweListElement<XX> elem;
74 public:
75 // LIFECYCLE
76 SweList() : pTop(0), pTail(0) {}
77 ~SweList() { erase_all(); }
78 // OPERATIONS
79 void push_front(
80 const XX & i_aObj );
81 void pop_front();
82 void push_back(
83 const XX & i_aObj );
84 void erase_all();
86 // INQUIRY
87 const_iterator begin() const { return pTop; }
88 iterator begin() { return pTop; }
89 const_iterator end() const { return (elem*)0; }
90 iterator end() { return (elem*)0; }
91 const XX & front() const { return pTop->Obj(); }
92 XX & front() { return pTop->Obj(); }
93 const XX & back() const { return pTail->Obj(); }
94 XX & back() { return pTail->Obj(); }
96 bool empty() const { return pTop == 0; }
97 uintt size() const;
100 private:
101 // Forbiddden methods.
102 SweList(
103 const self & i_rList );
104 self & operator=(
105 const self & i_rList );
107 // DATA
108 DYN elem * pTop;
109 elem * pTail;
112 template <class XX>
113 class SweList_dyn
115 public:
116 // TYPES
117 typedef SweList_dyn<XX> self;
118 typedef SweListElement< XX* > elem;
119 typedef SweListIterator< XX* > iterator;
121 // LIFECYCLE
122 SweList_dyn() : pTop(0), pTail(0) {}
123 ~SweList_dyn() { erase_all(); }
124 // OPERATIONS
125 void push_front(
126 XX * i_pObj );
127 void push_back(
128 XX * i_pObj );
129 void pop_front();
130 void erase_all();
132 // INQUIRY
133 iterator begin() const { return pTop; }
134 iterator end() const { return (elem*)0; }
135 XX * front() const { return pTop->Obj(); }
136 XX * back() const { return pTail->Obj(); }
138 bool empty() const { return pTop == 0; }
139 uintt size() const;
141 private:
142 // Forbiddden methods.
143 SweList_dyn(
144 const self & i_rList );
145 self & operator=(
146 const self & i_rList );
148 DYN elem * pTop;
149 elem * pTail;
155 template<class XX>
156 class SweListIterator
158 public:
159 typedef SweListIterator<XX> self;
160 typedef SweListElement<XX> elem;
162 SweListIterator(
163 elem * i_pElem = 0)
164 : pElem(i_pElem) { }
166 // OPERATORS
167 XX & operator*() const { return pElem->Obj(); }
168 self & operator++() { if (pElem != 0) pElem = pElem->Next();
169 return *this; }
170 bool operator==(
171 const self & i_rIter ) const
172 { return pElem == i_rIter.pElem; }
173 bool operator!=(
174 const self & i_rIter ) const
175 { return pElem != i_rIter.pElem; }
176 private:
177 friend class SweListCIterator<XX>;
179 elem * pElem;
182 template<class XX>
183 class SweListCIterator
185 public:
186 typedef SweListCIterator<XX> self;
187 typedef SweListElement<XX> elem;
189 SweListCIterator(
190 const elem * i_pElem = 0)
191 : pElem(i_pElem) { }
193 // OPERATORS
194 self & operator=(
195 const SweListIterator<XX> &
196 i_rIter )
197 { pElem = i_rIter.pElem; return *this; }
199 const XX & operator*() const { return pElem->Obj(); }
200 self & operator++() { if (pElem != 0) pElem = pElem->Next();
201 return *this; }
202 bool operator==(
203 const self & i_rIter ) const
204 { return pElem == i_rIter.pElem; }
205 bool operator!=(
206 const self & i_rIter ) const
207 { return pElem != i_rIter.pElem; }
208 private:
209 const elem * pElem;
212 // IMPLEMENTATION
214 template <class XX>
215 void
216 SweList<XX>::push_front( const XX & i_aObj )
218 DYN elem * dpNew = new elem(i_aObj);
219 dpNew->SetNext(pTop);
220 pTop = dpNew;
221 if (pTail == 0)
222 pTail = pTop;
225 template <class XX>
226 void
227 SweList<XX>::push_back( const XX & i_aObj)
229 if (pTail != 0)
231 pTail->SetNext(new elem(i_aObj));
232 pTail = pTail->Next();
234 else
236 pTop = pTail = new elem(i_aObj);
240 template <class XX>
241 void
242 SweList<XX>::pop_front()
244 if (pTop != 0)
246 elem * pDel = pTop;
247 pTop = pTop->Next();
248 delete pDel;
249 if (pTop == 0)
250 pTail = 0;
254 template <class XX>
255 uintt
256 SweList<XX>::size() const
258 uintt ret = 0;
259 for ( const_iterator iter = begin();
260 iter != end();
261 ++iter )
263 ++ret;
265 return ret;
269 template <class XX>
270 void
271 SweList<XX>::erase_all()
273 for (pTail = pTop ; pTop != 0; pTail = pTop)
275 pTop = pTop->Next();
276 delete pTail;
278 pTop = pTail = 0;
282 template <class XX>
283 void
284 SweList_dyn<XX>::push_front( XX * i_pObj )
286 DYN elem * dpNew = new elem(i_pObj);
287 dpNew->SetNext(pTop);
288 pTop = dpNew;
289 if (pTail == 0)
290 pTail = pTop;
293 template <class XX>
294 void
295 SweList_dyn<XX>::push_back( XX * i_pObj )
297 if (pTail != 0)
299 pTail->SetNext(new elem(i_pObj));
300 pTail = pTail->Next();
302 else
304 pTop = pTail = new elem(i_pObj);
308 template <class XX>
309 void
310 SweList_dyn<XX>::pop_front()
312 if (pTop != 0)
314 elem * pDel = pTop;
315 pTop = pTop->Next();
316 if (pDel->Obj() != 0)
317 Delete_dyn(pDel->Obj());
318 delete pDel;
319 if (pTop == 0)
320 pTail = 0;
325 template <class XX>
326 void
327 SweList_dyn<XX>::erase_all()
329 for (pTail = pTop ; pTop != 0; pTail = pTop)
331 pTop = pTop->Next();
332 if (pTail->Obj() != 0)
334 delete pTail->Obj();
336 delete pTail;
338 pTop = pTail = 0;
341 template <class XX>
342 uintt
343 SweList_dyn<XX>::size() const
345 uintt ret = 0;
346 for ( iterator iter = begin();
347 iter != end();
348 ++iter )
350 ++ret;
352 return ret;
356 } // namespace csv
359 #endif
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */