OpenFOAM: API Guide
v2112
The open source CFD toolbox
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
-------------------------------------------------------------------------------
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 "
IOPtrList.H
"
30
31
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32
33
template
<
class
T>
34
template
<
class
INew>
35
Foam::IOPtrList<T>::IOPtrList
(
const
IOobject
&
io
,
const
INew
& inewt)
36
:
37
regIOobject
(
io
)
38
{
39
if
40
(
41
(
42
io
.
readOpt
() ==
IOobject::MUST_READ
43
||
io
.
readOpt
() ==
IOobject::MUST_READ_IF_MODIFIED
44
)
45
|| (
io
.
readOpt
() ==
IOobject::READ_IF_PRESENT
&&
headerOk
())
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
57
template
<
class
T>
58
Foam::IOPtrList<T>::IOPtrList
(
const
IOobject
&
io
)
59
:
60
regIOobject
(
io
)
61
{
62
if
63
(
64
(
65
io
.
readOpt
() ==
IOobject::MUST_READ
66
||
io
.
readOpt
() ==
IOobject::MUST_READ_IF_MODIFIED
67
)
68
|| (
io
.
readOpt
() ==
IOobject::READ_IF_PRESENT
&&
headerOk
())
69
)
70
{
71
// For if MUST_READ_IF_MODIFIED
72
addWatch
();
73
74
PtrList<T>::readIstream
(
readStream
(typeName),
INew<T>
());
75
close
();
76
}
77
}
78
79
80
template
<
class
T>
81
Foam::IOPtrList<T>::IOPtrList
(
const
IOobject
&
io
,
const
label len)
82
:
83
regIOobject
(
io
),
84
PtrList
<
T
>(len)
85
{
86
if
(
io
.
readOpt
() !=
IOobject::NO_READ
)
87
{
88
FatalErrorInFunction
89
<<
"NO_READ must be set if specifying size"
<<
nl
90
<<
exit
(
FatalError
);
91
}
92
}
93
94
95
template
<
class
T>
96
Foam::IOPtrList<T>::IOPtrList
(
const
IOobject
&
io
,
const
PtrList<T>
& content)
97
:
98
regIOobject
(
io
)
99
{
100
if
101
(
102
(
103
io
.
readOpt
() ==
IOobject::MUST_READ
104
||
io
.
readOpt
() ==
IOobject::MUST_READ_IF_MODIFIED
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
122
template
<
class
T>
123
Foam::IOPtrList<T>::IOPtrList
(
const
IOobject
&
io
,
PtrList<T>
&& content)
124
:
125
regIOobject
(
io
)
126
{
127
PtrList<T>::transfer
(content);
128
129
if
130
(
131
(
132
io
.
readOpt
() ==
IOobject::MUST_READ
133
||
io
.
readOpt
() ==
IOobject::MUST_READ_IF_MODIFIED
134
)
135
|| (
io
.
readOpt
() ==
IOobject::READ_IF_PRESENT
&&
headerOk
())
136
)
137
{
138
// For if MUST_READ_IF_MODIFIED
139
addWatch
();
140
141
PtrList<T>::readIstream
(
readStream
(typeName),
INew<T>
());
142
close
();
143
}
144
}
145
146
147
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
148
149
template
<
class
T>
150
bool
Foam::IOPtrList<T>::writeData
(
Ostream
&
os
)
const
151
{
152
return
(
os
<< *
this
).
good
();
153
}
154
155
156
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
157
158
template
<
class
T>
159
void
Foam::IOPtrList<T>::operator=
(
const
IOPtrList<T>
& rhs)
160
{
161
PtrList<T>::operator=
(rhs);
162
}
163
164
165
// ************************************************************************* //
IOPtrList.H
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition:
INew.H:52
Foam::IOPtrList
A PtrList of objects of type <T> with automated input and output.
Definition:
IOPtrList.H:57
Foam::IOPtrList::operator=
void operator=(const IOPtrList< T > &rhs)
Copy assignment of entries.
Definition:
IOPtrList.C:159
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition:
IOobject.H:170
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition:
IOobjectI.H:164
Foam::IOobject::good
bool good() const noexcept
Did last readHeader() succeed?
Definition:
IOobjectI.H:222
Foam::IOobject::NO_READ
@ NO_READ
Definition:
IOobject.H:178
Foam::IOobject::MUST_READ_IF_MODIFIED
@ MUST_READ_IF_MODIFIED
Definition:
IOobject.H:180
Foam::IOobject::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition:
IOobject.H:181
Foam::IOobject::MUST_READ
@ MUST_READ
Definition:
IOobject.H:179
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition:
Ostream.H:62
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition:
PtrList.H:73
Foam::PtrList::readIstream
void readIstream(Istream &is, const INew &inew)
Read from Istream using Istream constructor class.
Definition:
PtrListIO.C:38
Foam::PtrList::operator=
void operator=(const PtrList< T > &list)
Copy assignment.
Definition:
PtrList.C:133
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition:
regIOobject.H:76
Foam::regIOobject::close
void close()
Close Istream.
Definition:
regIOobjectRead.C:173
Foam::regIOobject::readStream
Istream & readStream(const word &, const bool valid=true)
Return Istream and check object type against that given.
Definition:
regIOobjectRead.C:131
Foam::regIOobject::headerOk
bool headerOk()
Read and check header info. Does not check the headerClassName.
Definition:
regIOobject.C:438
Foam::regIOobject::addWatch
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED)
Definition:
regIOobject.C:267
Foam::regionModels::surfaceFilmModels::kinematicSingleLayer::transfer
transferModelList & transfer()
Transfer.
Definition:
kinematicSingleLayerI.H:188
T
const volScalarField & T
Definition:
createFieldRefs.H:2
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition:
error.H:453
os
OBJstream os(runTime.globalPath()/outputName)
io
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Foam::FatalError
error FatalError
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition:
errorManip.H:130
Foam::nl
constexpr char nl
The newline '\n' character (0x0a)
Definition:
Ostream.H:53
src
OpenFOAM
db
IOobjects
IOPtrList
IOPtrList.C
Generated by
1.9.5
OPENFOAM® is a registered
trademark
of OpenCFD Ltd.