List.H 7.78 KB
Newer Older
Henry's avatar
Henry committed
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 OpenFOAM Foundation
Henry's avatar
Henry committed
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
41
42
43
44
45
46
47
48
49
50
51
     \\/     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 3 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, see <http://www.gnu.org/licenses/>.

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.

    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"
#include "Xfer.H"

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

namespace Foam
{

52
53
// Forward declaration of classes

Henry's avatar
Henry committed
54
55
56
57
58
59
60
61
62
63
64
class Istream;
class Ostream;

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

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

template<class T, unsigned Size> class FixedList;
template<class T> class PtrList;
template<class T> class SLList;
65

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

Henry's avatar
Henry committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
template<class T> class SortableList;
template<class T> class IndirectList;
template<class T> class UIndirectList;
template<class T> class BiIndirectList;

typedef UList<label> unallocLabelList;

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

template<class T>
class List
:
    public UList<T>
{

protected:

    //- Override size to be inconsistent with allocated storage.
89
    //  Use with care
Henry's avatar
Henry committed
90
91
92
93
94
95
96
97
98
99
100
101
    inline void size(const label);


public:

    // Static Member Functions

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

    // Constructors

102
        //- Null constructor
Henry's avatar
Henry committed
103
104
        inline List();

105
        //- Construct with given size
Henry's avatar
Henry committed
106
107
        explicit List(const label);

108
        //- Construct with given size and value for all elements
Henry's avatar
Henry committed
109
110
        List(const label, const T&);

111
        //- Construct with given size initializing all elements to zero
112
113
        List(const label, const zero);

114
        //- Copy constructor
Henry's avatar
Henry committed
115
116
        List(const List<T>&);

117
118
119
120
        //- Copy constructor from list of another type
        template<class T2>
        explicit List(const List<T2>&);

Henry's avatar
Henry committed
121
        //- Construct by transferring the parameter contents
122
        List(const Xfer<List<T>>&);
Henry's avatar
Henry committed
123

124
        //- Construct as copy or re-use as specified
125
        List(List<T>&, bool reuse);
Henry's avatar
Henry committed
126

127
        //- Construct as subset
Henry's avatar
Henry committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
        List(const UList<T>&, const labelUList& mapAddressing);

        //- Construct as copy of FixedList<T, Size>
        template<unsigned Size>
        explicit List(const FixedList<T, Size>&);

        //- Construct as copy of PtrList<T>
        explicit List(const PtrList<T>&);

        //- Construct as copy of SLList<T>
        explicit List(const SLList<T>&);

        //- Construct as copy of UIndirectList<T>
        explicit List(const UIndirectList<T>&);

        //- Construct as copy of BiIndirectList<T>
        explicit List(const BiIndirectList<T>&);

146
        //- Construct from Istream
Henry's avatar
Henry committed
147
148
149
        List(Istream&);

        //- Clone
150
        inline autoPtr<List<T>> clone() const;
Henry's avatar
Henry committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164


    //- Destructor
    ~List();


    // Related types

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


    // Member Functions

165
        //- Return the number of elements in the UList
Henry's avatar
Henry committed
166
167
168
169
170
171
172
173
174
175
176
        inline label size() const;


        // Edit

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

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

177
            //- Reset size of List
Henry's avatar
Henry committed
178
179
            void setSize(const label);

180
            //- Reset size of List and value for new elements
Henry's avatar
Henry committed
181
182
            void setSize(const label, const T&);

183
            //- Clear the list, i.e. set size to zero
Henry's avatar
Henry committed
184
185
186
187
188
189
190
191
192
193
194
195
            void clear();

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

            //- Append a List at the end of this list
            inline void append(const UList<T>&);

            //- Append a UIndirectList at the end of this list
            inline void append(const UIndirectList<T>&);

            //- Transfer the contents of the argument List into this list
196
            //  and annul the argument list
Henry's avatar
Henry committed
197
198
199
            void transfer(List<T>&);

            //- Transfer the contents of the argument List into this list
200
            //  and annul the argument list
Henry's avatar
Henry committed
201
202
203
204
            template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
            void transfer(DynamicList<T, SizeInc, SizeMult, SizeDiv>&);

            //- Transfer the contents of the argument List into this list
205
            //  and annul the argument list
Henry's avatar
Henry committed
206
207
208
            void transfer(SortableList<T>&);

            //- Transfer contents to the Xfer container
209
            inline Xfer<List<T>> xfer();
Henry's avatar
Henry committed
210

211
            //- Return subscript-checked element of UList
Henry's avatar
Henry committed
212
213
            inline T& newElmt(const label);

214
215
216
217
218

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


Henry's avatar
Henry committed
219
220
    // Member operators

221
        //- Assignment from UList operator. Takes linear time
Henry's avatar
Henry committed
222
223
        void operator=(const UList<T>&);

224
        //- Assignment operator. Takes linear time
Henry's avatar
Henry committed
225
226
        void operator=(const List<T>&);

227
        //- Assignment from SLList operator. Takes linear time
Henry's avatar
Henry committed
228
229
        void operator=(const SLList<T>&);

230
        //- Assignment from UIndirectList operator. Takes linear time
Henry's avatar
Henry committed
231
232
        void operator=(const UIndirectList<T>&);

233
        //- Assignment from BiIndirectList operator. Takes linear time
Henry's avatar
Henry committed
234
235
236
237
238
        void operator=(const BiIndirectList<T>&);

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

239
240
241
        //- Assignment of all entries to zero
        inline void operator=(const zero);

Henry's avatar
Henry committed
242
243
244

    // Istream operator

245
        //- Read List from Istream, discarding contents of existing List
Henry's avatar
Henry committed
246
247
248
249
250
        friend Istream& operator>> <T>
        (Istream&, List<T>&);
};


251
//- Read a bracket-delimited list, or handle a single value as list of size 1
Henry's avatar
Henry committed
252
253
254
255
256
//  For example,
//  \code
//      wList = readList<word>(IStringStream("(patch1 patch2 patch3)")());
//      wList = readList<word>(IStringStream("patch0")());
//  \endcode
257
//  Mostly useful for handling command-line arguments
Henry's avatar
Henry committed
258
259
260
261
262
263
264
265
266
267
template<class T>
List<T> readList(Istream&);


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

} // End namespace Foam

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

268
#include "ListI.H"
Henry's avatar
Henry committed
269
270
271
272

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

#ifdef NoRepository
273
    #include "List.C"
Henry's avatar
Henry committed
274
275
276
277
278
279
280
#endif

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

#endif

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