IOField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "IOField.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 :
36  regIOobject(io)
37 {
38  // Check for MUST_READ_IF_MODIFIED
39  warnNoRereading<IOField<Type>>();
40 
41  if
42  (
43  (
46  )
47  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
48  )
49  {
50  readStream(typeName) >> *this;
51  close();
52  }
53 }
54 
55 
56 template<class Type>
57 Foam::IOField<Type>::IOField(const IOobject& io, const bool valid)
58 :
59  regIOobject(io)
60 {
61  // Check for MUST_READ_IF_MODIFIED
62  warnNoRereading<IOField<Type>>();
63 
64  if
65  (
68  )
69  {
70  Istream& is = readStream(typeName, valid);
71 
72  if (valid)
73  {
74  is >> *this;
75  }
76  close();
77  }
78  else if (io.readOpt() == IOobject::READ_IF_PRESENT)
79  {
80  bool haveFile = headerOk();
81 
82  Istream& is = readStream(typeName, haveFile && valid);
83 
84  if (valid && haveFile)
85  {
86  is >> *this;
87  }
88  close();
89  }
90 }
91 
92 
93 template<class Type>
94 Foam::IOField<Type>::IOField(const IOobject& io, const label size)
95 :
96  regIOobject(io)
97 {
98  // Check for MUST_READ_IF_MODIFIED
99  warnNoRereading<IOField<Type>>();
100 
101  if
102  (
103  (
106  )
107  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
108  )
109  {
110  readStream(typeName) >> *this;
111  close();
112  }
113  else
114  {
115  Field<Type>::setSize(size);
116  }
117 }
118 
119 
120 template<class Type>
122 :
123  regIOobject(io)
124 {
125  // Check for MUST_READ_IF_MODIFIED
126  warnNoRereading<IOField<Type>>();
127 
128  if
129  (
130  (
133  )
134  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
135  )
136  {
137  readStream(typeName) >> *this;
138  close();
139  }
140  else
141  {
142  Field<Type>::operator=(content);
143  }
144 }
145 
146 
147 template<class Type>
149 :
150  regIOobject(io)
151 {
152  // Check for MUST_READ_IF_MODIFIED
153  warnNoRereading<IOField<Type>>();
154 
155  Field<Type>::transfer(content);
156 
157  if
158  (
159  (
162  )
163  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
164  )
165  {
166  readStream(typeName) >> *this;
167  close();
168  }
169 }
170 
171 
172 template<class Type>
174 :
175  regIOobject(io)
176 {
177  const bool reuse = tfld.movable();
178 
179  if (reuse)
180  {
181  Field<Type>::transfer(tfld.ref());
182  }
183 
184  if
185  (
186  (
189  )
190  || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
191  )
192  {
193  readStream(typeName) >> *this;
194  close();
195  }
196  else if (!reuse)
197  {
198  Field<Type>::operator=(tfld());
199  }
200 
201  tfld.clear();
202 }
203 
204 
205 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
206 
207 template<class Type>
209 {
210  return (os << static_cast<const Field<Type>&>(*this)).good();
211 }
212 
213 
214 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
215 
216 template<class Type>
218 {
220 }
221 
222 
223 // ************************************************************************* //
setSize
points setSize(newPointi)
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOField::IOField
IOField(const IOField &)=default
Default copy construct.
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::IOobject::READ_IF_PRESENT
Definition: IOobject.H:187
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Field::operator=
void operator=(const Field< Type > &)
Copy assignment.
Definition: Field.C:635
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
IOField.H
Foam::UList< Type >
Foam::IOField::writeData
bool writeData(Ostream &os) const
Definition: IOField.C:208
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOField::operator=
void operator=(const IOField< Type > &rhs)
Copy assignment of entries.
Definition: IOField.C:217
Foam::IOobject::MUST_READ
Definition: IOobject.H:185