// sstream standard header
#ifndef _SSTREAM_
#define _SSTREAM_
#include <string>
_STD_BEGIN
export
		// TEMPLATE CLASS basic_stringbuf
template<class _Elem,
	class _Traits,
	class _Alloc>
	class basic_stringbuf
		: public basic_streambuf<_Elem, _Traits>
	{	// stream buffer maintaining an allocated character array
public:
	typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Myt;
	typedef _Alloc allocator_type;
	typedef basic_streambuf<_Elem, _Traits> _Mysb;
	typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;

	explicit basic_stringbuf(ios_base::openmode _Mode =
		ios_base::in | ios_base::out)
		{	// construct empty character buffer from mode
		_Init(0, 0, _Getstate(_Mode));
		}

	explicit basic_stringbuf(const _Mystr& _Str,
		ios_base::openmode _Mode = ios_base::in | ios_base::out)
		{	// construct character buffer from string, mode
		_Init(_Str.c_str(), _Str.size(), _Getstate(_Mode));
		}

 #if _HAS_RVALUE_REFERENCES
	basic_stringbuf(_Myt&& _Right)
		{	// construct by moving _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}

	_Myt& operator=(_Myt&& _Right)
		{	// assign from _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		return (*this);
		}

	void _Assign_rv(_Myt&& _Right)
		{	// assign by moving _Right
		if (this != &_Right)
			{	// different, worth moving
			_Tidy();
			this->swap(_Right);
			}
		}

	void swap(_Myt& _Right)
		{	// swap with _Right
		if (this != &_Right)
			{	// different, worth swapping
			_Mysb::swap(_Right);
			_STD swap(_Seekhigh, _Right._Seekhigh);
			_STD swap(_Mystate, _Right._Mystate);
			_Swap_adl(_Al, _Right._Al);
			}
		}

	void swap(_Myt&& _Right)
		{	// swap with _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}
 #endif /* _HAS_RVALUE_REFERENCES */

	virtual ~basic_stringbuf()
		{	// destroy the object
		_Tidy();
		}

	enum
		{	// constants for bits in stream state
		_Allocated = 1,	// set if character array storage has been allocated
		_Constant = 2,	// set if character array nonmutable
		_Noread = 4,	// set if character array cannot be read
		_Append = 8,	// set if all writes are appends
		_Atend = 16};	// set if initial writes are appends
	typedef int _Strstate;

	typedef typename _Traits::int_type int_type;
	typedef typename _Traits::pos_type pos_type;
	typedef typename _Traits::off_type off_type;

	_Mystr str() const;

	void str(const _Mystr& _Newstr)
		{	// replace character array from string
		_Tidy();
		_Init(_Newstr.c_str(), _Newstr.size(), _Mystate);
		}

protected:
	virtual int_type overflow(int_type _Meta = _Traits::eof());

	virtual int_type pbackfail(int_type _Meta = _Traits::eof());

	virtual int_type underflow();

	virtual pos_type seekoff(off_type _Off,
		ios_base::seekdir _Way,
		ios_base::openmode _Which = ios_base::in | ios_base::out);

	virtual pos_type seekpos(pos_type _Ptr,
		ios_base::openmode _Mode = ios_base::in | ios_base::out);

	void _Init(const _Elem *_Ptr,
		size_t _Count, _Strstate _State);

	void _Tidy();

private:
	enum
		{	// constant for minimum buffer size
		_MINSIZE = 32};

	_Strstate _Getstate(ios_base::openmode _Mode)
		{	// convert open mode to stream state bits
		_Strstate _State = (_Strstate)0;
		if (!(_Mode & ios_base::in))
			_State |= _Noread;
		if (!(_Mode & ios_base::out))
			_State |= _Constant;
		if (_Mode & ios_base::app)
			_State |= _Append;
		if (_Mode & ios_base::ate)
			_State |= _Atend;
		return (_State);
		}

	_Elem *_Seekhigh;	// the high-water pointer in character array
	_Strstate _Mystate;	// the stream state
	allocator_type _Al;	// the allocator object
	};

 #if _HAS_RVALUE_REFERENCES
	// basic_stringbuf TEMPLATE OPERATORS
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_stringbuf<_Elem, _Traits, _Alloc>& _Left,
		basic_stringbuf<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_stringbufs
	_Left.swap(_Right);
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_stringbuf<_Elem, _Traits, _Alloc>& _Left,
		basic_stringbuf<_Elem, _Traits, _Alloc>&& _Right)
	{	// swap _Left and _Right basic_stringbufs
	typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Myt;
	_Left.swap(_STD forward<_Myt>(_Right));
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_stringbuf<_Elem, _Traits, _Alloc>&& _Left,
		basic_stringbuf<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_stringbufs
	typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Myt;
	_Right.swap(_STD forward<_Myt>(_Left));
	}
 #endif /* _HAS_RVALUE_REFERENCES */

		// TEMPLATE CLASS basic_istringstream
template<class _Elem,
	class _Traits,
	class _Alloc>
	class basic_istringstream
		: public basic_istream<_Elem, _Traits>
	{	// input stream associated with a character array
public:
	typedef basic_istringstream<_Elem, _Traits, _Alloc> _Myt;
	typedef basic_istream<_Elem, _Traits> _Mybase;
	typedef _Alloc allocator_type;
	typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb;
	typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;

	explicit basic_istringstream(ios_base::openmode _Mode = ios_base::in)
		: _Mybase(&_Stringbuffer),
			_Stringbuffer(_Mode | ios_base::in)
		{	// construct empty readable character buffer
		}

	explicit basic_istringstream(const _Mystr& _Str,
		ios_base::openmode _Mode = ios_base::in)
		: _Mybase(&_Stringbuffer),
			_Stringbuffer(_Str, _Mode | ios_base::in)
		{	// construct readable character buffer from NTCS
		}

 #if _HAS_RVALUE_REFERENCES
	basic_istringstream(_Myt&& _Right)
		: _Mybase(&_Stringbuffer)
		{	// construct by moving _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}

	_Myt& operator=(_Myt&& _Right)
		{	// move from _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		return (*this);
		}

	void _Assign_rv(_Myt&& _Right)
		{	// assign by moving _Right
		if (this != &_Right)
			{	// different, worth moving
			_Stringbuffer.str(_Mystr());
			this->swap(_Right);
			}
		}

	void swap(_Myt& _Right)
		{	// swap with _Right
		if (this != &_Right)
			{	// different, swap base and buffer
			_Mybase::swap(_Right);
			_Stringbuffer.swap(_Right._Stringbuffer);
			}
		}

	void swap(_Myt&& _Right)
		{	// swap with _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}
 #endif /* _HAS_RVALUE_REFERENCES */

	virtual ~basic_istringstream()
		{	// destroy the object
		}

	_Mysb *rdbuf() const
		{	// return pointer to file buffer
		return ((_Mysb *)&_Stringbuffer);
		}

	_Mystr str() const
		{	// return string copy of character array
		return (_Stringbuffer.str());
		}

	void str(const _Mystr& _Newstr)
		{	// replace character array from string
		_Stringbuffer.str(_Newstr);
		}

private:
	_Mysb _Stringbuffer;	// the string buffer
	};

 #if _HAS_RVALUE_REFERENCES
	// basic_istringstream TEMPLATE OPERATORS
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_istringstream<_Elem, _Traits, _Alloc>& _Left,
		basic_istringstream<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_istringstreams
	_Left.swap(_Right);
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_istringstream<_Elem, _Traits, _Alloc>& _Left,
		basic_istringstream<_Elem, _Traits, _Alloc>&& _Right)
	{	// swap _Left and _Right basic_istringstreams
	typedef basic_istringstream<_Elem, _Traits, _Alloc> _Myt;
	_Left.swap(_STD forward<_Myt>(_Right));
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_istringstream<_Elem, _Traits, _Alloc>&& _Left,
		basic_istringstream<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_istringstreams
	typedef basic_istringstream<_Elem, _Traits> _Myt;
	_Right.swap(_STD forward<_Myt>(_Left));
	}
 #endif /* _HAS_RVALUE_REFERENCES */

		// TEMPLATE CLASS basic_ostringstream
template<class _Elem,
	class _Traits,
	class _Alloc>
	class basic_ostringstream
		: public basic_ostream<_Elem, _Traits>
	{	// output stream associated with a character array
public:
	typedef basic_ostringstream<_Elem, _Traits, _Alloc> _Myt;
	typedef basic_ostream<_Elem, _Traits> _Mybase;
	typedef _Alloc allocator_type;
	typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb;
	typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;

	explicit basic_ostringstream(ios_base::openmode _Mode = ios_base::out)
		: _Mybase(&_Stringbuffer),
			_Stringbuffer(_Mode | ios_base::out)
		{	// construct empty writable character buffer
		}

	explicit basic_ostringstream(const _Mystr& _Str,
		ios_base::openmode _Mode = ios_base::out)
		: _Mybase(&_Stringbuffer),
			_Stringbuffer(_Str, _Mode | ios_base::out)
		{	// construct writable character buffer from NTCS
		}

 #if _HAS_RVALUE_REFERENCES
	basic_ostringstream(_Myt&& _Right)
		: _Mybase(&_Stringbuffer)
		{	// construct by moving _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}

	_Myt& operator=(_Myt&& _Right)
		{	// move from _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		return (*this);
		}

	void _Assign_rv(_Myt&& _Right)
		{	// assign by moving _Right
		if (this != &_Right)
			{	// different, worth moving
			_Stringbuffer.str(_Mystr());
			this->swap(_Right);
			}
		}

	void swap(_Myt& _Right)
		{	// swap with _Right
		if (this != &_Right)
			{	// different, swap base and buffer
			_Mybase::swap(_Right);
			_Stringbuffer.swap(_Right._Stringbuffer);
			}
		}

	void swap(_Myt&& _Right)
		{	// swap with _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}
 #endif /* _HAS_RVALUE_REFERENCES */

	virtual ~basic_ostringstream()
		{	// destroy the object
		}

	_Mysb *rdbuf() const
		{	// return pointer to buffer
		return ((_Mysb *)&_Stringbuffer);
		}

	_Mystr str() const
		{	// return string copy of character array
		return (_Stringbuffer.str());
		}

	void str(const _Mystr& _Newstr)
		{	// replace character array from string
		_Stringbuffer.str(_Newstr);
		}

private:
	_Mysb _Stringbuffer;	// the string buffer
	};

 #if _HAS_RVALUE_REFERENCES
	// basic_ostringstream TEMPLATE OPERATORS
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_ostringstream<_Elem, _Traits, _Alloc>& _Left,
		basic_ostringstream<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_ostringstreams
	_Left.swap(_Right);
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_ostringstream<_Elem, _Traits, _Alloc>& _Left,
		basic_ostringstream<_Elem, _Traits, _Alloc>&& _Right)
	{	// swap _Left and _Right basic_ostringstreams
	typedef basic_ostringstream<_Elem, _Traits, _Alloc> _Myt;
	_Left.swap(_STD forward<_Myt>(_Right));
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_ostringstream<_Elem, _Traits, _Alloc>&& _Left,
		basic_ostringstream<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_ostringstreams
	typedef basic_ostringstream<_Elem, _Traits> _Myt;
	_Right.swap(_STD forward<_Myt>(_Left));
	}
 #endif /* _HAS_RVALUE_REFERENCES */

		// TEMPLATE CLASS basic_stringstream
template<class _Elem,
	class _Traits,
	class _Alloc>
	class basic_stringstream
		: public basic_iostream<_Elem, _Traits>
	{	// input/output stream associated with a character array
public:
	typedef basic_stringstream<_Elem, _Traits, _Alloc> _Myt;
	typedef basic_iostream<_Elem, _Traits> _Mybase;
	typedef _Elem char_type;
	typedef _Traits traits_type;
	typedef _Alloc allocator_type;
	typedef typename _Traits::int_type int_type;
	typedef typename _Traits::pos_type pos_type;
	typedef typename _Traits::off_type off_type;
	typedef basic_stringbuf<_Elem, _Traits, _Alloc> _Mysb;
	typedef basic_string<_Elem, _Traits, _Alloc> _Mystr;

	explicit basic_stringstream(ios_base::openmode _Mode =
		ios_base::in | ios_base::out)
		: _Mybase(&_Stringbuffer),
			_Stringbuffer(_Mode)
		{	// construct empty character buffer
		}

	explicit basic_stringstream(const _Mystr& _Str,
		ios_base::openmode _Mode = ios_base::in | ios_base::out)
		: _Mybase(&_Stringbuffer),
			_Stringbuffer(_Str, _Mode)
		{	// construct character buffer from NTCS
		}

 #if _HAS_RVALUE_REFERENCES
	basic_stringstream(_Myt&& _Right)
		: _Mybase(&_Stringbuffer)
		{	// construct by moving _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}

	_Myt& operator=(_Myt&& _Right)
		{	// move from _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		return (*this);
		}

	void _Assign_rv(_Myt&& _Right)
		{	// assign by moving _Right
		if (this != &_Right)
			{	// different, worth moving
			_Stringbuffer.str(_Mystr());
			this->swap(_Right);
			}
		}

	void swap(_Myt& _Right)
		{	// swap with _Right
		if (this != &_Right)
			{	// different, swap base and buffer
			_Mybase::swap(_Right);
			_Stringbuffer.swap(_Right._Stringbuffer);
			}
		}

	void swap(_Myt&& _Right)
		{	// swap with _Right
		_Assign_rv(_STD forward<_Myt>(_Right));
		}
 #endif /* _HAS_RVALUE_REFERENCES */

	virtual ~basic_stringstream()
		{	// destroy the object
		}

	_Mysb *rdbuf() const
		{	// return pointer to buffer
		return ((_Mysb *)&_Stringbuffer);
		}

	_Mystr str() const
		{	// return string copy of character array
		return (_Stringbuffer.str());
		}

	void str(const _Mystr& _Newstr)
		{	// replace character array from string
		_Stringbuffer.str(_Newstr);
		}

private:
	_Mysb _Stringbuffer;	// the string buffer
	};

 #if _HAS_RVALUE_REFERENCES
	// basic_stringstream TEMPLATE OPERATORS
template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_stringstream<_Elem, _Traits, _Alloc>& _Left,
		basic_stringstream<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_stringstreams
	_Left.swap(_Right);
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_stringstream<_Elem, _Traits, _Alloc>& _Left,
		basic_stringstream<_Elem, _Traits, _Alloc>&& _Right)
	{	// swap _Left and _Right basic_stringstreams
	typedef basic_stringstream<_Elem, _Traits, _Alloc> _Myt;
	_Left.swap(_STD forward<_Myt>(_Right));
	}

template<class _Elem,
	class _Traits,
	class _Alloc> inline
	void swap(basic_stringstream<_Elem, _Traits, _Alloc>&& _Left,
		basic_stringstream<_Elem, _Traits, _Alloc>& _Right)
	{	// swap _Left and _Right basic_stringstreams
	typedef basic_ostringstream<_Elem, _Traits> _Myt;
	_Right.swap(_STD forward<_Myt>(_Left));
	}
 #endif /* _HAS_RVALUE_REFERENCES */
_STD_END
#endif /* _SSTREAM_ */

/*
 * Copyright (c) 1992-2010 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.30:0009 */
