functionObjectFile.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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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::functionObjectFile
26 
27 Description
28  Base class for output file data handling
29 
30 See Also
31  Foam::functionObject
32  Foam::OutputFilterFunctionObject
33 
34 SourceFiles
35  functionObjectFile.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef functionObjectFile_H
40 #define functionObjectFile_H
41 
42 #include "objectRegistry.H"
43 #include "OFstream.H"
44 #include "PtrList.H"
45 #include "HashSet.H"
46 #include "IOmanip.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 
54 /*---------------------------------------------------------------------------*\
55  Class functionObjectFile Declaration
56 \*---------------------------------------------------------------------------*/
57 
59 {
60 private:
61 
62  // Private data
63 
64  //- Reference to the database
65  const objectRegistry& obr_;
66 
67  //- Prefix
68  const word prefix_;
69 
70  //- Name of file
72 
73  //- File pointer
75 
76  //- Write precision
78 
79 
80 protected:
81 
82  // Protected Data
83 
84  //- Flag to enable/disable writing to file
85  bool writeToFile_;
86 
87 
88  // Protected Member Functions
89 
90  //- Initialise the output stream for writing
91  virtual void initStream(Ostream& os) const;
92 
93  //- Return the base directory for output
94  virtual fileName baseFileDir() const;
95 
96  //- Return the base directory for the current time value
97  virtual fileName baseTimeDir() const;
98 
99  //- Return an autoPtr to a new file
100  virtual autoPtr<OFstream> createFile(const word& name) const;
101 
102  //- Reset internal file pointer to new file with new name
103  virtual void resetFile(const word& name);
104 
105  //- Return the value width when writing to stream with optional offset
106  virtual Omanip<int> valueWidth(const label offset = 0) const;
107 
108  //- Disallow default bitwise copy construct
110 
111  //- Disallow default bitwise assignment
112  void operator=(const functionObjectFile&);
113 
114 
115 public:
116 
117  //- Directory prefix
118  static const word outputPrefix;
119 
120  //- Additional characters for writing
121  static label addChars;
122 
123  // Constructors
124 
125  //- Construct null
126  functionObjectFile(const objectRegistry& obr, const word& prefix);
127 
128  //- Construct from components and read options from dictionary
130  (
131  const objectRegistry& obr,
132  const word& prefix,
133  const word& fileName,
134  const dictionary& dict
135  );
136 
137 
138  //- Destructor
139  virtual ~functionObjectFile();
140 
141 
142  // Member Functions
143 
144  //- Read
145  void read(const dictionary& dict);
146 
147  //- Return access to the file (if only 1)
148  OFstream& file();
149 
150  //- Return true if can write to file
151  bool writeToFile() const;
152 
153  //- Write a commented string to stream
154  void writeCommented
155  (
156  Ostream& os,
157  const string& str
158  ) const;
159 
160  //- Write a tabbed string to stream
161  void writeTabbed
162  (
163  Ostream& os,
164  const string& str
165  ) const;
166 
167  //- Write a commented header to stream
168  void writeHeader
169  (
170  Ostream& os,
171  const string& str
172  ) const;
173 
174  //- Write the current time to stream
175  void writeTime(Ostream& os) const;
176 
177  //- Write a (commented) header property and value pair
178  template<class Type>
179  void writeHeaderValue
180  (
181  Ostream& os,
182  const string& property,
183  const Type& value
184  ) const;
185 
186  //- Return width of character stream output
187  label charWidth() const;
188 };
189 
190 
191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 
193 } // End namespace Foam
194 
195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 
197 #ifdef NoRepository
199 #endif
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************************************************************* //
Foam::functionObjectFile::prefix_
const word prefix_
Prefix.
Definition: functionObjectFile.H:67
Foam::functionObjectFile::writeTime
void writeTime(Ostream &os) const
Write the current time to stream.
Definition: functionObjectFile.C:250
Foam::functionObjectFile::filePtr_
autoPtr< OFstream > filePtr_
File pointer.
Definition: functionObjectFile.H:73
Foam::functionObjectFile::valueWidth
virtual Omanip< int > valueWidth(const label offset=0) const
Return the value width when writing to stream with optional offset.
Definition: functionObjectFile.C:123
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::functionObjectFile::baseFileDir
virtual fileName baseFileDir() const
Return the base directory for output.
Definition: functionObjectFile.C:47
Foam::functionObjectFile::functionObjectFile
functionObjectFile(const functionObjectFile &)
Disallow default bitwise copy construct.
Foam::functionObjectFile::charWidth
label charWidth() const
Return width of character stream output.
Definition: functionObjectFile.C:212
Foam::functionObjectFile::writeTabbed
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: functionObjectFile.C:230
objectRegistry.H
Foam::functionObjectFile::read
void read(const dictionary &dict)
Read.
Definition: functionObjectFile.C:178
functionObjectFileTemplates.C
OFstream.H
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::functionObjectFile::file
OFstream & file()
Return access to the file (if only 1)
Definition: functionObjectFile.C:189
Foam::label
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
IOmanip.H
Istream and Ostream manipulators taking arguments.
Foam::functionObjectFile::initStream
virtual void initStream(Ostream &os) const
Initialise the output stream for writing.
Definition: functionObjectFile.C:39
Foam::functionObjectFile::outputPrefix
static const word outputPrefix
Directory prefix.
Definition: functionObjectFile.H:117
HashSet.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionObjectFile::writeHeader
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: functionObjectFile.C:240
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::functionObjectFile::operator=
void operator=(const functionObjectFile &)
Disallow default bitwise assignment.
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::functionObjectFile::writeToFile
bool writeToFile() const
Return true if can write to file.
Definition: functionObjectFile.C:206
Foam::functionObjectFile::writeHeaderValue
void writeHeaderValue(Ostream &os, const string &property, const Type &value) const
Write a (commented) header property and value pair.
Definition: functionObjectFileTemplates.C:32
Foam::functionObjectFile::resetFile
virtual void resetFile(const word &name)
Reset internal file pointer to new file with new name.
Definition: functionObjectFile.C:116
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::functionObjectFile::obr_
const objectRegistry & obr_
Reference to the database.
Definition: functionObjectFile.H:64
Foam::functionObjectFile::addChars
static label addChars
Additional characters for writing.
Definition: functionObjectFile.H:120
Foam::Omanip
Definition: IOmanip.H:47
Foam::functionObjectFile::createFile
virtual autoPtr< OFstream > createFile(const word &name) const
Return an autoPtr to a new file.
Definition: functionObjectFile.C:83
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
PtrList.H
Foam::functionObjectFile::fileName_
word fileName_
Name of file.
Definition: functionObjectFile.H:70
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::functionObjectFile::writeCommented
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: functionObjectFile.C:219
Foam::functionObjectFile::baseTimeDir
virtual fileName baseTimeDir() const
Return the base directory for the current time value.
Definition: functionObjectFile.C:76
Foam::functionObjectFile::writePrecision_
label writePrecision_
Write precision.
Definition: functionObjectFile.H:76
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::functionObjectFile::writeToFile_
bool writeToFile_
Flag to enable/disable writing to file.
Definition: functionObjectFile.H:84
Foam::functionObjectFile::~functionObjectFile
virtual ~functionObjectFile()
Destructor.
Definition: functionObjectFile.C:172