BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / IOstreams / StringStreams / OStringStream.H
blob449e4fb5a4dddbf5e613a141326a96ce47a231e3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 Class
25     Foam::OStringStream
27 Description
28     Output to memory buffer stream.
30 SourceFiles
31     StringStreamsPrint.C
33 \*---------------------------------------------------------------------------*/
35 #ifndef OStringStream_H
36 #define OStringStream_H
38 #include "OSstream.H"
39 #include <sstream>
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 namespace Foam
46 /*---------------------------------------------------------------------------*\
47                         Class OStringStream Declaration
48 \*---------------------------------------------------------------------------*/
50 class OStringStream
52     public OSstream
55 public:
57     // Constructors
59         //- Construct and set stream status
60         OStringStream
61         (
62             streamFormat format=ASCII,
63             versionNumber version=currentVersion
64         )
65         :
66             OSstream
67             (
68                *(new std::ostringstream()),
69                 "OStringStream.sinkFile",
70                 format,
71                 version
72             )
73         {}
75         //- Construct as copy
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         {}
96     //- Destructor
97     ~OStringStream()
98     {
99         delete &dynamic_cast<std::ostringstream&>(stdStream());
100     }
103     // Member functions
105         // Access
107             //- Return the string
108             string str() const
109             {
110                 return dynamic_cast<const std::ostringstream&>
111                 (
112                     stdStream()
113                 ).str();
114             }
117         // Edit
119             //- Clear the OStringStream
120             void rewind()
121             {
122 #               if __GNUC__ < 4 && __GNUC_MINOR__ < 4
123                 stdStream().rdbuf()->pubsetbuf(" ", 1);
124 #               else
125                 stdStream().rdbuf()->pubseekpos(0);
126 #               endif
127             }
130         // Print
132             //- Print description to Ostream
133             void print(Ostream&) const;
137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 } // End namespace Foam
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 #endif
145 // ************************************************************************* //