List.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  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 Class
25  Foam::List
26 
27 Description
28  A 1D array of objects of type <T>, where the size of the vector
29  is known and used for subscript bounds checking, etc.
30 
31  Storage is allocated on free-store during construction.
32 
33 SourceFiles
34  List.C
35  ListI.H
36  ListIO.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef List_H
41 #define List_H
42 
43 #include "UList.H"
44 #include "autoPtr.H"
45 #include "Xfer.H"
46 #include <initializer_list>
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declaration of classes
54 
55 class Istream;
56 class Ostream;
57 
58 // Forward declaration of friend functions and operators
59 template<class T> class List;
60 
61 template<class T> Istream& operator>>(Istream&, List<T>&);
62 
63 template<class T, unsigned Size> class FixedList;
64 template<class T> class PtrList;
65 
66 class SLListBase;
67 template<class LListBase, class T> class LList;
68 template<class T>
70 
71 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
72 class DynamicList;
73 
74 template<class T> class SortableList;
75 template<class T> class IndirectList;
76 template<class T> class UIndirectList;
77 template<class T> class BiIndirectList;
78 
80 
81 /*---------------------------------------------------------------------------*\
82  Class List Declaration
83 \*---------------------------------------------------------------------------*/
84 
85 template<class T>
86 class List
87 :
88  public UList<T>
89 {
90  // Private member functions
91 
92  //- Allocate list storage
93  inline void alloc();
94 
95  //- Reallocate list storage to the given size
96  inline void reAlloc(const label s);
97 
98  //- Copy list of given type
99  template<class List2>
100  inline void copyList(const List2&);
101 
102  //- Allocate storage and copy list of given type
103  template<class List2>
104  inline void allocCopyList(const List2&);
105 
106  //- Construct given start and end iterators and number of elements
107  template<class InputIterator>
108  inline List(InputIterator first, InputIterator last, const label s);
109 
110 
111 protected:
112 
113  //- Override size to be inconsistent with allocated storage.
114  // Use with care
115  inline void size(const label);
116 
117 
118 public:
119 
120  // Static Member Functions
121 
122  //- Return a null List
123  inline static const List<T>& null();
124 
125 
126  // Constructors
127 
128  //- Null constructor
129  inline List();
130 
131  //- Construct with given size
132  explicit List(const label);
133 
134  //- Construct with given size and value for all elements
135  List(const label, const T&);
136 
137  //- Construct with given size initializing all elements to zero
138  List(const label, const zero);
139 
140  //- Copy constructor
141  List(const List<T>&);
142 
143  //- Copy constructor from list containing another type
144  template<class T2>
145  explicit List(const List<T2>&);
146 
147  //- Construct by transferring the parameter contents
148  List(const Xfer<List<T>>&);
149 
150  //- Construct as copy or re-use as specified
151  List(List<T>&, bool reuse);
152 
153  //- Construct as subset
154  List(const UList<T>&, const labelUList& mapAddressing);
155 
156  //- Construct given start and end iterators
157  template<class InputIterator>
158  List(InputIterator first, InputIterator last);
159 
160  //- Construct as copy of FixedList<T, Size>
161  template<unsigned Size>
162  explicit List(const FixedList<T, Size>&);
163 
164  //- Construct as copy of PtrList<T>
165  explicit List(const PtrList<T>&);
166 
167  //- Construct as copy of SLList<T>
168  explicit List(const SLList<T>&);
169 
170  //- Construct as copy of UIndirectList<T>
171  explicit List(const UIndirectList<T>&);
172 
173  //- Construct as copy of BiIndirectList<T>
174  explicit List(const BiIndirectList<T>&);
175 
176  //- Construct from an initializer list
177  List(std::initializer_list<T>);
178 
179  //- Construct from Istream
180  List(Istream&);
181 
182  //- Clone
183  inline autoPtr<List<T>> clone() const;
184 
185 
186  //- Destructor
187  ~List();
188 
189 
190  // Related types
191 
192  //- Declare type of subList
193  typedef SubList<T> subList;
194 
195 
196  // Member Functions
197 
198  //- Return the number of elements in the UList
199  inline label size() const;
200 
201 
202  // Edit
203 
204  //- Alias for setSize(const label)
205  inline void resize(const label);
206 
207  //- Alias for setSize(const label, const T&)
208  inline void resize(const label, const T&);
209 
210  //- Reset size of List
211  void setSize(const label);
212 
213  //- Reset size of List and value for new elements
214  void setSize(const label, const T&);
215 
216  //- Clear the list, i.e. set size to zero
217  inline void clear();
218 
219  //- Append an element at the end of the list
220  inline void append(const T&);
221 
222  //- Append a List at the end of this list
223  inline void append(const UList<T>&);
224 
225  //- Append a UIndirectList at the end of this list
226  inline void append(const UIndirectList<T>&);
227 
228  //- Transfer the contents of the argument List into this list
229  // and annul the argument list
230  void transfer(List<T>&);
231 
232  //- Transfer the contents of the argument List into this list
233  // and annul the argument list
234  template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
236 
237  //- Transfer the contents of the argument List into this list
238  // and annul the argument list
239  void transfer(SortableList<T>&);
240 
241  //- Transfer contents to the Xfer container
242  inline Xfer<List<T>> xfer();
243 
244  //- Return subscript-checked element of UList
245  inline T& newElmt(const label);
246 
247 
248  //- Disallow implicit shallowCopy
249  void shallowCopy(const UList<T>&) = delete;
250 
251 
252  // Member operators
253 
254  //- Assignment to UList operator. Takes linear time
255  void operator=(const UList<T>&);
256 
257  //- Assignment operator. Takes linear time
258  void operator=(const List<T>&);
259 
260  //- Assignment to SLList operator. Takes linear time
261  void operator=(const SLList<T>&);
262 
263  //- Assignment to UIndirectList operator. Takes linear time
264  void operator=(const UIndirectList<T>&);
265 
266  //- Assignment to BiIndirectList operator. Takes linear time
267  void operator=(const BiIndirectList<T>&);
268 
269  //- Assignment to an initializer list
270  void operator=(std::initializer_list<T>);
271 
272  //- Assignment of all entries to the given value
273  inline void operator=(const T&);
274 
275  //- Assignment of all entries to zero
276  inline void operator=(const zero);
277 
278 
279  // Istream operator
280 
281  //- Read List from Istream, discarding contents of existing List
282  friend Istream& operator>> <T>
283  (Istream&, List<T>&);
284 };
285 
286 
287 //- Read a bracket-delimited list, or handle a single value as list of size 1
288 // For example,
289 // \code
290 // wList = readList<word>(IStringStream("(patch1 patch2 patch3)")());
291 // wList = readList<word>(IStringStream("patch0")());
292 // \endcode
293 // Mostly useful for handling command-line arguments
294 template<class T>
296 
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 } // End namespace Foam
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 #include "ListI.H"
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 #ifdef NoRepository
309  #include "List.C"
310 #endif
311 
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 
314 #endif
315 
316 // ************************************************************************* //
UList< label > unallocLabelList
Definition: List.H:76
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:54
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:177
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
A list that is sorted upon construction or when explicitly requested with the sort() method...
Definition: List.H:73
Template class for non-intrusive linked lists.
Definition: LList.H:51
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
~List()
Destructor.
Definition: List.C:269
T & newElmt(const label)
Return subscript-checked element of UList.
Definition: ListI.H:151
Base singly-linked list.
Definition: SLListBase.H:50
SubList< T > subList
Declare type of subList.
Definition: List.H:192
List< T > readList(Istream &)
Read a bracket-delimited list, or handle a single value as list of size 1.
static const List< T > & null()
Return a null List.
Definition: ListI.H:117
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:137
T & first()
Return the first element of the list.
Definition: UListI.H:114
A List obtained as a section of another List.
Definition: SubList.H:53
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
void shallowCopy(const UList< T > &)=delete
Disallow implicit shallowCopy.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:124
Istream & operator>>(Istream &, directionInfo &)
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:61
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
List()
Null constructor.
Definition: ListI.H:103
Indexes into negList (negative index) or posList (zero or positive index).
void operator=(const UList< T > &)
Assignment to UList operator. Takes linear time.
Definition: List.C:376
void setSize(const label)
Reset size of List.
Definition: List.C:281
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
A List with indirect addressing.
Definition: fvMatrix.H:106
autoPtr< List< T > > clone() const
Clone.
Definition: ListI.H:108
A class representing the concept of 0 used to avoid unnecessary manipulations for objects that are kn...
Definition: zero.H:49
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
T & last()
Return the last element of the list.
Definition: UListI.H:128
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170
A List with indirect addressing.
Definition: IndirectList.H:102
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
Namespace for OpenFOAM.