initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / containers / LinkedLists / linkTypes / SLListBase / SLListBase.H
blobb5c957a537020bd534dcd5a7670b413606516201
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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::SLListBase
28 Description
29     Base singly-linked list.
31 SourceFiles
32     SLListBase.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef SLListBase_H
37 #define SLListBase_H
39 #include "bool.H"
40 #include "label.H"
41 #include "uLabel.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 /*---------------------------------------------------------------------------*\
49                            Class SLListBase Declaration
50 \*---------------------------------------------------------------------------*/
52 class SLListBase
55 public:
57     //- Link structure
58     struct link
59     {
60         //- Pointer to next entry in list
61         link* next_;
63         //- Null construct
64         inline link();
66         //- Construct given pointer to another link
67         inline link(link* p);
68     };
71 private:
73     // Private data
75        //- last_ points to last element
76        //  last_->next_ points to first element, i.e. circular storage
77        link* last_;
79        //- Number of elements in in list
80        label nElmts_;
82     // Private member functions
84         //- Disallow default bitwise copy construct
85         SLListBase(const SLListBase&);
87         //- Disallow default bitwise assignment
88         void operator=(const SLListBase&);
91 public:
93     // Forward declaration of STL iterators
95         class iterator;
96         friend class iterator;
98         class const_iterator;
99         friend class const_iterator;
102     // Constructors
104         //- Null construct
105         inline SLListBase();
107         //- Construct given initial entry
108         inline SLListBase(link*);
111     // Destructor
113         ~SLListBase();
116     // Member Functions
118         // Access
120             //- Return number of elements in list
121             inline label size() const;
123             //- Return true if the list is empty
124             inline bool empty() const;
126             //- Return first entry
127             inline link* first();
129             //- Return const access to first entry
130             inline const link* first() const;
132             //- Return last entry
133             inline link* last();
135             //- Return const access to last entry
136             inline const link* last() const;
139         // Edit
141             //- Add at head of list
142             void insert(link*);
144             //- Add at tail of list
145             void append(link*);
147             //- Remove and return head
148             link* removeHead();
150             // Remove and return element
151             link* remove(link*);
153             // Remove and return element specified by iterator
154             inline link* remove(iterator&);
156             //- Clear the list
157             inline void clear();
159             //- Transfer the contents of the argument into this List
160             //  and annull the argument list.
161             inline void transfer(SLListBase&);
163     // STL iterator
165         //- An STL-conforming iterator
166         class iterator
167         {
168             friend class SLListBase;
169             friend class const_iterator;
171             // Private data
173                 //- Reference to the list this is an iterator for
174                 SLListBase& curList_;
176                 //- Current element
177                 link* curElmt_;
179                 //- Copy of the link
180                 link curLink_;
182             // Private Member Functions
184             //- Construct for a given SLListBase with NULL element and link.
185             //  Only used to create endIter
186             inline iterator(SLListBase&);
188         public:
190             //- Construct for a given SLListBase and link
191             inline iterator(SLListBase&, link*);
193             // Member operators
195                 inline void operator=(const iterator&);
197                 inline bool operator==(const iterator&) const;
198                 inline bool operator!=(const iterator&) const;
200                 inline link& operator*();
202                 inline iterator& operator++();
203                 inline iterator operator++(int);
204         };
206         inline iterator begin();
207         inline const iterator& end();
210     // STL const_iterator
212         //- An STL-conforming const_iterator
213         class const_iterator
214         {
215             // Private data
217                 //- Reference to the list this is an iterator for
218                 const SLListBase& curList_;
220                 //- Current element
221                 const link* curElmt_;
223         public:
225             //- Construct for a given SLListBase and link
226             inline const_iterator(const SLListBase&, const link*);
228             //- Construct from a non-const iterator
229             inline const_iterator(const iterator&);
232             // Member operators
234                 inline void operator=(const const_iterator&);
236                 inline bool operator==(const const_iterator&) const;
237                 inline bool operator!=(const const_iterator&) const;
239                 inline const link& operator*();
241                 inline const_iterator& operator++();
242                 inline const_iterator operator++(int);
243         };
245         inline const_iterator cbegin() const;
246         inline const const_iterator& cend() const;
248         inline const_iterator begin() const;
249         inline const const_iterator& end() const;
252 private:
254         //- iterator returned by end()
255         static iterator endIter_;
257         //- const_iterator returned by end()
258         static const_iterator endConstIter_;
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 } // End namespace Foam
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 #include "SLListBaseI.H"
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 #endif
274 // ************************************************************************* //