IOobjectWriteHeader.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 | Copyright (C) 2011-2016 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)
47  << "FoamFile\n{\n"
48  << " version " << os.version() << ";\n"
49  << " format " << os.format() << ";\n"
50  << " class " << type << ";\n";
51 
52  if (note().size())
53  {
54  os << " note " << note() << ";\n";
55  }
56 
57  os << " location " << instance()/db().dbDir()/local() << ";\n"
58  << " object " << name() << ";\n"
59  << "}" << nl;
60 
61  writeDivider(os) << endl;
62 
63  return true;
64 }
65 
66 
68 {
69  return writeHeader(os, type());
70 }
71 
72 
73 // ************************************************************************* //
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
static Stream & writeBanner(Stream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
Definition: IOobjectI.H:45
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:221
InfoProxy< IOstream > info() const
Return info proxy.
Definition: IOstream.H:531
static Stream & writeDivider(Stream &os)
Write the standard file section divider.
Definition: IOobjectI.H:98
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
bool writeHeader(Ostream &) const
Write header.
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:272
A class for handling words, derived from string.
Definition: word.H:59
const fileName & local() const
Definition: IOobject.H:347
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
virtual const fileName & dbDir() const
Local directory path of this objectRegistry relative to the time.
const fileName & instance() const
Definition: IOobject.H:337
const word & name() const
Return name.
Definition: IOobject.H:260
#define InfoInFunction
Report an information message using Foam::Info.