Loading...
Searching...
No Matches
IOdictionary.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) 2021-2024 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
30#include "objectRegistry.H"
31#include "Pstream.H"
32#include "Time.H"
33
34// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35
37(
38 const IOobject& io,
47(
48 const IOobject& io,
50)
51:
53{}
54
55
57(
58 const IOobject& io,
59 const word& wantedType,
60 const dictionary* fallback
61)
62:
64{
65 if (!readHeaderOk(IOstreamOption::ASCII, wantedType) && fallback)
66 {
68 }
69
70 // For if MUST_READ_IF_MODIFIED
71 addWatch();
72}
73
74
76(
77 const IOobject& io,
78 Istream& is
79)
80:
81 baseIOdictionary(io, is)
82{
83 // Default construct dictionary and read in afterwards
84 // so that if there is some fancy massaging due to a
85 // functionEntry in
86 // the dictionary at least the type information is already complete.
87 is >> *this;
88
89 // For if MUST_READ_IF_MODIFIED
90 addWatch();
91}
92
93
94// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
97{
98 return readContents(io, typeName);
99}
100
101
103(
104 const IOobject& io,
105 const word& wantedType
106)
107{
109 if (rio.readOpt() == IOobjectOption::READ_MODIFIED)
110 {
111 rio.readOpt(IOobjectOption::MUST_READ);
112 }
113
114 // The object is global
115 rio.globalObject(true);
116
117 IOdictionary reader
118 (
119 rio,
120 (wantedType.empty() ? typeName : wantedType)
121 );
122
123 return dictionary(std::move(static_cast<dictionary&>(reader)));
124}
125
126
127// ************************************************************************* //
static dictionary readContents(const IOobject &io)
Read and return contents, testing for "dictionary" type. The IOobject will not be registered.
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Construct given an IOobject and optional fallback dictionary content.
@ NO_REGISTER
Do not request registration (bool: false).
bool globalObject() const noexcept
True if object is treated the same for all processors.
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
@ ASCII
"ascii" (normal default)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
baseIOdictionary(const baseIOdictionary &)=default
Copy construct.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
void operator=(const dictionary &rhs)
Copy assignment.
Definition dictionary.C:886
virtual void addWatch()
Add file watch on object (if registered and READ_IF_MODIFIED).
bool readHeaderOk(const IOstreamOption::streamFormat fmt, const word &typeName)
Helper: check readOpt flags and read if necessary.
A class for handling words, derived from Foam::string.
Definition word.H:66
const auto & io
const auto & fallback
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
dictionary dict