baseIOdictionary.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-2014 OpenFOAM Foundation
9  Copyright (C) 2021 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 "baseIOdictionary.H"
30 #include "objectRegistry.H"
31 #include "Pstream.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(baseIOdictionary, 0);
39 
40  bool baseIOdictionary::writeDictionaries
41  (
42  debug::infoSwitch("writeDictionaries", 0)
43  );
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 (
51  const IOobject& io,
52  const dictionary* fallback
53 )
54 :
55  regIOobject(io)
56 {
57  dictionary::name() = IOobject::objectPath();
58 }
59 
60 
62 (
63  const IOobject& io,
64  const dictionary& dict
65 )
66 :
68 {}
69 
70 
72 (
73  const IOobject& io,
74  Istream& is
75 )
76 :
77  regIOobject(io)
78 {
79  dictionary::name() = IOobject::objectPath();
80 }
81 
82 
83 // * * * * * * * * * * * * * * * Members Functions * * * * * * * * * * * * * //
84 
86 {
87  return regIOobject::name();
88 }
89 
90 
92 {
93  is >> *this;
94 
95  if (writeDictionaries && Pstream::master() && !is.bad())
96  {
97  Sout<< nl
98  << "--- baseIOdictionary " << name()
99  << ' ' << objectPath() << ":" << nl;
100  writeHeader(Sout);
101  writeData(Sout);
102  Sout<< "--- End of baseIOdictionary " << name() << nl << endl;
103  }
104 
105  return !is.bad();
106 }
107 
108 
110 {
111  dictionary::write(os, false);
112  return os.good();
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
117 
119 {
121 }
122 
123 
124 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::baseIOdictionary::readData
virtual bool readData(Istream &)
The readData function required by regIOobject read operation.
Definition: baseIOdictionary.C:91
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::baseIOdictionary::writeData
virtual bool writeData(Ostream &) const
The writeData function required by regIOobject write operation.
Definition: baseIOdictionary.C:109
Foam::baseIOdictionary::operator=
void operator=(const baseIOdictionary &rhs)
Copy assignment of dictionary entries (leave regIOobject untouched)
Definition: baseIOdictionary.C:118
Foam::baseIOdictionary::baseIOdictionary
baseIOdictionary(const baseIOdictionary &)=default
Copy construct.
objectRegistry.H
Foam::UPstream::master
static bool master(const label communicator=worldComm)
Am I the master process.
Definition: UPstream.H:457
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::writeHeader
static void writeHeader(Ostream &os, const word &fieldName)
Definition: rawSurfaceWriterImpl.C:66
baseIOdictionary.H
Foam::baseIOdictionary::name
const word & name() const
Definition: baseIOdictionary.C:85
Foam::IOstream::good
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
Foam::debug::infoSwitch
int infoSwitch(const char *name, const int deflt=0)
Lookup info switch or add default value.
Definition: debug.C:231
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::baseIOdictionary
baseIOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO function...
Definition: baseIOdictionary.H:56
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::writeData
static void writeData(Ostream &os, const Type &val)
Definition: rawSurfaceWriterImpl.C:45
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Pstream.H
Foam::IOstream::bad
bool bad() const noexcept
True if stream is corrupted.
Definition: IOstream.H:251
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Time.H
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::dictionary::write
void write(Ostream &os, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:206
Foam::dictionary::operator=
void operator=(const dictionary &rhs)
Copy assignment.
Definition: dictionary.C:881
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Sout
OSstream Sout
OSstream wrapped stdout (std::cout)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)