List.H 8.36 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    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 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    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
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
23
24
25
26
27
28
29

Class
    Foam::List

Description
    A 1D array of objects of type \<T\>, where the size of the vector
    is known and used for subscript bounds checking, etc.
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
    Storage is allocated on free-store during construction.

SourceFiles
    List.C
    ListI.H
    ListIO.C

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

#ifndef List_H
#define List_H

#include "UList.H"
#include "autoPtr.H"
Mark Olesen's avatar
Mark Olesen committed
45
#include "Xfer.H"
46
#include <initializer_list>
47
48
49
50
51
52

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

namespace Foam
{

53
54
// Forward declaration of classes

55
56
57
58
59
60
61
62
class Istream;
class Ostream;

// Forward declaration of friend functions and operators
template<class T> class List;

template<class T> Istream& operator>>(Istream&, List<T>&);

Mark Olesen's avatar
Mark Olesen committed
63
template<class T, unsigned Size> class FixedList;
64
65
template<class T> class PtrList;
template<class T> class SLList;
66

mattijs's avatar
mattijs committed
67
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
68
69
class DynamicList;

70
template<class T> class SortableList;
71
template<class T> class IndirectList;
mattijs's avatar
mattijs committed
72
template<class T> class UIndirectList;
73
74
template<class T> class BiIndirectList;

mattijs's avatar
mattijs committed
75
typedef UList<label> unallocLabelList;
76
77
78
79
80
81
82
83
84
85

/*---------------------------------------------------------------------------*\
                           Class List Declaration
\*---------------------------------------------------------------------------*/

template<class T>
class List
:
    public UList<T>
{
86
87
88
89
90
91
92
93
94
95
    // Private member functions

        //- Copy list of given type
        template<class List2>
        void CopyList(const List2&);

        //- Construct given start and end iterators and number of elements
        template<class InputIterator>
        List(InputIterator first, InputIterator last, const label s);

96

97
98
99
protected:

    //- Override size to be inconsistent with allocated storage.
100
    //  Use with care
101
102
    inline void size(const label);

Andrew Heather's avatar
Andrew Heather committed
103

104
105
public:

106
107
108
109
110
    // Static Member Functions

        //- Return a null List
        inline static const List<T>& null();

111

112
113
    // Constructors

114
        //- Null constructor
115
116
        inline List();

117
        //- Construct with given size
118
119
        explicit List(const label);

120
        //- Construct with given size and value for all elements
121
122
        List(const label, const T&);

123
        //- Construct with given size initializing all elements to zero
124
125
        List(const label, const zero);

126
        //- Copy constructor
127
128
        List(const List<T>&);

129
        //- Copy constructor from list containing another type
130
131
132
        template<class T2>
        explicit List(const List<T2>&);

133
        //- Construct by transferring the parameter contents
134
        List(const Xfer<List<T>>&);
135

136
        //- Construct as copy or re-use as specified
137
        List(List<T>&, bool reuse);
138

139
        //- Construct as subset
140
        List(const UList<T>&, const labelUList& mapAddressing);
mattijs's avatar
mattijs committed
141

142
143
144
145
        //- Construct given start and end iterators
        template<class InputIterator>
        List(InputIterator first, InputIterator last);

146
        //- Construct as copy of FixedList<T, Size>
Mark Olesen's avatar
Mark Olesen committed
147
        template<unsigned Size>
mattijs's avatar
mattijs committed
148
        explicit List(const FixedList<T, Size>&);
149
150

        //- Construct as copy of PtrList<T>
mattijs's avatar
mattijs committed
151
        explicit List(const PtrList<T>&);
152
153

        //- Construct as copy of SLList<T>
mattijs's avatar
mattijs committed
154
        explicit List(const SLList<T>&);
155

mattijs's avatar
mattijs committed
156
        //- Construct as copy of UIndirectList<T>
mattijs's avatar
mattijs committed
157
        explicit List(const UIndirectList<T>&);
mattijs's avatar
mattijs committed
158

159
        //- Construct as copy of BiIndirectList<T>
mattijs's avatar
mattijs committed
160
        explicit List(const BiIndirectList<T>&);
161

162
163
164
        //- Construct from an initializer list
        List(std::initializer_list<T> lst);

165
        //- Construct from Istream
166
167
168
        List(Istream&);

        //- Clone
169
        inline autoPtr<List<T>> clone() const;
170
171


Andrew Heather's avatar
Andrew Heather committed
172
173
    //- Destructor
    ~List();
174
175
176
177
178
179
180
181


    // Related types

        //- Declare type of subList
        typedef SubList<T> subList;


182
    // Member Functions
183

184
        //- Return the number of elements in the UList
mattijs's avatar
mattijs committed
185
186
        inline label size() const;

187
188
189

        // Edit

190
            //- Alias for setSize(const label)
191
192
            inline void resize(const label);

193
            //- Alias for setSize(const label, const T&)
194
195
            inline void resize(const label, const T&);

196
            //- Reset size of List
197
198
            void setSize(const label);

199
            //- Reset size of List and value for new elements
200
201
            void setSize(const label, const T&);

202
            //- Clear the list, i.e. set size to zero
203
204
            void clear();

205
206
207
            //- Append an element at the end of the list
            inline void append(const T&);

Mark Olesen's avatar
Mark Olesen committed
208
            //- Append a List at the end of this list
Mark Olesen's avatar
Mark Olesen committed
209
            inline void append(const UList<T>&);
Mark Olesen's avatar
Mark Olesen committed
210
211

            //- Append a UIndirectList at the end of this list
Mark Olesen's avatar
Mark Olesen committed
212
            inline void append(const UIndirectList<T>&);
Mark Olesen's avatar
Mark Olesen committed
213

Mark Olesen's avatar
Mark Olesen committed
214
            //- Transfer the contents of the argument List into this list
215
            //  and annul the argument list
216
217
            void transfer(List<T>&);

Mark Olesen's avatar
Mark Olesen committed
218
            //- Transfer the contents of the argument List into this list
219
            //  and annul the argument list
mattijs's avatar
mattijs committed
220
221
222
            template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
            void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);

Mark Olesen's avatar
Mark Olesen committed
223
            //- Transfer the contents of the argument List into this list
224
            //  and annul the argument list
225
226
            void transfer(SortableList<T>&);

Mark Olesen's avatar
Mark Olesen committed
227
            //- Transfer contents to the Xfer container
228
            inline Xfer<List<T>> xfer();
229

230
            //- Return subscript-checked element of UList
231
232
            inline T& newElmt(const label);

233
234
235
236
237

