IOField.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-2019 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 "IOField.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  regIOobject(io)
34 {
35  // Check for MUST_READ_IF_MODIFIED
36  warnNoRereading<IOField<Type>>();
37 
38  if
39  (
40  (
43  )
45  )
46  {
47  readStream(typeName) >> *this;
48  close();
49  }
50 }
51 
52 
53 template<class Type>
55 :
56  regIOobject(io)
57 {
58  // Check for MUST_READ_IF_MODIFIED
59  warnNoRereading<IOField<Type>>();
60 
61  if
62  (
65  )
66  {
67  Istream& is = readStream(typeName, read);
68 
69  if (read)
70  {
71  is >> *this;
72  }
73  close();
74  }
75  else if (io.readOpt() == IOobject::READ_IF_PRESENT)
76  {
77  bool haveFile = headerOk();
78 
79  Istream& is = readStream(typeName, haveFile && read);
80 
81  if (read && haveFile)
82  {
83  is >> *this;
84  }
85  close();
86  }
87 }
88 
89 
90 template<class Type>
92 :
93  regIOobject(io)
94 {
95  // Check for MUST_READ_IF_MODIFIED
96  warnNoRereading<IOField<Type>>();
97 
98  if
99  (
100  (
103  )
104  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
105  )
106  {
107  readStream(typeName) >> *this;
108  close();
109  }
110  else
111  {
112  Field<Type>::setSize(size);
113  }
114 }
115 
116 
117 template<class Type>
119 :
120  regIOobject(io),
121  Field<Type>(f)
122 {
123  // Check for MUST_READ_IF_MODIFIED
124  warnNoRereading<IOField<Type>>();
125 
126  if
127  (
128  (
131  )
132  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
133  )
134  {
135  readStream(typeName) >> *this;
136  close();
137  }
138 }
139 
140 
141 template<class Type>
143 :
144  regIOobject(io),
145  Field<Type>(move(f))
146 {
147  // Check for MUST_READ_IF_MODIFIED
148  warnNoRereading<IOField<Type>>();
149 
150  if
151  (
152  (
155  )
156  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
157  )
158  {
159  readStream(typeName) >> *this;
160  close();
161  }
162 }
163 
164 
165 template<class Type>
167 :
168  regIOobject(io),
169  Field<Type>(f)
170 {
171  // Check for MUST_READ_IF_MODIFIED
172  warnNoRereading<IOField<Type>>();
173 
174  if
175  (
176  (
179  )
180  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
181  )
182  {
183  readStream(typeName) >> *this;
184  close();
185  }
186 }
187 
188 
189 template<class Type>
191 :
192  regIOobject(move(f)),
193  Field<Type>(move(f))
194 {}
195 
196 
197 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
198 
199 template<class Type>
201 {}
202 
203 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
204 
205 template<class Type>
207 {
208  return (os << static_cast<const Field<Type>&>(*this)).good();
209 }
210 
211 
212 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
213 
214 template<class Type>
216 {
218 }
219 
220 
221 template<class Type>
223 {
224  Field<Type>::operator=(move(rhs));
225 }
226 
227 
228 template<class Type>
230 {
232 }
233 
234 
235 template<class Type>
237 {
238  Field<Type>::operator=(move(rhs));
239 }
240 
241 
242 template<class Type>
244 {
246 }
247 
248 
249 // ************************************************************************* //
IOField(const IOobject &)
Construct from IOobject.
Definition: IOField.C:31
bool writeData(Ostream &) const
Pure virtual writaData function.
Definition: IOField.C:206
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
virtual bool read()
Read object.
static const char *const typeName
Definition: Field.H:105
void operator=(const IOField< Type > &)
Definition: IOField.C:215
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
bool headerOk()
Read and check header info.
Definition: regIOobject.C:397
Pre-declare SubField and related Field type.
Definition: Field.H:56
void close()
Close Istream.
Istream & readStream(const word &, const bool read=true)
Return Istream and check object type against that given.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void operator=(const Field< Type > &)
Definition: Field.C:512
labelList f(nPoints)
void setSize(const label)
Reset size of List.
Definition: List.C:281
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
readOption readOpt() const
Definition: IOobject.H:353
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual ~IOField()
Destructor.
Definition: IOField.C:200
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50