summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/kwsys_std_sstream.h.in
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2003-05-12 17:15:49 (GMT)
committerBrad King <brad.king@kitware.com>2003-05-12 17:15:49 (GMT)
commitb910480e32088f6ec5eebeeef9d42491ef523790 (patch)
tree8dc4c2589a285d03577be85143af8e85885887e5 /Source/kwsys/kwsys_std_sstream.h.in
parent395fae76420230bda51d74fbd45b1eb0f797f854 (diff)
downloadCMake-b910480e32088f6ec5eebeeef9d42491ef523790.zip
CMake-b910480e32088f6ec5eebeeef9d42491ef523790.tar.gz
CMake-b910480e32088f6ec5eebeeef9d42491ef523790.tar.bz2
ENH: Added wrappers around the std stream headers to make them look like ansi streams on all platforms.
Diffstat (limited to 'Source/kwsys/kwsys_std_sstream.h.in')
-rw-r--r--Source/kwsys/kwsys_std_sstream.h.in125
1 files changed, 125 insertions, 0 deletions
diff --git a/Source/kwsys/kwsys_std_sstream.h.in b/Source/kwsys/kwsys_std_sstream.h.in
new file mode 100644
index 0000000..3bd32af
--- /dev/null
+++ b/Source/kwsys/kwsys_std_sstream.h.in
@@ -0,0 +1,125 @@
+/*=========================================================================
+
+ Program: KWSys - Kitware System Library
+ Module: $RCSfile$
+ Language: C++
+ Date: $Date$
+ Version: $Revision$
+
+ Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
+ See http://www.cmake.org/HTML/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notices for more information.
+
+=========================================================================*/
+#ifndef @KWSYS_NAMESPACE@_std_sstream
+#define @KWSYS_NAMESPACE@_std_sstream
+
+#include <@KWSYS_NAMESPACE@/Configure.hxx>
+
+#if !defined(KWSYS_NO_ANSI_STRING_STREAM)
+# ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# endif
+# include <sstream>
+# ifdef _MSC_VER
+# pragma warning(pop)
+# endif
+#else
+# ifdef _MSC_VER
+# pragma warning (push, 1)
+# pragma warning (disable: 4702)
+# endif
+# if !defined(KWSYS_NO_ANSI_STREAM_HEADERS)
+# include <strstream>
+# else
+# include <strstream.h>
+# if !defined(KWSYS_NO_STD_NAMESPACE)
+
+namespace std
+{
+ using ::ostream;
+ using ::istream;
+ using ::istrstream;
+ using ::ostrstream;
+ using ::ios;
+ using ::endl;
+ using ::ends;
+ using ::flush;
+}
+
+# endif
+# endif
+# ifdef _MSC_VER
+# pragma warning(pop)
+# endif
+
+// Only have old std::strstream classes. Wrap them to look like new
+// ostringstream and istringstream classes.
+
+# include <@KWSYS_NAMESPACE@/std/string>
+
+# if !defined(KWSYS_NO_STD_NAMESPACE)
+namespace std
+{
+# endif
+
+class ostringstream_cleanup
+{
+public:
+ ostringstream_cleanup(kwsys_std::ostrstream& ostr): m_OStrStream(ostr) {}
+ ~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
+ static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
+protected:
+ kwsys_std::ostrstream& m_OStrStream;
+};
+
+class ostringstream: public kwsys_std::ostrstream
+{
+public:
+ typedef kwsys_std::ostrstream Superclass;
+ ostringstream() {}
+ kwsys_std::string str()
+ {
+ ostringstream_cleanup cleanup(*this);
+ ostringstream_cleanup::IgnoreUnusedVariable(cleanup);
+ int pcount = this->pcount();
+ const char* ptr = this->Superclass::str();
+ return kwsys_std::string(ptr?ptr:"", pcount);
+ }
+private:
+ ostringstream(const ostringstream&);
+ void operator=(const ostringstream&);
+};
+
+class istringstream: private kwsys_std::string, public kwsys_std::istrstream
+{
+public:
+ typedef kwsys_std::string StdString;
+ typedef kwsys_std::istrstream IStrStream;
+ istringstream(): StdString(), IStrStream(StdString::c_str()) {}
+ istringstream(const kwsys_std::string& s):
+ StdString(s), IStrStream(StdString::c_str()) {}
+ kwsys_std::string str() const { return *this; }
+ void str(const kwsys_std::string& s)
+ {
+ // Very dangerous. If this throws, the object is hosed. When the
+ // destructor is later called, the program is hosed too.
+ this->~istringstream();
+ new (this) istringstream(s);
+ }
+private:
+ istringstream(const istringstream&);
+ void operator=(const istringstream&);
+};
+
+# if !defined(KWSYS_NO_STD_NAMESPACE)
+}
+# endif
+
+#endif
+
+#endif