        //- Disallow implicit shallowCopy
        void shallowCopy(const UList<T>&) = delete;


238
239
    // Member operators

240
        //- Assignment from UList operator. Takes linear time
241
242
        void operator=(const UList<T>&);

243
        //- Assignment operator. Takes linear time
244
245
        void operator=(const List<T>&);

246
        //- Assignment from SLList operator. Takes linear time
247
248
        void operator=(const SLList<T>&);

249
        //- Assignment from UIndirectList operator. Takes linear time
mattijs's avatar
mattijs committed
250
251
        void operator=(const UIndirectList<T>&);

252
        //- Assignment from BiIndirectList operator. Takes linear time
253
254
255
256
257
        void operator=(const BiIndirectList<T>&);

        //- Assignment of all entries to the given value
        inline void operator=(const T&);

258
259
260
        //- Assignment of all entries to zero
        inline void operator=(const zero);

261
262
263

    // Istream operator

264
        //- Read List from Istream, discarding contents of existing List
Henry Weller's avatar
Henry Weller committed
265
        friend Istream& operator>> <T>
266
267
268
269
        (Istream&, List<T>&);
};


270
//- Read a bracket-delimited list, or handle a single value as list of size 1
Mark Olesen's avatar
Mark Olesen committed
271
//  For example,
272
//  \code
Mark Olesen's avatar
Mark Olesen committed
273
274
//      wList = readList<word>(IStringStream("(patch1 patch2 patch3)")());
//      wList = readList<word>(IStringStream("patch0")());
275
//  \endcode
276
//  Mostly useful for handling command-line arguments
277
template<class T>
Mark Olesen's avatar
Mark Olesen committed
278
279
List<T> readList(Istream&);

280
281
282
283
284
285
286

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

} // End namespace Foam

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

287
#include "ListI.H"
288
289
290
291

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

#ifdef NoRepository
292
    #include "List.C"
293
294
295
296
297
298
299
#endif

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

#endif

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