TZIVI-254: IVI needs a newer version of cmake
[profile/ivi/cmake.git] / Source / kwsys / kwsys_ios_sstream.h.in
1 /*============================================================================
2   KWSys - Kitware System Library
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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
14
15 #include <@KWSYS_NAMESPACE@/Configure.hxx>
16
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
20 #endif
21
22 #if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
23 # ifdef _MSC_VER
24 #  pragma warning (push, 1)
25 #  pragma warning (disable: 4702)
26 # endif
27 # include <sstream>
28 # ifdef _MSC_VER
29 #  pragma warning(pop)
30 # endif
31 #else
32 # ifdef _MSC_VER
33 #  pragma warning (push, 1)
34 #  pragma warning (disable: 4702)
35 #  pragma warning (disable: 4995) /* Old streams are deprecated.  */
36 # endif
37 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
38 #  include <strstream>
39 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
40 #  include <strstream.h>
41 # elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
42 #  include <strstrea.h>
43 # endif
44 # if @KWSYS_NAMESPACE@_IOS_USE_ANSI
45 #  include <new> // Need placement operator new.
46 # else
47 #  include <new.h> // Need placement operator new.
48 # endif
49 # ifdef _MSC_VER
50 #  pragma warning(pop)
51 # endif
52
53 // Only have old std strstream classes.  Wrap them to look like new
54 // ostringstream and istringstream classes.
55
56 # include <@KWSYS_NAMESPACE@/stl/string>
57
58 namespace @KWSYS_NAMESPACE@_ios
59 {
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;
70
71 class stringstream_cleanup
72 {
73 public:
74   stringstream_cleanup(strstream& str): m_StrStream(str) {}
75   ~stringstream_cleanup() { m_StrStream.rdbuf()->freeze(0); }
76   static void IgnoreUnusedVariable(const stringstream_cleanup&) {}
77 protected:
78   strstream& m_StrStream;
79 private:
80   void operator=(stringstream_cleanup const&);
81 };
82
83 class stringstream: public strstream
84 {
85 public:
86   typedef strstream Superclass;
87   stringstream() {}
88   stringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
89   kwsys_stl::string str()
90     {
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();
98 #else
99     int count = this->rdbuf()->pcount();
100 #endif
101     const char* ptr = this->Superclass::str();
102     return kwsys_stl::string(ptr?ptr:"", count);
103     }
104   void str(const kwsys_stl::string& s)
105     {
106     this->~stringstream();
107     new (this) stringstream(s);
108     }
109 private:
110   stringstream(const stringstream&);
111   void operator=(const stringstream&);
112 };
113
114 class ostringstream_cleanup
115 {
116 public:
117   ostringstream_cleanup(ostrstream& ostr): m_OStrStream(ostr) {}
118   ~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
119   static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
120 protected:
121   ostrstream& m_OStrStream;
122 private:
123   void operator=(ostringstream_cleanup const&);
124 };
125
126 class ostringstream: public ostrstream
127 {
128 public:
129   typedef ostrstream Superclass;
130   ostringstream() {}
131   ostringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
132   kwsys_stl::string str()
133     {
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);
139     }
140   void str(const kwsys_stl::string& s)
141     {
142     this->~ostringstream();
143     new (this) ostringstream(s);
144     }
145 private:
146   ostringstream(const ostringstream&);
147   void operator=(const ostringstream&);
148 };
149
150 #if defined(_MSC_VER)
151 # pragma warning (push)
152 # pragma warning (disable: 4097) /* typedef-name used as synonym for class */
153 #endif
154 #if defined(__WATCOMC__)
155 // W728: class modifiers for 'A' conflict with class modifiers for 'B'
156 # pragma warning 728 10
157 #endif
158
159 class istringstream: private kwsys_stl::string, public istrstream
160 {
161 public:
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)
170     {
171     this->~istringstream();
172     new (this) istringstream(s);
173     }
174   void clear(int flags)
175     {
176     this->IStrStream::clear(flags);
177     }
178 private:
179   istringstream(const istringstream&);
180   void operator=(const istringstream&);
181 };
182
183 #if defined(__WATCOMC__)
184 # pragma warning 728 9
185 #endif
186 #if defined(_MSC_VER)
187 # pragma warning (pop)
188 #endif
189
190 } // namespace @KWSYS_NAMESPACE@_ios
191
192 #endif
193
194 /* Undefine temporary macro.  */
195 #if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
196 # undef kwsys_stl
197 #endif
198
199 #endif