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