writeFile.H
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) 2012-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 Class
25  Foam::functionObjects::writeFile
26 
27 Description
28  functionObject base class for writing single files
29 
30 See also
31  Foam::regionFunctionObject
32  Foam::functionObject
33 
34 SourceFiles
35  functionObjectFile.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef functionObjects_writeFile_H
40 #define functionObjects_writeFile_H
41 
42 #include "regionFunctionObject.H"
43 #include "Time.H"
44 #include "IOmanip.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace functionObjects
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class functionObjectFile Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class writeFile
58 :
60 {
61 
62 protected:
63 
64  // Protected data
65 
66  //- Prefix
67  const word prefix_;
68 
69 
70  // Protected Member Functions
71 
72  //- Initialise the output stream for writing
73  virtual void initStream(Ostream& os) const;
74 
75  //- Return the base directory for output
76  virtual fileName baseFileDir() const;
77 
78  //- Return the base directory for the current time value
79  virtual fileName baseTimeDir() const;
80 
81  //- File header information
82  virtual void writeFileHeader(const label i = 0);
83 
84  //- Return the value width when writing to stream with optional offset
85  virtual Omanip<int> valueWidth(const label offset = 0) const;
86 
87  //- Disallow default bitwise copy construct
88  writeFile(const writeFile&);
89 
90  //- Disallow default bitwise assignment
91  void operator=(const writeFile&);
92 
93 
94 public:
95 
96  //- Directory prefix
97  static const word outputPrefix;
98 
99  //- Additional characters for writing
100  static label addChars;
101 
102 
103  // Constructors
104 
105  //- Construct from name, Time, dictionary and prefix
106  writeFile
107  (
108  const word& name,
109  const Time& t,
110  const dictionary& dict,
111  const word& prefix
112  );
113 
114  //- Construct from name, objectRegistry, dictionary and prefix
115  writeFile
116  (
117  const word& name,
118  const objectRegistry& obr,
119  const dictionary& dict,
120  const word& prefix
121  );
122 
123 
124  //- Destructor
125  virtual ~writeFile();
126 
127 
128  // Member Functions
129 
130  //- Write a commented string to stream
131  void writeCommented(Ostream& os, const string& str) const;
132 
133  //- Write a tabbed string to stream
134  void writeTabbed(Ostream& os, const string& str) const;
135 
136  //- Write a commented header to stream
137  void writeHeader(Ostream& os, const string& str) const;
138 
139  //- Write the current time to stream
140  void writeTime(Ostream& os) const;
141 
142  //- Write a (commented) header property and value pair
143  template<class Type>
144  void writeHeaderValue
145  (
146  Ostream& os,
147  const string& property,
148  const Type& value
149  ) const;
150 
151  //- Return width of character stream output
152  label charWidth() const;
153 };
154 
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 } // End namespace functionObjects
159 } // End namespace Foam
160 
161 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 
163 #ifdef NoRepository
164  #include "writeFileTemplates.C"
165 #endif
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #endif
170 
171 // ************************************************************************* //
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:152
Specialization of Foam::functionObject for a region and providing a reference to the region Foam::obj...
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:162
dictionary dict
virtual void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:43
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
A class for handling file names.
Definition: fileName.H:69
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
virtual fileName baseTimeDir() const
Return the base directory for the current time value.
Definition: writeFile.C:79
static label addChars
Additional characters for writing.
Definition: writeFile.H:99
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:134
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual fileName baseFileDir() const
Return the base directory for output.
Definition: writeFile.C:50
virtual void writeFileHeader(const label i=0)
File header information.
Definition: writeFile.C:85
const word & name() const
Return the name of this functionObject.
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:172
static const word outputPrefix
Directory prefix.
Definition: writeFile.H:96
A class for handling words, derived from string.
Definition: word.H:59
writeFile(const writeFile &)
Disallow default bitwise copy construct.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Istream and Ostream manipulators taking arguments.
virtual Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:90
void operator=(const writeFile &)
Disallow default bitwise assignment.
const word prefix_
Prefix.
Definition: writeFile.H:66
virtual ~writeFile()
Destructor.
Definition: writeFile.C:128
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:141
Registry of regIOobjects.
functionObject base class for writing single files
Definition: writeFile.H:56
Namespace for OpenFOAM.