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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2017 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 "IOobject.H"
30 #include "objectRegistry.H"
31 #include "foamVersion.H"
32 
33 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 
35 // A banner corresponding to this:
36 //
37 /*--------------------------------*- C++ -*----------------------------------*\
38 | ========= | |
39 | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
40 | \\ / O peration | Version: VERSION |
41 | \\ / A nd | Website: www.openfoam.com |
42 | \\/ M anipulation | |
43 \*---------------------------------------------------------------------------*/
44 
46 {
47  // The version padded with spaces to fit after "Version: "
48  // - initialized with zero-length string to detect if it has been populated
49  static char paddedVersion[39] = "";
50 
51  if (!*paddedVersion)
52  {
53  // Populate: like strncpy but without trailing '\0'
54 
55  std::size_t len = foamVersion::version.length();
56  if (len > 38)
57  {
58  len = 38;
59  }
60 
61  std::memset(paddedVersion, ' ', 38);
62  std::memcpy(paddedVersion, foamVersion::version.c_str(), len);
63  paddedVersion[38] = '\0';
64  }
65 
66  os <<
67  "/*--------------------------------";
68 
69  if (noHint)
70  {
71  // Without syntax hint
72  os << "---------";
73  }
74  else
75  {
76  // With syntax hint
77  os << "*- C++ -*";
78  }
79 
80  os <<
81  "----------------------------------*\\\n"
82  "| ========= |"
83  " |\n"
84  "| \\\\ / F ield |"
85  " OpenFOAM: The Open Source CFD Toolbox |\n"
86  "| \\\\ / O peration |"
87  " Version: " << paddedVersion << "|\n"
88  "| \\\\ / A nd |"
89  " Website: www.openfoam.com |\n"
90  "| \\\\/ M anipulation |"
91  " |\n"
92  "\\*-----------------------------------------"
93  "----------------------------------*/\n";
94 
95  return os;
96 }
97 
98 
100 {
101  os <<
102  "// * * * * * * * * * * * * * * * * * "
103  "* * * * * * * * * * * * * * * * * * * * //\n";
104 
105  return os;
106 }
107 
108 
110 {
111  os << "\n\n"
112  "// *****************************************"
113  "******************************** //\n";
114 
115  return os;
116 }
117 
118 
120 {
121  if (!os.good())
122  {
124  << "No stream open for write" << nl
125  << os.info() << endl;
126 
127  return false;
128  }
129 
130  writeBanner(os)
131  << "FoamFile\n{\n"
132  << " version " << os.version() << ";\n"
133  << " format " << os.format() << ";\n"
134  << " class " << type << ";\n";
135 
136  if (os.format() == IOstream::BINARY)
137  {
138  os << " arch " << foamVersion::buildArch << ";\n";
139  }
140 
141  if (!note().empty())
142  {
143  os << " note " << note() << ";\n";
144  }
145 
146  os << " location " << instance()/db().dbDir()/local() << ";\n"
147  << " object " << name() << ";\n"
148  << "}" << nl;
149 
150  writeDivider(os) << nl;
151 
152  return true;
153 }
154 
155 
157 {
158  return writeHeader(os, type());
159 }
160 
161 
162 // ************************************************************************* //
InfoInFunction
#define InfoInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:325
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::IOobject::writeBanner
static Ostream & writeBanner(Ostream &os, bool noHint=false)
Write the standard OpenFOAM file/dictionary banner.
Definition: IOobjectWriteHeader.C:45
Foam::IOobject::writeEndDivider
static Ostream & writeEndDivider(Ostream &os)
Write the standard end file divider.
Definition: IOobjectWriteHeader.C:109
objectRegistry.H
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:289
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::writeHeader
static void writeHeader(Ostream &os, const word &fieldName)
Definition: rawSurfaceWriterImpl.C:49
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::IOstream::info
InfoProxy< IOstream > info() const
Return info proxy.
Definition: IOstream.H:404
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:341
IOobject.H
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:73
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::IOobject::writeDivider
static Ostream & writeDivider(Ostream &os)
Write the standard file section divider.
Definition: IOobjectWriteHeader.C:99
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::foamVersion::buildArch
const std::string buildArch
Foam::IOobject::writeHeader
bool writeHeader(Ostream &os) const
Write header.
Definition: IOobjectWriteHeader.C:156
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:224
foamVersion.H