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