2009-09-28 19:37:35 +04:00
|
|
|
/*============================================================================
|
|
|
|
KWSys - Kitware System Library
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2003-12-23 19:03:33 +03:00
|
|
|
|
2009-09-28 19:37:35 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2003-12-23 19:03:33 +03:00
|
|
|
|
2009-09-28 19:37:35 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2003-12-23 19:03:33 +03:00
|
|
|
#ifndef @KWSYS_NAMESPACE@_ios_sstream
|
|
|
|
#define @KWSYS_NAMESPACE@_ios_sstream
|
|
|
|
|
|
|
|
#include <@KWSYS_NAMESPACE@/Configure.hxx>
|
|
|
|
|
|
|
|
/* Define this macro temporarily to keep the code readable. */
|
|
|
|
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
|
|
|
|
# define kwsys_stl @KWSYS_NAMESPACE@_stl
|
|
|
|
#endif
|
|
|
|
|
2003-12-31 01:15:51 +03:00
|
|
|
#if @KWSYS_NAMESPACE@_IOS_USE_SSTREAM
|
2003-12-23 19:03:33 +03:00
|
|
|
# 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)
|
2004-12-01 15:28:13 +03:00
|
|
|
# pragma warning (disable: 4995) /* Old streams are deprecated. */
|
2003-12-23 19:03:33 +03:00
|
|
|
# endif
|
2003-12-31 01:15:51 +03:00
|
|
|
# if @KWSYS_NAMESPACE@_IOS_USE_ANSI
|
2003-12-23 19:03:33 +03:00
|
|
|
# include <strstream>
|
2003-12-31 01:15:51 +03:00
|
|
|
# elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREAM_H
|
2003-12-23 19:03:33 +03:00
|
|
|
# include <strstream.h>
|
2003-12-31 01:15:51 +03:00
|
|
|
# elif @KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H
|
2003-12-23 19:03:33 +03:00
|
|
|
# include <strstrea.h>
|
|
|
|
# endif
|
2004-12-01 15:28:13 +03:00
|
|
|
# if @KWSYS_NAMESPACE@_IOS_USE_ANSI
|
|
|
|
# include <new> // Need placement operator new.
|
|
|
|
# else
|
|
|
|
# include <new.h> // Need placement operator new.
|
|
|
|
# endif
|
2003-12-23 19:03:33 +03:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
# pragma warning(pop)
|
|
|
|
# endif
|
|
|
|
|
2008-01-31 16:21:35 +03:00
|
|
|
// Only have old std strstream classes. Wrap them to look like new
|
2003-12-23 19:03:33 +03:00
|
|
|
// ostringstream and istringstream classes.
|
|
|
|
|
|
|
|
# include <@KWSYS_NAMESPACE@/stl/string>
|
|
|
|
|
|
|
|
namespace @KWSYS_NAMESPACE@_ios
|
|
|
|
{
|
2005-09-21 21:42:49 +04:00
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::streambuf;
|
2003-12-23 19:03:33 +03:00
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::ostream;
|
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::istream;
|
2006-12-14 21:18:27 +03:00
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::strstream;
|
2003-12-23 19:03:33 +03:00
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::istrstream;
|
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::ostrstream;
|
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::ios;
|
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::endl;
|
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::ends;
|
|
|
|
using @KWSYS_NAMESPACE@_ios_namespace::flush;
|
|
|
|
|
2006-12-14 21:18:27 +03:00
|
|
|
class stringstream_cleanup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
stringstream_cleanup(strstream& str): m_StrStream(str) {}
|
|
|
|
~stringstream_cleanup() { m_StrStream.rdbuf()->freeze(0); }
|
|
|
|
static void IgnoreUnusedVariable(const stringstream_cleanup&) {}
|
|
|
|
protected:
|
|
|
|
strstream& m_StrStream;
|
|
|
|
private:
|
|
|
|
void operator=(stringstream_cleanup const&);
|
|
|
|
};
|
|
|
|
|
|
|
|
class stringstream: public strstream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef strstream Superclass;
|
|
|
|
stringstream() {}
|
|
|
|
stringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
|
|
|
|
kwsys_stl::string str()
|
|
|
|
{
|
|
|
|
stringstream_cleanup cleanup(*this);
|
|
|
|
stringstream_cleanup::IgnoreUnusedVariable(cleanup);
|
2006-12-18 19:04:25 +03:00
|
|
|
// Visual Studio 6 has a strstream::pcount, but this is not rdbuf()->pcount()
|
|
|
|
#if (@KWSYS_NAMESPACE@_IOS_USE_STRSTREA_H) && defined(_MSC_VER) && (_MSC_VER == 1200)
|
|
|
|
int count = this->pcount();
|
2007-04-19 20:12:19 +04:00
|
|
|
#elif defined(__WATCOMC__)
|
|
|
|
int count = this->rdbuf()->out_waiting();
|
2006-12-18 19:04:25 +03:00
|
|
|
#else
|
2006-12-15 18:30:41 +03:00
|
|
|
int count = this->rdbuf()->pcount();
|
2006-12-18 19:04:25 +03:00
|
|
|
#endif
|
2006-12-14 21:18:27 +03:00
|
|
|
const char* ptr = this->Superclass::str();
|
|
|
|
return kwsys_stl::string(ptr?ptr:"", count);
|
|
|
|
}
|
|
|
|
void str(const kwsys_stl::string& s)
|
|
|
|
{
|
|
|
|
this->~stringstream();
|
|
|
|
new (this) stringstream(s);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
stringstream(const stringstream&);
|
|
|
|
void operator=(const stringstream&);
|
|
|
|
};
|
|
|
|
|
2003-12-23 19:03:33 +03:00
|
|
|
class ostringstream_cleanup
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ostringstream_cleanup(ostrstream& ostr): m_OStrStream(ostr) {}
|
|
|
|
~ostringstream_cleanup() { m_OStrStream.rdbuf()->freeze(0); }
|
|
|
|
static void IgnoreUnusedVariable(const ostringstream_cleanup&) {}
|
|
|
|
protected:
|
|
|
|
ostrstream& m_OStrStream;
|
2005-06-09 16:18:46 +04:00
|
|
|
private:
|
|
|
|
void operator=(ostringstream_cleanup const&);
|
2003-12-23 19:03:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ostringstream: public ostrstream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ostrstream Superclass;
|
|
|
|
ostringstream() {}
|
2005-03-03 20:00:43 +03:00
|
|
|
ostringstream(const kwsys_stl::string& s) { *this << s.c_str(); }
|
2003-12-23 19:03:33 +03:00
|
|
|
kwsys_stl::string str()
|
|
|
|
{
|
|
|
|
ostringstream_cleanup cleanup(*this);
|
|
|
|
ostringstream_cleanup::IgnoreUnusedVariable(cleanup);
|
2006-12-14 21:18:27 +03:00
|
|
|
int count = this->pcount();
|
2003-12-23 19:03:33 +03:00
|
|
|
const char* ptr = this->Superclass::str();
|
2006-12-14 21:18:27 +03:00
|
|
|
return kwsys_stl::string(ptr?ptr:"", count);
|
2003-12-23 19:03:33 +03:00
|
|
|
}
|
2005-03-03 20:00:43 +03:00
|
|
|
void str(const kwsys_stl::string& s)
|
|
|
|
{
|
|
|
|
this->~ostringstream();
|
|
|
|
new (this) ostringstream(s);
|
|
|
|
}
|
2003-12-23 19:03:33 +03:00
|
|
|
private:
|
|
|
|
ostringstream(const ostringstream&);
|
|
|
|
void operator=(const ostringstream&);
|
|
|
|
};
|
|
|
|
|
2005-06-09 16:18:46 +04:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# pragma warning (push)
|
|
|
|
# pragma warning (disable: 4097) /* typedef-name used as synonym for class */
|
|
|
|
#endif
|
2007-04-19 20:12:19 +04:00
|
|
|
#if defined(__WATCOMC__)
|
|
|
|
// W728: class modifiers for 'A' conflict with class modifiers for 'B'
|
|
|
|
# pragma warning 728 10
|
|
|
|
#endif
|
2005-06-09 16:18:46 +04:00
|
|
|
|
2003-12-23 19:03:33 +03:00
|
|
|
class istringstream: private kwsys_stl::string, public istrstream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef kwsys_stl::string StdString;
|
|
|
|
typedef istrstream IStrStream;
|
|
|
|
istringstream(): StdString(),
|
|
|
|
IStrStream(const_cast<char*>(StdString::c_str())) {}
|
|
|
|
istringstream(const kwsys_stl::string& s):
|
|
|
|
StdString(s), IStrStream(const_cast<char*>(StdString::c_str())) {}
|
|
|
|
kwsys_stl::string str() const { return *this; }
|
|
|
|
void str(const kwsys_stl::string& s)
|
|
|
|
{
|
|
|
|
this->~istringstream();
|
|
|
|
new (this) istringstream(s);
|
|
|
|
}
|
2007-04-20 17:50:46 +04:00
|
|
|
void clear(int flags)
|
|
|
|
{
|
|
|
|
this->IStrStream::clear(flags);
|
|
|
|
}
|
2003-12-23 19:03:33 +03:00
|
|
|
private:
|
|
|
|
istringstream(const istringstream&);
|
|
|
|
void operator=(const istringstream&);
|
|
|
|
};
|
|
|
|
|
2007-04-19 20:12:19 +04:00
|
|
|
#if defined(__WATCOMC__)
|
|
|
|
# pragma warning 728 9
|
|
|
|
#endif
|
2005-06-09 16:18:46 +04:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
# pragma warning (pop)
|
|
|
|
#endif
|
|
|
|
|
2003-12-23 19:03:33 +03:00
|
|
|
} // namespace @KWSYS_NAMESPACE@_ios
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Undefine temporary macro. */
|
|
|
|
#if !defined (KWSYS_NAMESPACE) && !@KWSYS_NAMESPACE@_NAME_IS_KWSYS
|
|
|
|
# undef kwsys_stl
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|