00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::OStringStream 00026 00027 Description 00028 Output to memory buffer stream. 00029 00030 SourceFiles 00031 StringStreamsPrint.C 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef OStringStream_H 00036 #define OStringStream_H 00037 00038 #include <OpenFOAM/OSstream.H> 00039 #include <sstream> 00040 00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00042 00043 namespace Foam 00044 { 00045 00046 /*---------------------------------------------------------------------------*\ 00047 Class OStringStream Declaration 00048 \*---------------------------------------------------------------------------*/ 00049 00050 class OStringStream 00051 : 00052 public OSstream 00053 { 00054 00055 public: 00056 00057 // Constructors 00058 00059 //- Construct and set stream status 00060 OStringStream 00061 ( 00062 streamFormat format=ASCII, 00063 versionNumber version=currentVersion 00064 ) 00065 : 00066 OSstream 00067 ( 00068 *(new std::ostringstream()), 00069 "OStringStream.sinkFile", 00070 format, 00071 version 00072 ) 00073 {} 00074 00075 //- Construct as copy 00076 OStringStream(const OStringStream& oss) 00077 : 00078 OSstream 00079 ( 00080 *( 00081 new std::ostringstream 00082 ( 00083 dynamic_cast<const std::ostringstream&> 00084 ( 00085 oss.stream() 00086 ).str() 00087 ) 00088 ), 00089 oss.name(), 00090 oss.format(), 00091 oss.version() 00092 ) 00093 {} 00094 00095 00096 // Destructor 00097 00098 ~OStringStream() 00099 { 00100 delete &dynamic_cast<std::ostringstream&>(stream()); 00101 } 00102 00103 00104 // Member functions 00105 00106 // Access 00107 00108 //- Return the string 00109 string str() const 00110 { 00111 return dynamic_cast<const std::ostringstream&>(stream()).str(); 00112 } 00113 00114 00115 // Edit 00116 00117 //- Clear the OStringStream 00118 void rewind() 00119 { 00120 # if __GNUC__ < 4 && __GNUC_MINOR__ < 4 00121 stream().rdbuf()->pubsetbuf(" ", 1); 00122 # else 00123 stream().rdbuf()->pubseekpos(0); 00124 # endif 00125 } 00126 00127 00128 // Print 00129 00130 //- Print description to Ostream 00131 void print(Ostream&) const; 00132 }; 00133 00134 00135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00136 00137 } // End namespace Foam 00138 00139 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00140 00141 #endif 00142 00143 // ************************ vim: set sw=4 sts=4 et: ************************ //