All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IOList.C
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-2022 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 \*---------------------------------------------------------------------------*/
25 
26 #include "IOList.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template
31 <
32  template<class> class Container,
33  template<class> class IOContainer,
34  class Type
35 >
37 :
38  regIOobject(io)
39 {
40  // Check for MUST_READ_IF_MODIFIED
41  if (!IOContainer<Type>::rereading)
42  {
43  warnNoRereading<IOContainer<Type>>();
44  }
45 
46  if
47  (
48  (
51  )
53  )
54  {
55  // For if MUST_READ_IF_MODIFIED
56  if (IOContainer<Type>::rereading)
57  {
58  addWatch();
59  }
60 
61  readStream(IOContainer<Type>::typeName) >> *this;
62  close();
63  }
64 }
65 
66 
67 template
68 <
69  template<class> class Container,
70  template<class> class IOContainer,
71  class Type
72 >
74 (
75  const IOobject& io,
76  const bool read
77 )
78 :
79  regIOobject(io)
80 {
81  // Check for MUST_READ_IF_MODIFIED
82  if (!IOContainer<Type>::rereading)
83  {
84  warnNoRereading<IOContainer<Type>>();
85  }
86 
87  if
88  (
91  )
92  {
93  // For if MUST_READ_IF_MODIFIED
94  if (IOContainer<Type>::rereading)
95  {
96  addWatch();
97  }
98 
99  Istream& is = readStream(IOContainer<Type>::typeName, read);
100 
101  if (read)
102  {
103  is >> *this;
104  }
105 
106  close();
107  }
108  else if (io.readOpt() == IOobject::READ_IF_PRESENT)
109  {
110  bool haveFile = headerOk();
111 
112  Istream& is = readStream(IOContainer<Type>::typeName, haveFile && read);
113 
114  if (read && haveFile)
115  {
116  is >> *this;
117  }
118 
119  close();
120  }
121 }
122 
123 
124 template
125 <
126  template<class> class Container,
127  template<class> class IOContainer,
128  class Type
129 >
131 (
132  const IOobject& io,
133  const label size
134 )
135 :
136  regIOobject(io)
137 {
138  // Check for MUST_READ_IF_MODIFIED
139  if (!IOContainer<Type>::rereading)
140  {
141  warnNoRereading<IOContainer<Type>>();
142  }
143 
144  if
145  (
146  (
149  )
150  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
151  )
152  {
153  // For if MUST_READ_IF_MODIFIED
154  if (IOContainer<Type>::rereading)
155  {
156  addWatch();
157  }
158 
159  readStream(IOContainer<Type>::typeName) >> *this;
160  close();
161  }
162  else
163  {
165  }
166 }
167 
168 
169 template
170 <
171  template<class> class Container,
172  template<class> class IOContainer,
173  class Type
174 >
176 (
177  const IOobject& io,
178  const Container<Type>& l
179 )
180 :
181  regIOobject(io)
182 {
183  // Check for MUST_READ_IF_MODIFIED
184  if (!IOContainer<Type>::rereading)
185  {
186  warnNoRereading<IOContainer<Type>>();
187  }
188 
189  if
190  (
191  (
194  )
195  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
196  )
197  {
198  // For if MUST_READ_IF_MODIFIED
199  if (IOContainer<Type>::rereading)
200  {
201  addWatch();
202  }
203 
204  readStream(IOContainer<Type>::typeName) >> *this;
205  close();
206  }
207  else
208  {
209  Container<Type>::operator=(l);
210  }
211 }
212 
213 
214 template
215 <
216  template<class> class Container,
217  template<class> class IOContainer,
218  class Type
219 >
221 (
222  const IOobject& io,
223  Container<Type>&& l
224 )
225 :
226  regIOobject(io),
227  Container<Type>(move(l))
228 {
229  // Check for MUST_READ_IF_MODIFIED
230  if (!IOContainer<Type>::rereading)
231  {
232  warnNoRereading<IOContainer<Type>>();
233  }
234 
235  if
236  (
237  (
240  )
241  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
242  )
243  {
244  // For if MUST_READ_IF_MODIFIED
245  if (IOContainer<Type>::rereading)
246  {
247  addWatch();
248  }
249 
250  readStream(IOContainer<Type>::typeName) >> *this;
251  close();
252  }
253 }
254 
255 
256 template
257 <
258  template<class> class Container,
259  template<class> class IOContainer,
260  class Type
261 >
263 (
265 )
266 :
267  regIOobject(f),
268  Container<Type>(f)
269 {}
270 
271 
272 template
273 <
274  template<class> class Container,
275  template<class> class IOContainer,
276  class Type
277 >
279 (
281 )
282 :
283  regIOobject(move(f)),
284  Container<Type>(move(f))
285 {}
286 
287 
288 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
289 
290 template
291 <
292  template<class> class Container,
293  template<class> class IOContainer,
294  class Type
295 >
297 {}
298 
299 
300 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
301 
302 template
303 <
304  template<class> class Container,
305  template<class> class IOContainer,
306  class Type
307 >
309 (
310  Ostream& os
311 ) const
312 {
313  return (os << static_cast<const Container<Type>&>(*this)).good();
314 }
315 
316 
317 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
318 
319 template
320 <
321  template<class> class Container,
322  template<class> class IOContainer,
323  class Type
324 >
326 (
328 )
329 {
330  Container<Type>::operator=(rhs);
331 }
332 
333 
334 template
335 <
336  template<class> class Container,
337  template<class> class IOContainer,
338  class Type
339 >
341 (
343 )
344 {
345  Container<Type>::operator=(move(rhs));
346 }
347 
348 
349 // ************************************************************************* //
virtual bool writeData(Ostream &) const
WriteData function required for regIOobject write operation.
Definition: IOList.C:309
IOListBase(const IOobject &)
Construct from IOobject.
Definition: IOList.C:36
virtual ~IOListBase()
Destructor.
Definition: IOList.C:296
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:119
readOption readOpt() const
Definition: IOobject.H:360
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
void close()
Close Istream.
bool headerOk()
Read and check header info.
Definition: regIOobject.C:453
Istream & readStream(const word &, const bool read=true)
Return Istream and check object type against that given.
void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:259
bool read(const char *, int32_t &)
Definition: int32IO.C: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
points setSize(newPointi)
labelList f(nPoints)