IOobjectWriteHeader.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Writes the header description of the File to the stream
26  associated with the File.
27 
28 \*---------------------------------------------------------------------------*/
29 
30 #include "IOobject.H"
31 #include "objectRegistry.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
36 {
37  if (!os.good())
38  {
40  << "No stream open for write" << nl
41  << os.info() << endl;
42 
43  return false;
44  }
45 
46  writeBanner(os) << foamFile << "\n{\n";
47 
49  {
50  os << " version " << os.version() << ";\n";
51  }
52 
53  os << " format " << os.format() << ";\n"
54  << " class " << type << ";\n";
55 
56  if (note().size())
57  {
58  os << " note " << note() << ";\n";
59  }
60 
61  os << " location " << instance()/db().dbDir()/local() << ";\n"
62  << " object " << name() << ";\n"
63  << "}" << nl;
64 
65  writeDivider(os) << nl;
66 
67  return true;
68 }
69 
70 
72 {
73  return writeHeader(os, type());
74 }
75 
76 
77 // ************************************************************************* //
const word & name() const
Return name.
Definition: IOobject.H:303
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
Definition: IOobjectI.H:65
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:113
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:321
A class for handling words, derived from string.
Definition: word.H:59
const fileName & local() const
Definition: IOobject.H:400
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
static constexpr const char * foamFile
Keyword for the FoamFile header sub-dictionary.
Definition: IOobject.H:98
const fileName & instance() const
Definition: IOobject.H:390
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
bool writeHeader(Ostream &) const
Write header.
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:312
InfoProxy< IOstream > info() const
Return info proxy.
Definition: IOstream.H:528
#define InfoInFunction
Report an information message using Foam::Info.