1 /*============================================================================
2 KWSys - Kitware System Library
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #ifndef @KWSYS_NAMESPACE@_ios_sstream
13 #define @KWSYS_NAMESPACE@_ios_sstream
15 #include <@KWSYS_NAMESPACE@/Configure.hxx>
17 /* Define this macro temporarily to keep the code readable. */
18 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
19 # define kwsys_stl @KWSYS_NAMESPACE@_stl
22 #if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
24 # pragma warning (push, 1)
25 # pragma warning (disable: 4702)
33 # pragma warning (push, 1)
34 # pragma warning (disable: 4702)
35 # pragma warning (disable: 4995) /* Old streams are deprecated. */
37 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
39 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
40 # include <strstream.h>
41 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
42 # include <strstrea.h>
44 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
45 # include <new> // Need placement operator new.
47 # include <new.h> // Need placement operator new.
53 // Only have old std strstream classes. Wrap them to look like new
54 // ostringstream and istringstream classes.
56 # include <@KWSYS_NAMESPACE@/stl/string>
58 namespace @KWSYS_NAMESPACE@_ios
60 using @KWSYS_NAMESPACE@_ios_namespace::streambuf;
61 using @KWSYS_NAMESPACE@_ios_namespace::ostream;
62 using @KWSYS_NAMESPACE@_ios_namespace::istream;
63 using @KWSYS_NAMESPACE@_ios_namespace::strstream;
64 using @KWSYS_NAMESPACE@_ios_namespace::istrstream;
65 using @KWSYS_NAMESPACE@_ios_namespace::ostrstream;
66 using @KWSYS_NAMESPACE@_ios_namespace::ios;
67 using @KWSYS_NAMESPACE@_ios_namespace::endl;
68 using @KWSYS_NAMESPACE@_ios_namespace::ends;
69 using @KWSYS_NAMESPACE@_ios_namespace::flush;
71 class stringstream_cleanup
74 stringstream_cleanup(strstream& str): m_StrStream(str) {}
75 ~stringstream_cleanup() { m_StrStream.rdbuf()->freeze(0); }
76 static void IgnoreUnusedVariable(const stringstream_cleanup&) {}
78 strstream& m_StrStream;
80 void operator=(stringstream_cleanup const&);
83 class stringstream: public strstream
86 typedef strstream Superclass;
88 stringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
89 kwsys_stl::string str()
91 stringstream_cleanup cleanup(*this);
92 stringstream_cleanup::IgnoreUnusedVariable(cleanup);
93 // Visual Studio 6 has a strstream::pcount, but this is not rdbuf()->pcount()
94 #if (@KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H) && defined(_MSC_VER) && (_MSC_VER == 1200)
95 int count = this->pcount();
96 #elif defined(__WATCOMC__)
97 int count = this->rdbuf()->out_waiting();
99 int count = this->rdbuf()->pcount();
101 const char* ptr = this->Superclass::str();
102 return kwsys_stl::string(ptr?ptr:"", count);
104 void str(const kwsys_stl::string& s)
106 this->~stringstream();
107 new (this) stringstream(s);
110 stringstream(const stringstream&);
111 void operator=(const stringstream&);
114 class ostringstream_cleanup
117 ostringstream_cleanup(ostrstream& ostr): m_OStrStream(ostr) {}
118 ~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
119 static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
121 ostrstream& m_OStrStream;
123 void operator=(ostringstream_cleanup const&);
126 class ostringstream: public ostrstream
129 typedef ostrstream Superclass;
131 ostringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
132 kwsys_stl::string str()
134 ostringstream_cleanup cleanup(*this);
135 ostringstream_cleanup::IgnoreUnusedVariable(cleanup);
136 int count = this->pcount();
137 const char* ptr = this->Superclass::str();
138 return kwsys_stl::string(ptr?ptr:"", count);
140 void str(const kwsys_stl::string& s)
142 this->~ostringstream();
143 new (this) ostringstream(s);
146 ostringstream(const ostringstream&);
147 void operator=(const ostringstream&);
150 #if defined(_MSC_VER)
151 # pragma warning (push)
152 # pragma warning (disable: 4097) /* typedef-name used as synonym for class */
154 #if defined(__WATCOMC__)
155 // W728: class modifiers for 'A' conflict with class modifiers for 'B'
156 # pragma warning 728 10
159 class istringstream: private kwsys_stl::string, public istrstream
162 typedef kwsys_stl::string StdString;
163 typedef istrstream IStrStream;
164 istringstream(): StdString(),
165 IStrStream(const_cast<char*>(StdString::c_str())) {}
166 istringstream(const kwsys_stl::string& s):
167 StdString(s), IStrStream(const_cast<char*>(StdString::c_str())) {}
168 kwsys_stl::string str() const { return *this; }
169 void str(const kwsys_stl::string& s)
171 this->~istringstream();
172 new (this) istringstream(s);
174 void clear(int flags)
176 this->IStrStream::clear(flags);
179 istringstream(const istringstream&);
180 void operator=(const istringstream&);
183 #if defined(__WATCOMC__)
184 # pragma warning 728 9
186 #if defined(_MSC_VER)
187 # pragma warning (pop)
190 } // namespace @KWSYS_NAMESPACE@_ios
194 /* Undefine temporary macro. */
195 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS