Loading...
Searching...
No Matches
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-2023 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\*---------------------------------------------------------------------------*/
29#include "IOPtrList.H"
30
31// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32
33template<class T>
34template<class INew>
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
50template<class T>
51Foam::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
61 close();
62 }
63}
64
65
66template<class T>
67Foam::IOPtrList<T>::IOPtrList(const IOobject& io, const label len)
68:
69 regIOobject(io),
70 PtrList<T>(len)
71{
72 if (io.isAnyRead())
73 {
74 FatalErrorInFunction
75 << "NO_READ must be set if specifying size" << nl
76 << exit(FatalError);
77 }
78}
79
80
81template<class T>
83:
85{
86 if (isReadRequired() || (isReadOptional() && headerOk()))
87 {
88 // For if MUST_READ_IF_MODIFIED
89 addWatch();
90
92 close();
93 }
94 else
95 {
96 PtrList<T>::operator=(content);
97 }
98}
99
100
101template<class T>
103:
105{
106 PtrList<T>::transfer(content);
107
108 if (isReadRequired() || (isReadOptional() && headerOk()))
109 {
110 // For if MUST_READ_IF_MODIFIED
111 addWatch();
114 close();
116}
117
118
119// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
120
121template<class T>
123{
124 IOobject rio(io, IOobjectOption::NO_REGISTER);
125 if (rio.readOpt() == IOobjectOption::READ_MODIFIED)
126 {
127 rio.readOpt(IOobjectOption::MUST_READ);
128 }
129 rio.resetHeader();
130
131 IOPtrList<T> reader(rio);
132
133 return PtrList<T>(std::move(static_cast<PtrList<T>&>(reader)));
134}
135
136
137// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138
139template<class T>
141{
142 return (os << *this).good();
143}
144
145
146// ************************************************************************* //
A helper class when constructing from an Istream or dictionary.
Definition INew.H:47
A PtrList of objects of type <T> with automated input and output.
Definition IOPtrList.H:53
bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition IOPtrList.C:133
IOPtrList(const IOPtrList &)=default
Default copy construct.
static PtrList< T > readContents(const IOobject &io)
Read and return contents. The IOobject will not be registered.
Definition IOPtrList.C:115
@ NO_REGISTER
Do not request registration (bool: false).
bool isReadOptional() const noexcept
True if (LAZY_READ) bits are set [same as READ_IF_PRESENT].
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
readOption readOpt() const noexcept
Get the read option.
@ MUST_READ
Reading required.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
void resetHeader(const word &newName=word::null)
Clear various bits (headerClassName, note, sizeof...) that would be obtained when reading from a file...
Definition IOobject.C:644
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
void transfer(PtrList< T > &list)
Transfer into this list and annul the argument list.
Definition PtrListI.H:289
void operator=(const UPtrList< T > &list)
Copy assignment.
Definition PtrListI.H:304
void readIstream(Istream &is, const INew &inew)
Read from Istream using Istream constructor class.
Definition PtrListIO.C:30
constexpr PtrList() noexcept
Default construct.
Definition PtrListI.H:29
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition regIOobject.H:71
void close()
Close Istream.
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
bool headerOk()
Read and check header info. Does not check the headerClassName.
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED).
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
const auto & io
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)