initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / containers / LinkedLists / linkTypes / DLListBase / DLListBase.H
blob8fd2c55bc19592d8f3caf2876efccc29b5aa5e16
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::DLListBase
28 Description
29     Base doubly-linked list.
31 SourceFiles
32     DLListBase.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef DLListBase_H
37 #define DLListBase_H
39 #include "bool.H"
40 #include "label.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 /*---------------------------------------------------------------------------*\
48                            Class DLListBase Declaration
49 \*---------------------------------------------------------------------------*/
51 class DLListBase
54 public:
56     //- Link structure
57     struct link
58     {
59         //- Pointer to next entry in list
60         link *prev_, *next_;
62         //- Null construct
63         inline link();
65         //- Check if the link is registered with the DLListBase
66         inline bool registered() const;
68         //- Deregister the link after removal
69         inline void deregister();
70     };
73 private:
75     // Private data
77        //- first_ points to first element and last_ points to last element.
78        link *first_, *last_;
80        //- Number of elements in in list
81        label nElmts_;
84     // Private member functions
86         //- Disallow default bitwise copy construct
87         DLListBase(const DLListBase&);
89         //- Disallow default bitwise assignment
90         void operator=(const DLListBase&);
93 public:
95     // Forward declaration of STL iterators
97         class iterator;
98         friend class iterator;
100         class const_iterator;
101         friend class const_iterator;
104     // Constructors
106         //- Null construct
107         inline DLListBase();
109         //- Construct given initial entry
110         inline DLListBase(link*);
113     // Destructor
115         ~DLListBase();
118     // Member Functions
120         // Access
122             //- Return number of elements in list
123             inline label size() const;
125             //- Return first entry
126             inline link* first();
128             //- Return const access to first entry
129             inline const link* first() const;
131             //- Return last entry
132             inline link* last();
134             //- Return const access to last entry
135             inline const link* last() const;
138         // Edit
140             //- Add at head of list
141             void insert(link*);
143             //- Add at tail of list
144             void append(link*);
146             //- Swap this element with the one above unless it is at the top
147             bool swapUp(link*);
149             //- Swap this element with the one below unless it is at the bottom
150             bool swapDown(link*);
152             //- Remove and return head
153             link* removeHead();
155             //- Remove and return element
156             link* remove(link*);
158             // Remove and return element specified by iterator
159             inline link* remove(iterator&);
161             //- Replace oldLink with newLink and return element
162             link* replace(link* oldLink, link* newLink);
164             //- Replace oldIter with newLink and return element
165             inline link* replace(iterator& oldIter, link* newLink);
167             //- Clear the list
168             inline void clear();
171     // STL iterator
173         //- An STL iterator
174         class iterator
175         {
176             friend class DLListBase;
177             friend class const_iterator;
179             // Private data
181                 //- Reference to the list this is an iterator for
182                 DLListBase& curList_;
184                 //- Current element
185                 link* curElmt_;
187                 //- Copy of the link
188                 link curLink_;
190         public:
192             //- Construct for a given DLListBase and link
193             inline iterator(DLListBase&, link*);
195             //- Construct for a given DLListBase
196             //  setting element and link to NULL.
197             //  Only used to create endIter
198             inline iterator(DLListBase&);
200             // Member operators
202                 inline void operator=(const iterator&);
204                 inline bool operator==(const iterator&) const;
205                 inline bool operator!=(const iterator&) const;
207                 inline link& operator*();
209                 inline iterator& operator++();
210                 inline iterator operator++(int);
211         };
213         inline iterator begin();
215         //- iterator returned by end()
216         static iterator endIter;
218         inline const iterator& end();
221     // STL const_iterator
223         //- An STL const_iterator
224         class const_iterator
225         {
226             // Private data
228                 //- Reference to the list this is an iterator for
229                 const DLListBase& curList_;
231                 //- Current element
232                 const link* curElmt_;
234         public:
236             //- Construct for a given DLListBase and link
237             inline const_iterator(const DLListBase&, const link*);
239             //- Construct from a non-const iterator
240             inline const_iterator(const iterator&);
242             // Member operators
244                 inline void operator=(const const_iterator&);
246                 inline bool operator==(const const_iterator&) const;
247                 inline bool operator!=(const const_iterator&) const;
249                 inline const link& operator*();
251                 inline const_iterator& operator++();
252                 inline const_iterator operator++(int);
253         };
255         inline const_iterator begin() const;
257         //- const_iterator returned by end()
258         static const_iterator endConstIter;
260         inline const const_iterator& end() const;
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
266 } // End namespace Foam
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 #include "DLListBaseI.H"
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 #endif
276 // ************************************************************************* //