masterOFstream.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2017 OpenFOAM Foundation
9  Copyright (C) 2020-2021 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 Class
28  Foam::masterOFstream
29 
30 Description
31  Master-only drop-in replacement for OFstream.
32 
33 SourceFiles
34  masterOFstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef masterOFstream_H
39 #define masterOFstream_H
40 
41 #include "StringStream.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class masterOFstream Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class masterOFstream
53 :
54  public OStringStream
55 {
56  // Private Data
57 
58  const fileName pathName_;
59 
60  const IOstreamOption::compressionType compression_;
61 
62  const bool append_;
63 
64  //- Should file be written
65  const bool valid_;
66 
67 
68  // Private Member Functions
69 
70  //- Open file with checking and write append contents
71  void checkWrite
72  (
73  const fileName& fName,
74  const char* str,
75  std::streamsize len
76  );
77 
78  //- Open file with checking and write append contents
79  void checkWrite(const fileName& fName, const std::string& s);
80 
81  //- Commit buffered information, including parallel gather as required
82  void commit();
83 
84 
85 public:
86 
87  // Constructors
88 
89  //- Construct from pathname and set stream status
90  explicit masterOFstream
91  (
92  const fileName& pathname,
93  IOstreamOption streamOpt = IOstreamOption(),
94  const bool append = false,
95  const bool valid = true
96  );
97 
98  //- Construct from pathname, version and set stream status
100  (
101  const fileName& pathname,
105  const bool append = false,
106  const bool valid = true
107  )
108  :
110  (
111  pathname,
112  IOstreamOption(fmt, ver, cmp),
113  append,
114  valid
115  )
116  {}
117 
118 
119  //- Destructor - commits buffered information to file
120  ~masterOFstream();
121 };
122 
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 } // End namespace Foam
127 
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 
130 #endif
131 
132 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:79
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:193
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:165
StringStream.H
Input/output from string buffers.
Foam::masterOFstream::~masterOFstream
~masterOFstream()
Destructor - commits buffered information to file.
Definition: masterOFstream.C:200
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::masterOFstream::masterOFstream
masterOFstream(const fileName &pathname, IOstreamOption streamOpt=IOstreamOption(), const bool append=false, const bool valid=true)
Construct from pathname and set stream status.
Definition: masterOFstream.C:183
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Detail::StringStreamAllocator< std::ostringstream >::str
Foam::string str() const
Get the string - as Foam::string rather than std::string.
Definition: StringStream.H:88
Foam::OStringStream
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:227
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
Foam::masterOFstream
Master-only drop-in replacement for OFstream.
Definition: masterOFstream.H:51