DLListBase.H 7.37 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Class
    Foam::DLListBase

Description
    Base doubly-linked list.

SourceFiles
    DLListBase.C

\*---------------------------------------------------------------------------*/

#ifndef DLListBase_H
#define DLListBase_H

#include "bool.H"
#include "label.H"
Mark Olesen's avatar
Mark Olesen committed
41
#include "uLabel.H"
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
                           Class DLListBase Declaration
\*---------------------------------------------------------------------------*/

class DLListBase
{

public:

    //- Link structure
    struct link
    {
        //- Pointer to next entry in list
        link *prev_, *next_;

        //- Null construct
        inline link();

        //- Check if the link is registered with the DLListBase
        inline bool registered() const;

        //- Deregister the link after removal
        inline void deregister();
    };


private:

    // Private data

       //- first_ points to first element and last_ points to last element.
       link *first_, *last_;

       //- Number of elements in in list
       label nElmts_;


    // Private member functions

        //- Disallow default bitwise copy construct
        DLListBase(const DLListBase&);

        //- Disallow default bitwise assignment
        void operator=(const DLListBase&);


public:

    // Forward declaration of STL iterators

        class iterator;
        friend class iterator;

        class const_iterator;
        friend class const_iterator;


    // Constructors

        //- Null construct
        inline DLListBase();

        //- Construct given initial entry
        inline DLListBase(link*);


    // Destructor

        ~DLListBase();


    // Member Functions

        // Access

            //- Return number of elements in list
            inline label size() const;

126
127
128
            //- Return true if the list is empty
            inline bool empty() const;

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
            //- Return first entry
            inline link* first();

            //- Return const access to first entry
            inline const link* first() const;

            //- Return last entry
            inline link* last();

            //- Return const access to last entry
            inline const link* last() const;


        // Edit

            //- Add at head of list
            void insert(link*);

            //- Add at tail of list
            void append(link*);

            //- Swap this element with the one above unless it is at the top
            bool swapUp(link*);

            //- Swap this element with the one below unless it is at the bottom
            bool swapDown(link*);

            //- Remove and return head
            link* removeHead();

            //- Remove and return element
            link* remove(link*);

            // Remove and return element specified by iterator
            inline link* remove(iterator&);

Mark Olesen's avatar
Mark Olesen committed
165
166
167
168
169
170
            //- Replace oldLink with newLink and return element
            link* replace(link* oldLink, link* newLink);

            //- Replace oldIter with newLink and return element
            inline link* replace(iterator& oldIter, link* newLink);

171
172
173
            //- Clear the list
            inline void clear();

174
175
176
            //- Transfer the contents of the argument into this List
            //  and annull the argument list.
            inline void transfer(DLListBase&);
177
178
179

    // STL iterator

180
        //- An STL-conforming iterator
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
        class iterator
        {
            friend class DLListBase;
            friend class const_iterator;

            // Private data

                //- Reference to the list this is an iterator for
                DLListBase& curList_;

                //- Current element
                link* curElmt_;

                //- Copy of the link
                link curLink_;

197
198
199
200
201
202
            // Private Member Functions

            //- Construct for a given SLListBase with NULL element and link.
            //  Only used to create endIter
            inline iterator(DLListBase&);

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
        public:

            //- Construct for a given DLListBase and link
            inline iterator(DLListBase&, link*);

            // Member operators

                inline void operator=(const iterator&);

                inline bool operator==(const iterator&) const;
                inline bool operator!=(const iterator&) const;

                inline link& operator*();

                inline iterator& operator++();
                inline iterator operator++(int);
        };

        inline iterator begin();
        inline const iterator& end();


    // STL const_iterator

227
        //- An STL-conforming const_iterator
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
        class const_iterator
        {
            // Private data

                //- Reference to the list this is an iterator for
                const DLListBase& curList_;

                //- Current element
                const link* curElmt_;

        public:

            //- Construct for a given DLListBase and link
            inline const_iterator(const DLListBase&, const link*);

            //- Construct from a non-const iterator
            inline const_iterator(const iterator&);

            // Member operators

                inline void operator=(const const_iterator&);

                inline bool operator==(const const_iterator&) const;
                inline bool operator!=(const const_iterator&) const;

                inline const link& operator*();

                inline const_iterator& operator++();
                inline const_iterator operator++(int);
        };

259
260
261
        inline const_iterator cbegin() const;
        inline const const_iterator& cend() const;

262
        inline const_iterator begin() const;
263
264
265
266
267
268
        inline const const_iterator& end() const;

private:

        //- iterator returned by end()
        static iterator endIter_;
269
270

        //- const_iterator returned by end()
271
        static const_iterator endConstIter_;
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288

};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "DLListBaseI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //