1 /*=========================================================================
3 Program: KWSys - Kitware System Library
4 Module: $RCSfile: kwsys_ios_sstream.h.in,v $
6 Copyright (c) Kitware, Inc., Insight Consortium. All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notices for more information.
13 =========================================================================*/
14 #ifndef @KWSYS_NAMESPACE@_ios_sstream
15 #define @KWSYS_NAMESPACE@_ios_sstream
17 #include <@KWSYS_NAMESPACE@/Configure.hxx>
19 /* Define this macro temporarily to keep the code readable. */
20 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
21 # define kwsys_stl @KWSYS_NAMESPACE@_stl
24 #if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
26 # pragma warning (push, 1)
27 # pragma warning (disable: 4702)
35 # pragma warning (push, 1)
36 # pragma warning (disable: 4702)
37 # pragma warning (disable: 4995) /* Old streams are deprecated. */
39 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
41 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
42 # include <strstream.h>
43 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
44 # include <strstrea.h>
46 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
47 # include <new> // Need placement operator new.
49 # include <new.h> // Need placement operator new.
55 // Only have old std strstream classes. Wrap them to look like new
56 // ostringstream and istringstream classes.
58 # include <@KWSYS_NAMESPACE@/stl/string>
60 namespace @KWSYS_NAMESPACE@_ios
62 using @KWSYS_NAMESPACE@
_ios_namespace::streambuf
;
63 using @KWSYS_NAMESPACE@
_ios_namespace::ostream
;
64 using @KWSYS_NAMESPACE@
_ios_namespace::istream
;
65 using @KWSYS_NAMESPACE@
_ios_namespace::strstream
;
66 using @KWSYS_NAMESPACE@
_ios_namespace::istrstream
;
67 using @KWSYS_NAMESPACE@
_ios_namespace::ostrstream
;
68 using @KWSYS_NAMESPACE@
_ios_namespace::ios
;
69 using @KWSYS_NAMESPACE@
_ios_namespace::endl
;
70 using @KWSYS_NAMESPACE@
_ios_namespace::ends
;
71 using @KWSYS_NAMESPACE@
_ios_namespace::flush
;
73 class stringstream_cleanup
76 stringstream_cleanup(strstream
& str
): m_StrStream(str
) {}
77 ~stringstream_cleanup() { m_StrStream
.rdbuf()->freeze(0); }
78 static void IgnoreUnusedVariable(const stringstream_cleanup
&) {}
80 strstream
& m_StrStream
;
82 void operator=(stringstream_cleanup
const&);
85 class stringstream
: public strstream
88 typedef strstream Superclass
;
90 stringstream(const kwsys_stl::string
& s
) { *this << s
.c_str(); }
91 kwsys_stl::string
str()
93 stringstream_cleanup
cleanup(*this);
94 stringstream_cleanup::IgnoreUnusedVariable(cleanup
);
95 // Visual Studio 6 has a strstream::pcount, but this is not rdbuf()->pcount()
96 #if (@KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H) && defined(_MSC_VER) && (_MSC_VER == 1200)
97 int count
= this->pcount();
98 #elif defined(__WATCOMC__)
99 int count
= this->rdbuf()->out_waiting();
101 int count
= this->rdbuf()->pcount();
103 const char* ptr
= this->Superclass::str();
104 return kwsys_stl::string(ptr
?ptr
:"", count
);
106 void str(const kwsys_stl::string
& s
)
108 this->~stringstream();
109 new (this) stringstream(s
);
112 stringstream(const stringstream
&);
113 void operator=(const stringstream
&);
116 class ostringstream_cleanup
119 ostringstream_cleanup(ostrstream
& ostr
): m_OStrStream(ostr
) {}
120 ~ostringstream_cleanup() { m_OStrStream
.rdbuf()->freeze(0); }
121 static void IgnoreUnusedVariable(const ostringstream_cleanup
&) {}
123 ostrstream
& m_OStrStream
;
125 void operator=(ostringstream_cleanup
const&);
128 class ostringstream
: public ostrstream
131 typedef ostrstream Superclass
;
133 ostringstream(const kwsys_stl::string
& s
) { *this << s
.c_str(); }
134 kwsys_stl::string
str()
136 ostringstream_cleanup
cleanup(*this);
137 ostringstream_cleanup::IgnoreUnusedVariable(cleanup
);
138 int count
= this->pcount();
139 const char* ptr
= this->Superclass::str();
140 return kwsys_stl::string(ptr
?ptr
:"", count
);
142 void str(const kwsys_stl::string
& s
)
144 this->~ostringstream();
145 new (this) ostringstream(s
);
148 ostringstream(const ostringstream
&);
149 void operator=(const ostringstream
&);
152 #if defined(_MSC_VER)
153 # pragma warning (push)
154 # pragma warning (disable: 4097) /* typedef-name used as synonym for class */
156 #if defined(__WATCOMC__)
157 // W728: class modifiers for 'A' conflict with class modifiers for 'B'
158 # pragma warning 728 10
161 class istringstream
: private kwsys_stl::string
, public istrstream
164 typedef kwsys_stl::string StdString
;
165 typedef istrstream IStrStream
;
166 istringstream(): StdString(),
167 IStrStream(const_cast<char*>(StdString::c_str())) {}
168 istringstream(const kwsys_stl::string
& s
):
169 StdString(s
), IStrStream(const_cast<char*>(StdString::c_str())) {}
170 kwsys_stl::string
str() const { return *this; }
171 void str(const kwsys_stl::string
& s
)
173 this->~istringstream();
174 new (this) istringstream(s
);
176 void clear(int flags
)
178 this->IStrStream::clear(flags
);
181 istringstream(const istringstream
&);
182 void operator=(const istringstream
&);
185 #if defined(__WATCOMC__)
186 # pragma warning 728 9
188 #if defined(_MSC_VER)
189 # pragma warning (pop)
192 } // namespace @KWSYS_NAMESPACE@_ios
196 /* Undefine temporary macro. */
197 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS