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>
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>
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  {
89  << "NO_READ must be set if specifying size" << nl
90  << exit(FatalError);
91  }
92 }
93 
94 
95 template<class T>
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>
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>
151 {
152  return (os << *this).good();
153 }
154 
155 
156 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
157 
158 template<class T>
160 {
162 }
163 
164 
165 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOPtrList::operator=
void operator=(const IOPtrList< T > &rhs)
Copy assignment of entries.
Definition: IOPtrList.C:159
Foam::IOPtrList
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:53
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:51
IOPtrList.H
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::IOPtrList::writeData
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOPtrList.C:150
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOPtrList::IOPtrList
IOPtrList(const IOPtrList &)=default
Default copy construct.