List.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 <initializer_list>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 using std::move;
53 
54 template<class T>
55 inline T clone(const T& t)
56 {
57  return move(T(t));
58 }
59 
60 // Forward declaration of classes
61 
62 class Istream;
63 class Ostream;
64 
65 // Forward declaration of friend functions and operators
66 template<class T> class List;
67 
68 template<class T> Istream& operator>>(Istream&, List<T>&);
69 
70 template<class T, unsigned Size> class FixedList;
71 template<class T> class PtrList;
72 
73 class SLListBase;
74 template<class LListBase, class T> class LList;
75 template<class T>
77 
78 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
79 class DynamicList;
80 
81 template<class T> class SortableList;
82 template<class T> class IndirectList;
83 template<class T> class UIndirectList;
84 template<class T> class BiIndirectList;
85 
87 
88 /*---------------------------------------------------------------------------*\
89  Class List Declaration
90 \*---------------------------------------------------------------------------*/
91 
92 template<class T>
93 class List
94 :
95  public UList<T>
96 {
97  // Private Member Functions
98 
99  //- Allocate list storage
100  inline void alloc();
101 
102  //- Reallocate list storage to the given size
103  inline void reAlloc(const label s);
104 
105  //- Copy list of given type
106  template<class List2>
107  inline void copyList(const List2&);
108 
109  //- Allocate storage and copy list of given type
110  template<class List2>
111  inline void allocCopyList(const List2&);
112 
113  //- Construct given start and end iterators and number of elements
114  template<class InputIterator>
115  inline List(InputIterator first, InputIterator last, const label s);
116 
117 
118 protected:
119 
120  //- Override size to be inconsistent with allocated storage.
121  // Use with care
122  inline void size(const label);
123 
124 
125 public:
126 
127  // Static Member Functions
128 
129  //- Return a null List
130  inline static const List<T>& null();
131 
132 
133  // Constructors
134 
135  //- Null constructor
136  inline List();
137 
138  //- Construct with given size
139  explicit List(const label);
140 
141  //- Construct with given size and value for all elements
142  List(const label, const T&);
143 
144  //- Construct with given size initializing all elements to zero
145  List(const label, const zero);
146 
147  //- Copy constructor
148  List(const List<T>&);
149 
150  //- Copy constructor from list containing another type
151  template<class T2>
152  explicit List(const List<T2>&);
153 
154  //- Move constructor
155  List(List<T>&&);
156 
157  //- Construct as copy or re-use as specified
158  List(List<T>&, bool reuse);
159 
160  //- Construct as subset
161  List(const UList<T>&, const labelUList& mapAddressing);
162 
163  //- Construct given start and end iterators
164  template<class InputIterator>
165  List(InputIterator first, InputIterator last);
166 
167  //- Construct as copy of FixedList<T, Size>
168  template<unsigned Size>
169  explicit List(const FixedList<T, Size>&);
170 
171  //- Construct as copy of PtrList<T>
172  explicit List(const PtrList<T>&);
173 
174  //- Construct as copy of SLList<T>
175  explicit List(const SLList<T>&);
176 
177  //- Construct as copy of UIndirectList<T>
178  explicit List(const UIndirectList<T>&);
179 
180  //- Construct as copy of BiIndirectList<T>
181  explicit List(const BiIndirectList<T>&);
182 
183  //- Construct from an initializer list
184  List(std::initializer_list<T>);
185 
186  //- Construct from Istream
187  List(Istream&);
188 
189  //- Clone
190  inline autoPtr<List<T>> clone() const;
191 
192 
193  //- Destructor
194  ~List();
195 
196 
197  // Related types
198 
199  //- Declare type of subList
200  typedef SubList<T> subList;
201 
202 
203  // Member Functions
204 
205  //- Return the number of elements in the UList
206  inline label size() const;
207 
208 
209  // Edit
210 
211  //- Alias for setSize(const label)
212  inline void resize(const label);
213 
214  //- Alias for setSize(const label, const T&)
215  inline void resize(const label, const T&);
216 
217  //- Reset size of List
218  void setSize(const label);
219 
220  //- Reset size of List and value for new elements
221  void setSize(const label, const T&);
222 
223  //- Clear the list, i.e. set size to zero
224  inline void clear();
225 
226  //- Append an element at the end of the list
227  inline void append(const T&);
228 
229  //- Append a List at the end of this list
230  inline void append(const UList<T>&);
231 
232  //- Append a UIndirectList at the end of this list
233  inline void append(const UIndirectList<T>&);
234 
235  //- Transfer the contents of the argument List into this list
236  // and annul the argument list
237  void transfer(List<T>&);
238 
239  //- Transfer the contents of the argument List into this list
240  // and annul the argument list
241  template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
243 
244  //- Transfer the contents of the argument List into this list
245  // and annul the argument list
246  void transfer(SortableList<T>&);
247 
248  //- Return subscript-checked element of UList
249  inline T& newElmt(const label);
250 
251 
252  //- Disallow implicit shallowCopy
253  void shallowCopy(const UList<T>&) = delete;
254 
255 
256  // Member Operators
257 
258  //- Assignment to UList operator. Takes linear time
259  void operator=(const UList<T>&);
260 
261  //- Assignment operator. Takes linear time
262  void operator=(const List<T>&);
263 
264  //- Move assignment operator
265  void operator=(List<T>&&);
266 
267  //- Assignment to SLList operator. Takes linear time
268  void operator=(const SLList<T>&);
269 
270  //- Assignment to UIndirectList operator. Takes linear time
271  void operator=(const UIndirectList<T>&);
272 
273  //- Assignment to BiIndirectList operator. Takes linear time
274  void operator=(const BiIndirectList<T>&);
275 
276  //- Assignment to an initializer list
277  void operator=(std::initializer_list<T>);
278 
279  //- Assignment of all entries to the given value
280  inline void operator=(const T&);
281 
282  //- Assignment of all entries to zero
283  inline void operator=(const zero);
284 
285 
286  // Istream operator
287 
288  //- Read List from Istream, discarding contents of existing List
289  friend Istream& operator>> <T>
290  (Istream&, List<T>&);
291 };
292 
293 
294 //- Read a bracket-delimited list, or handle a single value as list of size 1
295 // For example,
296 // \code
297 // wList = readList<word>(IStringStream("(patch1 patch2 patch3)")());
298 // wList = readList<word>(IStringStream("patch0")());
299 // \endcode
300 // Mostly useful for handling command-line arguments
301 template<class T>
303 
304 
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 
307 } // End namespace Foam
308 
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
310 
311 #include "ListI.H"
312 
313 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
314 
315 #ifdef NoRepository
316  #include "List.C"
317 #endif
318 
319 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 
321 #endif
322 
323 // ************************************************************************* //
UList< label > unallocLabelList
Definition: List.H:83
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
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
A list that is sorted upon construction or when explicitly requested with the sort() method...
Definition: List.H:80
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:152
Base singly-linked list.
Definition: SLListBase.H:50
SubList< T > subList
Declare type of subList.
Definition: List.H:199
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:118
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:138
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))
T clone(const T &t)
Definition: List.H:54
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:125
Istream & operator>>(Istream &, directionInfo &)
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
List()
Null constructor.
Definition: ListI.H:104
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:70
A List with indirect addressing.
Definition: fvMatrix.H:106
autoPtr< List< T > > clone() const
Clone.
Definition: ListI.H:109
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:171
A List with indirect addressing.
Definition: IndirectList.H:101
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
Namespace for OpenFOAM.