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-2022 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 :
38 {
39  if (isReadRequired() || (isReadOptional() && headerOk()))
40  {
41  // For if MUST_READ_IF_MODIFIED
42  addWatch();
43 
44  PtrList<T>::readIstream(readStream(typeName), inewt);
45  close();
46  }
47 }
48 
49 
50 template<class T>
51 Foam::IOPtrList<T>::IOPtrList(const IOobject& io)
52 :
53  regIOobject(io)
54 {
55  if (isReadRequired() || (isReadOptional() && headerOk()))
56  {
57  // For if MUST_READ_IF_MODIFIED
58  addWatch();
59 
60  PtrList<T>::readIstream(readStream(typeName), INew<T>());
61  close();
62  }
63 }
64 
65 
66 template<class T>
67 Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const label len)
68 :
69  regIOobject(io),
70  PtrList<T>(len)
71 {
72  if (io.readOpt() != IOobject::NO_READ)
73  {
75  << "NO_READ must be set if specifying size" << nl
76  << exit(FatalError);
77  }
78 }
79 
80 
81 template<class T>
82 Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const PtrList<T>& content)
83 :
84  regIOobject(io)
85 {
86  if (isReadRequired() || (isReadOptional() && headerOk()))
87  {
88  // For if MUST_READ_IF_MODIFIED
89  addWatch();
90 
91  PtrList<T>::readIstream(readStream(typeName), INew<T>());
92  close();
93  }
94  else
95  {
96  PtrList<T>::operator=(content);
97  }
98 }
99 
100 
101 template<class T>
102 Foam::IOPtrList<T>::IOPtrList(const IOobject& io, PtrList<T>&& content)
103 :
104  regIOobject(io)
105 {
106  PtrList<T>::transfer(content);
107 
108  if (isReadRequired() || (isReadOptional() && headerOk()))
109  {
110  // For if MUST_READ_IF_MODIFIED
111  addWatch();
112 
113  PtrList<T>::readIstream(readStream(typeName), INew<T>());
114  close();
115  }
116 }
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
121 template<class T>
122 bool Foam::IOPtrList<T>::writeData(Ostream& os) const
123 {
124  return (os << *this).good();
125 }
126 
127 
128 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
129 
130 template<class T>
132 {
134 }
135 
136 
137 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
void operator=(const IOPtrList< T > &rhs)
Copy assignment of entries.
Definition: IOPtrList.C:124
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
OBJstream os(runTime.globalPath()/outputName)
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition: IOPtrList.C:115
const volScalarField & T
A PtrList of objects of type <T> with automated input and output.
Definition: IOPtrList.H:49
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:46
IOPtrList(const IOPtrList &)=default
Default copy construct.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:69
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166