OStringStream.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) 2011-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::OStringStream
26 
27 Description
28  Output to memory buffer stream.
29 
30 SourceFiles
31  StringStreamsPrint.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef OStringStream_H
36 #define OStringStream_H
37 
38 #include "OSstream.H"
39 #include <sstream>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class OStringStream Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class OStringStream
51 :
52  public OSstream
53 {
54 
55 public:
56 
57  // Constructors
58 
59  //- Construct and set stream status
61  (
64  )
65  :
66  OSstream
67  (
68  *(new std::ostringstream()),
69  "OStringStream.sinkFile",
70  format,
71  version
72  )
73  {}
74 
75  //- Copy constructor
76  OStringStream(const OStringStream& oss)
77  :
78  OSstream
79  (
80  *(
81  new std::ostringstream
82  (
83  dynamic_cast<const std::ostringstream&>
84  (
85  oss.stdStream()
86  ).str()
87  )
88  ),
89  oss.name(),
90  oss.format(),
91  oss.version()
92  )
93  {}
94 
95 
96  //- Destructor
98  {
99  delete &dynamic_cast<std::ostringstream&>(stdStream());
100  }
101 
102 
103  // Member Functions
104 
105  // Access
106 
107  //- Return the string
108  string str() const
109  {
110  return dynamic_cast<const std::ostringstream&>
111  (
112  stdStream()
113  ).str();
114  }
115 
116 
117  // Edit
118 
119  //- Rewind the OStringStream
120  void rewind()
121  {
122  stdStream().rdbuf()->pubseekpos(0);
123  }
124 
125 
126  // Print
127 
128  //- Print description to Ostream
129  void print(Ostream&) const;
130 };
131 
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace Foam
136 
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
138 
139 #endif
140 
141 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
Generic output stream.
Definition: OSstream.H:54
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:180
Output to memory buffer stream.
Definition: OStringStream.H:52
OStringStream(streamFormat format=ASCII, versionNumber version=currentVersion)
Construct and set stream status.
Definition: OStringStream.H:60
~OStringStream()
Destructor.
Definition: OStringStream.H:96
void print(Ostream &) const
Print description to Ostream.
void rewind()
Rewind the OStringStream.
string str() const
Return the string.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Namespace for OpenFOAM.