IOPtrList.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) 2018 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "IOPtrList.H"
30
31// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32
33template<class T>
34template<class INew>
36:
38{
39 if
40 (
41 (
44 )
46 )
47 {
48 // For if MUST_READ_IF_MODIFIED
49 addWatch();
50
51 PtrList<T>::readIstream(readStream(typeName), inewt);
52 close();
53 }
54}
55
56
57template<class T>
59:
61{
62 if
63 (
64 (
67 )
69 )
70 {
71 // For if MUST_READ_IF_MODIFIED
72 addWatch();
73
75 close();
76 }
78
79
80template<class T>
82:
84 PtrList<T>(len)
85{
87 {
89 << "NO_READ must be set if specifying size" << nl
90 << exit(FatalError);
91 }
93
94
95template<class T>
97:
99{
100 if
101 (
102 (
105 )
106 || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
107 )
108 {
109 // For if MUST_READ_IF_MODIFIED
110 addWatch();
111
112 PtrList<T>::readIstream(readStream(typeName), INew<T>());
113 close();
114 }
115 else
116 {
117 PtrList<T>::operator=(content);
118 }
119}
120
121
122template<class T>
124:
126{
127 PtrList<T>::transfer(content);
128
129 if
130 (
131 (
134 )
136 )
137 {
138 // For if MUST_READ_IF_MODIFIED
139 addWatch();
140
142 close();
143 }
144}
145
146
147// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148
149template<class T>
151{
152 return (os << *this).good();
153}
154
155
156// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
157
158template<class T>
160{
162}
163
164
165// ************************************************************************* //
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:52
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:57
void operator=(const IOPtrList< T > &rhs)
Copy assignment of entries.
Definition: IOPtrList.C:159
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
bool good() const noexcept
Did last readHeader() succeed?
Definition: IOobjectI.H:222
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:180
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
void readIstream(Istream &is, const INew &inew)
Read from Istream using Istream constructor class.
Definition: PtrListIO.C:38
void operator=(const PtrList< T > &list)
Copy assignment.
Definition: PtrList.C:133
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
void close()
Close Istream.
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition: regIOobject.C:438
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition: regIOobject.C:267
const volScalarField & T
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53