FreeFOAM The Cross-Platform CFD Toolkit
OStringStream.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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/OSstream.H>
39 #include <sstream>
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class OStringStream Declaration
48 \*---------------------------------------------------------------------------*/
49 
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  //- Construct as copy
77  :
78  OSstream
79  (
80  *(
81  new std::ostringstream
82  (
83  dynamic_cast<const std::ostringstream&>
84  (
85  oss.stream()
86  ).str()
87  )
88  ),
89  oss.name(),
90  oss.format(),
91  oss.version()
92  )
93  {}
94 
95 
96  // Destructor
97 
99  {
100  delete &dynamic_cast<std::ostringstream&>(stream());
101  }
102 
103 
104  // Member functions
105 
106  // Access
107 
108  //- Return the string
109  string str() const
110  {
111  return dynamic_cast<const std::ostringstream&>(stream()).str();
112  }
113 
114 
115  // Edit
116 
117  //- Clear the OStringStream
118  void rewind()
119  {
120 # if __GNUC__ < 4 && __GNUC_MINOR__ < 4
121  stream().rdbuf()->pubsetbuf(" ", 1);
122 # else
123  stream().rdbuf()->pubseekpos(0);
124 # endif
125  }
126 
127 
128  // Print
129 
130  //- Print description to Ostream
131  void print(Ostream&) const;
132 };
133 
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 } // End namespace Foam
138 
139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
140 
141 #endif
142 
143 // ************************ vim: set sw=4 sts=4 et: ************************ //