DynamicField.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 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::DynamicField
26 
27 Description
28  Dynamically sized Field.
29 
30 SourceFiles
31  DynamicFieldI.H
32  DynamicField.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef DynamicField_H
37 #define DynamicField_H
38 
39 #include "Field.H"
40 #include "StaticAssert.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 // Forward declaration of friend functions and operators
48 
49 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
50 class DynamicField;
51 
52 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
53 Ostream& operator<<
54 (
55  Ostream&,
57 );
58 
59 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
60 Istream& operator>>
61 (
62  Istream&,
64 );
65 
66 
67 /*---------------------------------------------------------------------------*\
68  Class DynamicField Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 template<class T, unsigned SizeInc=0, unsigned SizeMult=2, unsigned SizeDiv=1>
72 class DynamicField
73 :
74  public Field<T>
75 {
76  //- Avoid invalid sizing parameters
77  StaticAssert((SizeInc || SizeMult) && SizeDiv);
78 
79  // Private data
80 
81  //- The capacity (allocated size) of the underlying field.
83 
84 
85 public:
86 
87  // Static Member Functions
88 
89  //- Return a null field
90  inline static const DynamicField<T, SizeInc, SizeMult, SizeDiv>& null()
91  {
92  return *reinterpret_cast
93  <
95  >(0);
96  }
97 
98 
99  // Constructors
100 
101  //- Construct null
102  inline DynamicField();
103 
104  //- Construct given size.
105  explicit inline DynamicField(const label);
106 
107  //- Construct from UList. Size set to UList size.
108  // Also constructs from DynamicField with different sizing parameters.
109  explicit inline DynamicField(const UList<T>&);
110 
111  //- Construct by transferring the parameter contents
112  explicit inline DynamicField(const Xfer<List<T> >&);
113 
114  //- Construct by 1 to 1 mapping from the given field
115  inline DynamicField
116  (
117  const UList<T>& mapF,
118  const labelList& mapAddressing
119  );
120 
121  //- Construct by interpolative mapping from the given field
122  inline DynamicField
123  (
124  const UList<T>& mapF,
125  const labelListList& mapAddressing,
126  const scalarListList& weights
127  );
128 
129  //- Construct by mapping from the given field
130  inline DynamicField
131  (
132  const UList<T>& mapF,
133  const FieldMapper& map
134  );
135 
136  //- Construct copy
138 
139  //- Construct by transferring the Field contents
140  inline DynamicField
141  (
143  );
144 
145  //- Construct from Istream. Size set to size of list read.
146  explicit DynamicField(Istream&);
147 
148  //- Clone
150 
151 
152  // Member Functions
153 
154  // Access
155 
156  //- Size of the underlying storage.
157  inline label capacity() const;
158 
159  // Edit
160 
161  //- Alter the size of the underlying storage.
162  // The addressed size will be truncated if needed to fit, but will
163  // remain otherwise untouched.
164  // Use this or reserve() in combination with append().
165  inline void setCapacity(const label);
166 
167  //- Alter the addressed list size.
168  // New space will be allocated if required.
169  // Use this to resize the list prior to using the operator[] for
170  // setting values (as per List usage).
171  inline void setSize(const label);
172 
173  //- Alter the addressed list size and fill new space with a
174  // constant.
175  inline void setSize(const label, const T&);
176 
177  //- Alter the addressed list size.
178  // New space will be allocated if required.
179  // Use this to resize the list prior to using the operator[] for
180  // setting values (as per List usage).
181  inline void resize(const label);
182 
183  //- Alter the addressed list size and fill new space with a
184  // constant.
185  inline void resize(const label, const T&);
186 
187  //- Reserve allocation space for at least this size.
188  // Never shrinks the allocated size, use setCapacity() for that.
189  inline void reserve(const label);
190 
191  //- Clear the addressed list, i.e. set the size to zero.
192  // Allocated size does not change
193  inline void clear();
194 
195  //- Clear the list and delete storage.
196  inline void clearStorage();
197 
198  //- Shrink the allocated space to the number of elements used.
199  // Returns a reference to the DynamicField.
201 
202  //- Transfer contents to the Xfer container as a plain List
203  inline Xfer<List<T> > xfer();
204 
205 
206  // Member Operators
207 
208  //- Append an element at the end of the list
210  (
211  const T&
212  );
213 
214  //- Append a List at the end of this list
216  (
217  const UList<T>&
218  );
219 
220  //- Remove and return the top element
221  inline T remove();
222 
223  //- Return non-const access to an element, resizing list if
224  // necessary
225  inline T& operator()(const label);
226 
227  //- Assignment of all addressed entries to the given value
228  inline void operator=(const T&);
229 
230  //- Assignment from DynamicField
231  inline void operator=
232  (
234  );
235 
236  //- Assignment from UList
237  inline void operator=(const UList<T>&);
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #include "DynamicFieldI.H"
248 
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 
251 #ifdef NoRepository
252 # include "DynamicField.C"
253 #endif
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
reinterpret_cast
const Foam::edgeFaceCirculator Foam::edgeFaceCirculator::endConstIter * reinterpret_cast(0), -1, false, -1, false
Foam::DynamicField::clear
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicFieldI.H:277
Foam::DynamicField::setCapacity
void setCapacity(const label)
Alter the size of the underlying storage.
Definition: DynamicFieldI.H:144
Foam::DynamicField::operator=
void operator=(const T &)
Assignment of all addressed entries to the given value.
Foam::DynamicField::clearStorage
void clearStorage()
Clear the list and delete storage.
Definition: DynamicFieldI.H:284
Foam::DynamicField::resize
void resize(const label)
Alter the addressed list size.
Foam::DynamicField::setSize
void setSize(const label)
Alter the addressed list size.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::DynamicField::capacity_
label capacity_
The capacity (allocated size) of the underlying field.
Definition: DynamicField.H:81
Foam::DynamicField::operator()
T & operator()(const label)
Return non-const access to an element, resizing list if.
Definition: DynamicFieldI.H:380
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:45
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
DynamicField.C
Foam::DynamicField
Dynamically sized Field.
Definition: DynamicField.H:49
Foam::DynamicField::StaticAssert
StaticAssert((SizeInc||SizeMult) &&SizeDiv)
Avoid invalid sizing parameters.
Foam::DynamicField::DynamicField
DynamicField()
Construct null.
Definition: DynamicFieldI.H:29
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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
DynamicFieldI.H
Foam::DynamicField::append
DynamicField< T, SizeInc, SizeMult, SizeDiv > & 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
Field.H
Foam::DynamicField::capacity
label capacity() const
Size of the underlying storage.
Definition: DynamicFieldI.H:135
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynamicField::xfer
Xfer< List< T > > xfer()
Transfer contents to the Xfer container as a plain List.
Definition: DynamicFieldI.H:312
StaticAssert.H
Foam::DynamicField::reserve
void reserve(const label)
Reserve allocation space for at least this size.
Definition: DynamicFieldI.H:165
Foam::DynamicField::remove
T remove()
Remove and return the top element.
Definition: DynamicFieldI.H:358
Foam::DynamicField::clone
tmp< DynamicField< T, SizeInc, SizeMult, SizeDiv > > clone() const
Clone.
Definition: DynamicField.C:40
Foam::List< T >
Foam::UList< T >
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::DynamicField::shrink
DynamicField< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicFieldI.H:293