FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/Field.H>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 // Forward declaration of friend functions and operators
47 
48 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
49 class DynamicField;
50 
51 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
52 Ostream& operator<<
53 (
54  Ostream&,
55  const DynamicField<T, SizeInc, SizeMult, SizeDiv>&
56 );
57 template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
58 Istream& operator>>
59 (
60  Istream&,
61  DynamicField<T, SizeInc, SizeMult, SizeDiv>&
62 );
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class DynamicField Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 template<class T, unsigned SizeInc=0, unsigned SizeMult=2, unsigned SizeDiv=1>
71 :
72  public Field<T>
73 {
74  // Private data
75 
76  //- The capacity (allocated size) of the underlying field.
77  label capacity_;
78 
79 
80 public:
81 
82  // Static Member Functions
83 
84  //- Return a null field
86  {
87  return *reinterpret_cast
88  <
90  >(0);
91  }
92 
93 
94  // Constructors
95 
96  //- Construct null
97  inline DynamicField();
98 
99  //- Construct given size.
100  explicit inline DynamicField(const label);
101 
102  //- Construct from UList. Size set to UList size.
103  // Also constructs from DynamicField with different sizing parameters.
104  explicit inline DynamicField(const UList<T>&);
105 
106  //- Construct by transferring the parameter contents
107  explicit inline DynamicField(const Xfer<List<T> >&);
108 
109  //- Construct by 1 to 1 mapping from the given field
110  inline DynamicField
111  (
112  const UList<T>& mapF,
113  const labelList& mapAddressing
114  );
115 
116  //- Construct by interpolative mapping from the given field
117  inline DynamicField
118  (
119  const UList<T>& mapF,
120  const labelListList& mapAddressing,
121  const scalarListList& weights
122  );
123 
124  //- Construct by mapping from the given field
125  inline DynamicField
126  (
127  const UList<T>& mapF,
128  const FieldMapper& map
129  );
130 
131  //- Construct copy
133 
134  //- Construct by transferring the Field contents
135  inline DynamicField
136  (
138  );
139 
140  //- Construct from Istream. Size set to size of list read.
141  explicit DynamicField(Istream&);
142 
143  //- Clone
145 
146 
147  // Member Functions
148 
149  // Access
150 
151  //- Size of the underlying storage.
152  inline label capacity() const;
153 
154  // Edit
155 
156  //- Alter the size of the underlying storage.
157  // The addressed size will be truncated if needed to fit, but will
158  // remain otherwise untouched.
159  // Use this or reserve() in combination with append().
160  inline void setCapacity(const label);
161 
162  //- Alter the addressed list size.
163  // New space will be allocated if required.
164  // Use this to resize the list prior to using the operator[] for
165  // setting values (as per List usage).
166  inline void setSize(const label);
167 
168  //- Alter the addressed list size and fill new space with a
169  // constant.
170  inline void setSize(const label, const T&);
171 
172  //- Alter the addressed list size.
173  // New space will be allocated if required.
174  // Use this to resize the list prior to using the operator[] for
175  // setting values (as per List usage).
176  inline void resize(const label);
177 
178  //- Alter the addressed list size and fill new space with a
179  // constant.
180  inline void resize(const label, const T&);
181 
182  //- Reserve allocation space for at least this size.
183  // Never shrinks the allocated size, use setCapacity() for that.
184  inline void reserve(const label);
185 
186  //- Clear the addressed list, i.e. set the size to zero.
187  // Allocated size does not change
188  inline void clear();
189 
190  //- Clear the list and delete storage.
191  inline void clearStorage();
192 
193  //- Shrink the allocated space to the number of elements used.
194  // Returns a reference to the DynamicField.
196 
197  //- Transfer contents to the Xfer container as a plain List
198  inline Xfer<List<T> > xfer();
199 
200 
201  // Member Operators
202 
203  //- Append an element at the end of the list
205  (
206  const T&
207  );
208 
209  //- Append a List at the end of this list
211  (
212  const UList<T>&
213  );
214 
215  //- Remove and return the top element
216  inline T remove();
217 
218  //- Return non-const access to an element, resizing list if
219  // necessary
220  inline T& operator()(const label);
221 
222  //- Assignment of all addressed entries to the given value
223  inline void operator=(const T&);
224 
225  //- Assignment from DynamicField
226  inline void operator=
227  (
229  );
230 
231  //- Assignment from UList
232  inline void operator=(const UList<T>&);
233 
234 
235  // IOstream operators
236 
237  // Write DynamicField to Ostream.
238  friend Ostream& operator<< <T, SizeInc, SizeMult, SizeDiv>
239  (
240  Ostream&,
242  );
243 
244  //- Read from Istream, discarding contents of existing DynamicField.
245  friend Istream& operator>> <T, SizeInc, SizeMult, SizeDiv>
246  (
247  Istream&,
249  );
250 };
251 
252 
253 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 
255 } // End namespace Foam
256 
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
258 
259 #include "DynamicFieldI.H"
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #ifdef NoRepository
264 # include "DynamicField.C"
265 #endif
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************ vim: set sw=4 sts=4 et: ************************ //