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-2019 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 public:
71 
72  //- Directory prefix
73  static const word outputPrefix;
74 
75  //- Additional characters for writing
76  static label addChars;
77 
78 
79  // Constructors
80 
81  //- Construct from objectRegistry and prefix
82  writeFile
83  (
84  const objectRegistry& obr,
85  const word& prefix
86  );
87 
88  //- Disallow default bitwise copy construction
89  writeFile(const writeFile&) = delete;
90 
91 
92  //- Destructor
93  ~writeFile();
94 
95 
96  // Member Functions
97 
98  //- Initialise the output stream for writing
99  void initStream(Ostream& os) const;
100 
101  //- Return the base directory for output
102  fileName baseFileDir() const;
103 
104  //- Return the base directory for the current time value
105  fileName baseTimeDir() const;
106 
107  //- Return the value width when writing to stream with optional offset
108  Omanip<int> valueWidth(const label offset = 0) const;
109 
110  //- Write a commented string to stream
111  void writeCommented(Ostream& os, const string& str) const;
112 
113  //- Write a tabbed string to stream
114  void writeTabbed(Ostream& os, const string& str) const;
115 
116  //- Write a commented header to stream
117  void writeHeader(Ostream& os, const string& str) const;
118 
119  //- Write the current time to stream
120  void writeTime(Ostream& os) const;
121 
122  //- Write a (commented) header property and value pair
123  template<class Type>
124  void writeHeaderValue
125  (
126  Ostream& os,
127  const string& property,
128  const Type& value
129  ) const;
130 
131  //- Return width of character stream output
132  label charWidth() const;
133 
134 
135  // Member Operators
136 
137  //- Disallow default bitwise assignment
138  void operator=(const writeFile&) = delete;
139 };
140 
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 } // End namespace functionObjects
145 } // End namespace Foam
146 
147 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
148 
149 #ifdef NoRepository
150  #include "writeFileTemplates.C"
151 #endif
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 #endif
156 
157 // ************************************************************************* //
Istream and Ostream manipulators taking arguments.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A class for handling file names.
Definition: fileName.H:82
functionObject base class for writing single files
Definition: writeFile.H:56
void operator=(const writeFile &)=delete
Disallow default bitwise assignment.
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:141
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:121
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
label charWidth() const
Return width of character stream output.
Definition: writeFile.C:103
Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: writeFile.C:74
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:131
const word prefix_
Prefix.
Definition: writeFile.H:66
static const word outputPrefix
Directory prefix.
Definition: writeFile.H:72
void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: writeFile.C:42
static label addChars
Additional characters for writing.
Definition: writeFile.H:75
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:110
fileName baseTimeDir() const
Return the base directory for the current time value.
Definition: writeFile.C:67
writeFile(const objectRegistry &obr, const word &prefix)
Construct from objectRegistry and prefix.
Definition: writeFile.C:85
const objectRegistry & fileObr_
Reference to the region objectRegistry.
Definition: writeFile.H:63
Registry of regIOobjects.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
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
void offset(label &lst, const label o)