|
// (C) Copyright Gennadiy Rozental 2002.
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.
// See http://www.boost.org for most recent version including documentation.
//
// File : $RCSfile: wrap_stringstream.hpp,v $
//
// Version : $Id: wrap_stringstream.hpp,v 1.2 2003/02/13 08:05:29 rogeeff Exp $
//
// Description : wraps strstream and stringstream (depends with one is present )
// to prodive the unified interface
// ***************************************************************************
#ifndef BOOST_WRAP_STRINGSTREAM_HPP
#define BOOST_WRAP_STRINGSTREAM_HPP
// STL
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream> // for std::ostrstream
#else
#include <sstream> // for std::ostringstream
#endif // BOOST_NO_STRINGSTREAM
#include <string> // std::string
namespace boost {
// ************************************************************************** //
// ************** wrap_stringstream ************** //
// ************************************************************************** //
class wrap_stringstream {
#ifdef BOOST_NO_STRINGSTREAM
typedef std::ostrstream wrapped_stream;
#else
typedef std::ostringstream wrapped_stream;
#endif // BOOST_NO_STRINGSTREAM
public:
// access methods
wrap_stringstream& ref();
wrapped_stream& stream();
std::string const& str();
private:
// Data members
wrapped_stream m_stream;
std::string m_str;
};
//____________________________________________________________________________//
template <class T>
wrap_stringstream&
operator<<( wrap_stringstream& targ, T const& t )
{
targ.stream() << t;
return targ;
}
//____________________________________________________________________________//
inline wrap_stringstream::wrapped_stream&
wrap_stringstream::stream()
{
return m_stream;
}
//____________________________________________________________________________//
inline wrap_stringstream&
wrap_stringstream::ref()
{
return *this;
}
//____________________________________________________________________________//
inline wrap_stringstream&
operator<<( wrap_stringstream& targ, wrap_stringstream& src )
{
targ << src.str();
return targ;
}
//____________________________________________________________________________//
inline std::string const&
wrap_stringstream::str()
{
#ifdef BOOST_NO_STRINGSTREAM
m_str.assign( m_stream.str(), m_stream.pcount() );
m_stream.freeze( false );
#else
m_str = m_stream.str();
#endif
return m_str;
}
//____________________________________________________________________________//
} // namespace boost
#endif // BOOST_WRAP_STRINGSTREAM_HPP
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Mr. Shah is a reclusive C++/C# developer lurking somewhere in the depths of the city of London. He learnt physics at Kings' College London and obtained a Master in Science there. Having earned an MCAD, he teeters on the brink of transitioning from C++ to C#, unsure of which language to jump to. Fortunately, he also knows how to use .NET interop to merge code between the two languages (which means he won't have to make the choice anytime soon).
His interests (apart from programming) are walking, football (the real one!), philosophy, history, retro-gaming, strategy gaming, and any good game in general.
He maintains a website / blog / FAQ / junk at shexec32.serveftp.net, where he places the best answers he's written to the questions you've asked. If you can find him, maybe you can hire Mr. Shah to help you with anything C++[/CLI]/C#/.NET related
.