1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
27 #include <cosv/tpl/dyn.hxx>
38 typedef SweListElement
<XX
> self
;
42 : aObj(in_aObj
), pNext(0) {}
44 const XX
& Obj() const { return aObj
; }
45 XX
& Obj() { return aObj
; }
46 self
* Next() const { return pNext
; }
58 template <class XX
> class SweListIterator
;
59 template <class XX
> class SweListCIterator
;
67 typedef SweList
<XX
> self
;
68 typedef XX value_type
;
69 typedef SweListIterator
<XX
> iterator
;
70 typedef SweListCIterator
<XX
> const_iterator
;
72 typedef SweListElement
<XX
> elem
;
76 SweList() : pTop(0), pTail(0) {}
77 ~SweList() { erase_all(); }
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; }
101 // Forbiddden methods.
103 const self
& i_rList
);
105 const self
& i_rList
);
117 typedef SweList_dyn
<XX
> self
;
118 typedef SweListElement
< XX
* > elem
;
119 typedef SweListIterator
< XX
* > iterator
;
122 SweList_dyn() : pTop(0), pTail(0) {}
123 ~SweList_dyn() { erase_all(); }
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; }
142 // Forbiddden methods.
144 const self
& i_rList
);
146 const self
& i_rList
);
156 class SweListIterator
159 typedef SweListIterator
<XX
> self
;
160 typedef SweListElement
<XX
> elem
;
167 XX
& operator*() const { return pElem
->Obj(); }
168 self
& operator++() { if (pElem
!= 0) pElem
= pElem
->Next();
171 const self
& i_rIter
) const
172 { return pElem
== i_rIter
.pElem
; }
174 const self
& i_rIter
) const
175 { return pElem
!= i_rIter
.pElem
; }
177 friend class SweListCIterator
<XX
>;
183 class SweListCIterator
186 typedef SweListCIterator
<XX
> self
;
187 typedef SweListElement
<XX
> elem
;
190 const elem
* i_pElem
= 0)
195 const SweListIterator
<XX
> &
197 { pElem
= i_rIter
.pElem
; return *this; }
199 const XX
& operator*() const { return pElem
->Obj(); }
200 self
& operator++() { if (pElem
!= 0) pElem
= pElem
->Next();
203 const self
& i_rIter
) const
204 { return pElem
== i_rIter
.pElem
; }
206 const self
& i_rIter
) const
207 { return pElem
!= i_rIter
.pElem
; }
216 SweList
<XX
>::push_front( const XX
& i_aObj
)
218 DYN elem
* dpNew
= new elem(i_aObj
);
219 dpNew
->SetNext(pTop
);
227 SweList
<XX
>::push_back( const XX
& i_aObj
)
231 pTail
->SetNext(new elem(i_aObj
));
232 pTail
= pTail
->Next();
236 pTop
= pTail
= new elem(i_aObj
);
242 SweList
<XX
>::pop_front()
256 SweList
<XX
>::size() const
259 for ( const_iterator iter
= begin();
271 SweList
<XX
>::erase_all()
273 for (pTail
= pTop
; pTop
!= 0; pTail
= pTop
)
284 SweList_dyn
<XX
>::push_front( XX
* i_pObj
)
286 DYN elem
* dpNew
= new elem(i_pObj
);
287 dpNew
->SetNext(pTop
);
295 SweList_dyn
<XX
>::push_back( XX
* i_pObj
)
299 pTail
->SetNext(new elem(i_pObj
));
300 pTail
= pTail
->Next();
304 pTop
= pTail
= new elem(i_pObj
);
310 SweList_dyn
<XX
>::pop_front()
316 if (pDel
->Obj() != 0)
317 Delete_dyn(pDel
->Obj());
327 SweList_dyn
<XX
>::erase_all()
329 for (pTail
= pTop
; pTop
!= 0; pTail
= pTop
)
332 if (pTail
->Obj() != 0)
343 SweList_dyn
<XX
>::size() const
346 for ( iterator iter
= begin();
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */