Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / kwsys / kwsys_ios_sstream.h.in
blobc8b1e868284d7492f884f50594d6fa3ae1fddedc
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
22 #endif
24 #if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
25 # ifdef _MSC_VER
26 # pragma warning (push, 1)
27 # pragma warning (disable: 4702)
28 # endif
29 # include <sstream>
30 # ifdef _MSC_VER
31 # pragma warning(pop)
32 # endif
33 #else
34 # ifdef _MSC_VER
35 # pragma warning (push, 1)
36 # pragma warning (disable: 4702)
37 # pragma warning (disable: 4995) /* Old streams are deprecated. */
38 # endif
39 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
40 # include <strstream>
41 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
42 # include <strstream.h>
43 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
44 # include <strstrea.h>
45 # endif
46 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
47 # include <new> // Need placement operator new.
48 # else
49 # include <new.h> // Need placement operator new.
50 # endif
51 # ifdef _MSC_VER
52 # pragma warning(pop)
53 # endif
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
75 public:
76 stringstream_cleanup(strstream& str): m_StrStream(str) {}
77 ~stringstream_cleanup() { m_StrStream.rdbuf()->freeze(0); }
78 static void IgnoreUnusedVariable(const stringstream_cleanup&) {}
79 protected:
80 strstream& m_StrStream;
81 private:
82 void operator=(stringstream_cleanup const&);
85 class stringstream: public strstream
87 public:
88 typedef strstream Superclass;
89 stringstream() {}
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();
100 #else
101 int count = this->rdbuf()->pcount();
102 #endif
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);
111 private:
112 stringstream(const stringstream&);
113 void operator=(const stringstream&);
116 class ostringstream_cleanup
118 public:
119 ostringstream_cleanup(ostrstream& ostr): m_OStrStream(ostr) {}
120 ~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
121 static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
122 protected:
123 ostrstream& m_OStrStream;
124 private:
125 void operator=(ostringstream_cleanup const&);
128 class ostringstream: public ostrstream
130 public:
131 typedef ostrstream Superclass;
132 ostringstream() {}
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);
147 private:
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 */
155 #endif
156 #if defined(__WATCOMC__)
157 // W728: class modifiers for 'A' conflict with class modifiers for 'B'
158 # pragma warning 728 10
159 #endif
161 class istringstream: private kwsys_stl::string, public istrstream
163 public:
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);
180 private:
181 istringstream(const istringstream&);
182 void operator=(const istringstream&);
185 #if defined(__WATCOMC__)
186 # pragma warning 728 9
187 #endif
188 #if defined(_MSC_VER)
189 # pragma warning (pop)
190 #endif
192 } // namespace @KWSYS_NAMESPACE@_ios
194 #endif
196 /* Undefine temporary macro. */
197 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
198 # undef kwsys_stl
199 #endif
201 #endif