writeFile.H
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) 2012-2018 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::functionObject
32  Foam::functionObjects::logFiles
33 
34 SourceFiles
35  writeFile.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef functionObjects_writeFile_H
40 #define functionObjects_writeFile_H
41 
42 #include "objectRegistry.H"
43 #include "IOmanip.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 namespace functionObjects
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class functionObjectFile Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class writeFile
57 {
58 
59 protected:
60 
61  // Protected data
62 
63  //- Reference to the region objectRegistry
64  const objectRegistry& fileObr_;
65 
66  //- Prefix
67  const word prefix_;
68 
69 
70 private:
71 
72  // Private Member Functions
73 
74  //- Disallow default bitwise copy construct
75  writeFile(const writeFile&);
76 
77  //- Disallow default bitwise assignment
78  void operator=(const writeFile&);
79 
80 
81 public:
82 
83  //- Directory prefix
84  static const word outputPrefix;
85 
86  //- Additional characters for writing
87  static label addChars;
88 
89 
90  // Constructors
91 
92  //- Construct from objectRegistry and prefix
93  writeFile
94  (
95  const objectRegistry& obr,
96  const word& prefix
97  );
98 
99 
100  //- Destructor
101  ~writeFile();
102 
103 
104  // Member Functions
105 
106  //- Initialise the output stream for writing
107  void initStream(Ostream& os) const;
108 
109  //- Return the base directory for output
110  fileName baseFileDir() const;
111 
112  //- Return the base directory for the current time value
113  fileName baseTimeDir() const;
114 
115  //- Return the value width when writing to stream with optional offset
116  Omanip<int> valueWidth(const label offset = 0) const;
117 
118  //- Write a commented string to stream
119  void writeCommented(Ostream& os, const string& str) const;
120 
121  //- Write a tabbed string to stream
122  void writeTabbed(Ostream& os, const string& str) const;
123 
124  //- Write a commented header to stream
125  void writeHeader(Ostream& os, const string& str) const;
126 
127  //- Write the current time to stream
128  void writeTime(Ostream& os) const;
129 
130  //- Write a (commented) header property and value pair
131  template<class Type>
132  void writeHeaderValue
133  (
134  Ostream& os,
135  const string& property,
136  const Type& value
137  ) const;
138 
139  //- Return width of character stream output
140  label charWidth() const;
141 };
142 
143 
144 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
145 
146 } // End namespace functionObjects
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #ifdef NoRepository
152  #include "writeFileTemplates.C"
153 #endif
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
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
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:145
static label addChars
Additional characters for writing.
Definition: writeFile.H:86
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:124
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:42
static const word outputPrefix
Directory prefix.
Definition: writeFile.H:83
A class for handling words, derived from string.
Definition: word.H:59
fileName baseTimeDir() const
Return the base directory for the current time value.
Definition: writeFile.C:81
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:117
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
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.
const word prefix_
Prefix.
Definition: writeFile.H:66
fileName baseFileDir() const
Return the base directory for output.
Definition: writeFile.C:49
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:155
Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:88
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition: writeFile.H:63
Registry of regIOobjects.
functionObject base class for writing single files
Definition: writeFile.H:55
Namespace for OpenFOAM.
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:135