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 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward declaration of classes
53 
54 class Istream;
55 class Ostream;
56 
57 // Forward declaration of friend functions and operators
58 template<class T> class List;
59 
60 template<class T> Istream& operator>>(Istream&, List<T>&);
61 
62 template<class T, unsigned Size> class FixedList;
63 template<class T> class PtrList;
64 template<class T> class SLList;
65 
66 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
67 class DynamicList;
68 
69 template<class T> class SortableList;
70 template<class T> class IndirectList;
71 template<class T> class UIndirectList;
72 template<class T> class BiIndirectList;
73 
75 
76 /*---------------------------------------------------------------------------*\
77  Class List Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 template<class T>
81 class List
82 :
83  public UList<T>
84 {
85 
86 protected:
87 
88  //- Override size to be inconsistent with allocated storage.
89  // Use with care
90  inline void size(const label);
91 
92 
93 public:
94 
95  // Static Member Functions
96 
97  //- Return a null List
98  inline static const List<T>& null();
99 
100  // Constructors
101 
102  //- Null constructor
103  inline List();
104 
105  //- Construct with given size
106  explicit List(const label);
107 
108  //- Construct with given size and value for all elements
109  List(const label, const T&);
110 
111  //- Construct with given size initializing all elements to zero
112  List(const label, const zero);
113 
114  //- Copy constructor
115  List(const List<T>&);
116 
117  //- Construct by transferring the parameter contents
118  List(const Xfer<List<T>>&);
119 
120  //- Construct as copy or re-use as specified
121  List(List<T>&, bool reuse);
122 
123  //- Construct as subset
124  List(const UList<T>&, const labelUList& mapAddressing);
125 
126  //- Construct as copy of FixedList<T, Size>
127  template<unsigned Size>
128  explicit List(const FixedList<T, Size>&);
129 
130  //- Construct as copy of PtrList<T>
131  explicit List(const PtrList<T>&);
132 
133  //- Construct as copy of SLList<T>
134  explicit List(const SLList<T>&);
135 
136  //- Construct as copy of UIndirectList<T>
137  explicit List(const UIndirectList<T>&);
138 
139  //- Construct as copy of BiIndirectList<T>
140  explicit List(const BiIndirectList<T>&);
141 
142  //- Construct from Istream
143  List(Istream&);
144 
145  //- Clone
146  inline autoPtr<List<T>> clone() const;
147 
148 
149  //- Destructor
150  ~List();
151 
152 
153  // Related types
154 
155  //- Declare type of subList
156  typedef SubList<T> subList;
157 
158 
159  // Member Functions
160 
161  //- Return the number of elements in the UList
162  inline label size() const;
163 
164 
165  // Edit
166 
167  //- Alias for setSize(const label)
168  inline void resize(const label);
169 
170  //- Alias for setSize(const label, const T&)
171  inline void resize(const label, const T&);
172 
173  //- Reset size of List
174  void setSize(const label);
175 
176  //- Reset size of List and value for new elements
177  void setSize(const label, const T&);
178 
179  //- Clear the list, i.e. set size to zero
180  void clear();
181 
182  //- Append an element at the end of the list
183  inline void append(const T&);
184 
185  //- Append a List at the end of this list
186  inline void append(const UList<T>&);
187 
188  //- Append a UIndirectList at the end of this list
189  inline void append(const UIndirectList<T>&);
190 
191  //- Transfer the contents of the argument List into this list
192  // and annul the argument list
193  void transfer(List<T>&);
194 
195  //- Transfer the contents of the argument List into this list
196  // and annul the argument list
197  template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
199 
200  //- Transfer the contents of the argument List into this list
201  // and annul the argument list
202  void transfer(SortableList<T>&);
203 
204  //- Transfer contents to the Xfer container
205  inline Xfer<List<T>> xfer();
206 
207  //- Return subscript-checked element of UList
208  inline T& newElmt(const label);
209 
210 
211  //- Disallow implicit shallowCopy
212  void shallowCopy(const UList<T>&) = delete;
213 
214 
215  // Member operators
216 
217  //- Assignment from UList operator. Takes linear time
218  void operator=(const UList<T>&);
219 
220  //- Assignment operator. Takes linear time
221  void operator=(const List<T>&);
222 
223  //- Assignment from SLList operator. Takes linear time
224  void operator=(const SLList<T>&);
225 
226  //- Assignment from UIndirectList operator. Takes linear time
227  void operator=(const UIndirectList<T>&);
228 
229  //- Assignment from BiIndirectList operator. Takes linear time
230  void operator=(const BiIndirectList<T>&);
231 
232  //- Assignment of all entries to the given value
233  inline void operator=(const T&);
234 
235  //- Assignment of all entries to zero
236  inline void operator=(const zero);
237 
238 
239  // Istream operator
240 
241  //- Read List from Istream, discarding contents of existing List
242  friend Istream& operator>> <T>
243  (Istream&, List<T>&);
244 };
245 
246 
247 //- Read a bracket-delimited list, or handle a single value as list of size 1
248 // For example,
249 // \code
250 // wList = readList<word>(IStringStream("(patch1 patch2 patch3)")());
251 // wList = readList<word>(IStringStream("patch0")());
252 // \endcode
253 // Mostly useful for handling command-line arguments
254 template<class T>
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace Foam
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #include "ListI.H"
265 
266 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
267 
268 #ifdef NoRepository
269  #include "List.C"
270 #endif
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #endif
275 
276 // ************************************************************************* //
UList< label > unallocLabelList
Definition: List.H:71
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:53
Xfer< List< T > > xfer()
Transfer contents to the Xfer container.
Definition: ListI.H:90
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:68
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:286
T & newElmt(const label)
Return subscript-checked element of UList.
Definition: ListI.H:64
SubList< T > subList
Declare type of subList.
Definition: List.H:155
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:43
void resize(const label)
Alias for setSize(const label)
Definition: ListI.H:50
A List obtained as a section of another List.
Definition: SubList.H:53
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: List.C:356
Istream & operator>>(Istream &, directionInfo &)
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:97
Non-intrusive singly-linked list.
Definition: SLList.H:47
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
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
label size() const
Return the number of elements in the UList.
Definition: ListI.H:83
List()
Null constructor.
Definition: ListI.H:29
Indexes into negList (negative index) or posList (zero or positive index).
void operator=(const UList< T > &)
Assignment from UList operator. Takes linear time.
Definition: List.C:399
void setSize(const label)
Reset size of List.
Definition: List.C:295
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:62
A List with indirect addressing.
Definition: fvMatrix.H:106
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:53
autoPtr< List< T > > clone() const
Clone.
Definition: ListI.H:34
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:365
Namespace for OpenFOAM.