// istream standard header
#ifndef _ISTREAM_
#define _ISTREAM_

#pragma info(none)
#ifndef __CHKHDR__
#  pragma report(level, E)
#endif
#pragma info(restore)

#if __IBMCPP__ < 400
#error This file to be used only with IBM VisualAge C++ v4 and later compilers.
#endif /* __IBMCPP__ */

#pragma namemangling(ansi)

   /********************************************************************/
   /*  <istream> header file                                           */
   /*                                                                  */
   /*  VisualAge C++, Version 4.0                                      */
   /*    Licensed Material - Property of IBM                           */
   /*                                                                  */
   /*  5801-AAR and Other Materials                                    */
   /*                                                                  */
   /*  (c) Copyright IBM Corp 1991, 1998. All rights reserved.         */
   /*                                                                  */
   /*                                                                  */
   /*  Licensed Materials.                                             */
   /*                                                                  */
   /*  Dinkum C++ Library                                              */
   /*  Copyright (c) 1998.  Licensed to IBM Corp. and its suppliers.   */
   /*                                                                  */
   /********************************************************************/

#include <ostream>
_STD_BEGIN
		// TEMPLATE CLASS basic_istream
template<class _E, class _Tr>
	class basic_istream : virtual public basic_ios<_E, _Tr> {
public:
	typedef basic_istream<_E, _Tr> _Myt;
	typedef basic_ios<_E, _Tr> _Myios;
	typedef basic_streambuf<_E, _Tr> _Mysb;
	typedef istreambuf_iterator<_E, _Tr> _Iter;
	typedef ctype<_E> _Ctype;
	typedef num_get<_E, _Iter> _Nget;
	explicit basic_istream(_Mysb *_S, bool _Isstd = false,
		bool _Noinit = false)
		: _Chcount(0)
		{if (!_Noinit)
			_Myios::init(_S, _Isstd); }
	basic_istream(_Uninitialized)
		{ios_base::_Addstd(); }
	virtual ~basic_istream()
		{}
	typedef typename _Tr::int_type int_type;
	typedef typename _Tr::pos_type pos_type;
	typedef typename _Tr::off_type off_type;
	class sentry {
	public:
		explicit sentry(_Myt& _Is, bool _Noskip = false)
			: _Lk(_LOCK_STREAM), _Ok(_Is.ipfx(_Noskip))
			{}
		operator bool() const
			{return (_Ok); }
	private:
		sentry(const sentry&);	// not defined
		sentry& operator=(const sentry&);	// not defined
		bool _Ok;
		_Lockit _Lk;
		};
	bool ipfx(bool _Noskip = false)
		{if (ios_base::good())
			{if (_Myios::tie() != 0)
				_Myios::tie()->flush();
			if (!_Noskip && ios_base::flags() & ios_base::skipws)
				{const _Ctype& _Fac =
					_USE(ios_base::getloc(), _Ctype);
				_TRY_IO_BEGIN
				int_type _C = _Myios::rdbuf()->sgetc();
				for (; ; _C = _Myios::rdbuf()->snextc())
					if (_Tr::eq_int_type(_Tr::eof(), _C))
						{_Myios::setstate(ios_base::eofbit);
						break; }
					else if (!_Fac.is(_Ctype::space,
						_Tr::to_char_type(_C)))
						break;
				_CATCH_IO_END }
			if (ios_base::good())
				return (true); }
		_Myios::setstate(ios_base::failbit);
		return (false); }
	void isfx()
		{}
	_Myt& operator>>(_Myt& (*_F)(_Myt&))
		{return ((*_F)(*this)); }
	_Myt& operator>>(_Myios& (*_F)(_Myios&))
		{(*_F)(*(_Myios *)this);
		return (*this); }
	_Myt& operator>>(ios_base& (*_F)(ios_base&))
		{(*_F)(*(ios_base *)this);
		return (*this); }
	_Myt& operator>>(_Bool& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(short& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{long _Y;
			const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _Y);
			_CATCH_IO_END
			if (_St & ios_base::failbit
				|| _Y < SHRT_MIN || SHRT_MAX < _Y)
				_St |= ios_base::failbit;
			else
				_X = _Y; }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(unsigned short& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(int& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{long _Y;
			const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _Y);
			_CATCH_IO_END
			if (_St & ios_base::failbit
				|| _Y < INT_MIN || INT_MAX < _Y)
				_St |= ios_base::failbit;
			else
				_X = _Y; }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(unsigned int& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(long& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(unsigned long& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(float& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(double& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(long double& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(void *& _X)
		{ios_base::iostate _St = ios_base::goodbit;
		const sentry _Ok(*this);
		if (_Ok)
			{const _Nget& _Fac = _USE(ios_base::getloc(), _Nget);
			_TRY_IO_BEGIN
			_Fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
				*this, _St, _X);
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& operator>>(_Mysb *_Pb)
		{ios_base::iostate _St = ios_base::goodbit;
		bool _Copied = false;
		const sentry _Ok(*this);
		if (_Ok && _Pb != 0)
			{_TRY_IO_BEGIN
			int_type _C = _Myios::rdbuf()->sgetc();
			for (; ; _C = _Myios::rdbuf()->snextc())
				if (_Tr::eq_int_type(_Tr::eof(), _C))
					{_St |= ios_base::eofbit;
					break; }
				else
					{_TRY_BEGIN
						if (_Tr::eq_int_type(_Tr::eof(),
							_Pb->sputc(_Tr::to_char_type(_C))))
							break;
					_CATCH_ALL
						break;
					_CATCH_END
					_Copied = true; }
			_CATCH_IO_END }
		_Myios::setstate(!_Copied
			? _St | ios_base::failbit : _St);
		return (*this); }
	int_type get()
		{int_type _C;
		ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (!_Ok)
			_C = _Tr::eof();
		else
			{_TRY_IO_BEGIN
			_C = _Myios::rdbuf()->sbumpc();
			if (_Tr::eq_int_type(_Tr::eof(), _C))
				_St |= ios_base::eofbit | ios_base::failbit;
			else
				++_Chcount;
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (_C); }
	_Myt& get(_E *_S, streamsize _N)
		{return (get(_S, _N, _Myios::widen('\n'))); }
	_Myt& get(_E *_S, streamsize _N, _E _D)
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok && 0 < _N)
			{_TRY_IO_BEGIN
			int_type _C = _Myios::rdbuf()->sgetc();
			for (; 0 < --_N; _C = _Myios::rdbuf()->snextc())
				if (_Tr::eq_int_type(_Tr::eof(), _C))
					{_St |= ios_base::eofbit;
					break; }
				else if (_Tr::to_char_type(_C) == _D)
					break;
				else
					*_S++ = _Tr::to_char_type(_C), ++_Chcount;
			_CATCH_IO_END }
		_Myios::setstate(_Chcount == 0
			? _St | ios_base::failbit : _St);
		*_S = _E();
		return (*this); }
	_Myt& get(_E& _X)
		{int_type _C = get();
		if (!_Tr::eq_int_type(_Tr::eof(), _C))
			_X = _Tr::to_char_type(_C);
		return (*this); }
	_Myt& get(_Mysb& _Sb)
		{return (get(_Sb, _Myios::widen('\n'))); }
	_Myt& get(_Mysb& _Sb, _E _D)
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok)
			{_TRY_IO_BEGIN
			int_type _C = _Myios::rdbuf()->sgetc();
			for (; ; _C = _Myios::rdbuf()->snextc())
				if (_Tr::eq_int_type(_Tr::eof(), _C))
					{_St |= ios_base::eofbit;
					break; }
				else
					{_TRY_BEGIN
						_E _Ch = _Tr::to_char_type(_C);
						if (_Ch == _D
							|| _Tr::eq_int_type(_Tr::eof(),
								_Sb.sputc(_Ch)))
							break;
					_CATCH_ALL
						break;
					_CATCH_END
					++_Chcount; }
			_CATCH_IO_END }
		if (_Chcount == 0)
			_St |= ios_base::failbit;
		_Myios::setstate(_St);
		return (*this); }
	_Myt& getline(_E *_S, streamsize _N)
		{return (getline(_S, _N, _Myios::widen('\n'))); }
	_Myt& getline(_E *_S, streamsize _N, _E _D)
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok && 0 < _N)
			{int_type _Di = _Tr::to_int_type(_D);
			_TRY_IO_BEGIN
			int_type _C = _Myios::rdbuf()->sgetc();
			for (; ; _C = _Myios::rdbuf()->snextc())
				if (_Tr::eq_int_type(_Tr::eof(), _C))
					{_St |= ios_base::eofbit;
					break; }
				else if (_C == _Di)
					{++_Chcount;
					_Myios::rdbuf()->sbumpc();
					break; }
				else if (--_N <= 0)
					{_St |= ios_base::failbit;
					break; }
				else
					{++_Chcount;
					*_S++ = _Tr::to_char_type(_C); }
			_CATCH_IO_END }
		*_S = _E();
		_Myios::setstate(_Chcount == 0
			? _St | ios_base::failbit : _St);
		return (*this); }
	_Myt& ignore(streamsize _N = 1, int_type _Di = _Tr::eof())
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok && 0 < _N)
			{_TRY_IO_BEGIN
			for (; ; )
				{int_type _C;
				if (_N != INT_MAX && --_N < 0)
					break;
				else if (_Tr::eq_int_type(_Tr::eof(),
					_C = _Myios::rdbuf()->sbumpc()))
					{_St |= ios_base::eofbit;
					break; }
				else
					{++_Chcount;
					if (_C == _Di)
						break; }}
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& read(_E *_S, streamsize _N)
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok)
			{_TRY_IO_BEGIN
			const streamsize _M = _Myios::rdbuf()->sgetn(_S, _N);
			_Chcount += _M;
			if (_M != _N)
				_St |= ios_base::eofbit | ios_base::failbit;
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	streamsize readsome(_E *_S, streamsize _N)
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		int _M;
		if (_Myios::rdbuf() == 0)
			_St |= ios_base::failbit;
		else if ((_M = _Myios::rdbuf()->in_avail()) < 0)
			_St |= ios_base::eofbit;
		else if (0 < _M)
			read(_S, _M < _N ? _M : _N);
		_Myios::setstate(_St);
		return (gcount()); }
	int_type peek()
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		int_type _C;
		const sentry _Ok(*this, true);
		if (!_Ok)
			_C = _Tr::eof();
		else
			{_TRY_IO_BEGIN
			if (_Tr::eq_int_type(_Tr::eof(),
				_C = _Myios::rdbuf()->sgetc()))
				_St |= ios_base::eofbit;
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (_C); }
	_Myt& putback(_E _X)
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok)
			{_TRY_IO_BEGIN
			if (_Tr::eq_int_type(_Tr::eof(),
				_Myios::rdbuf()->sputbackc(_X)))
				_St |= ios_base::badbit;
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	_Myt& unget()
		{ios_base::iostate _St = ios_base::goodbit;
		_Chcount = 0;
		const sentry _Ok(*this, true);
		if (_Ok)
			{_TRY_IO_BEGIN
			if (_Tr::eq_int_type(_Tr::eof(),
				_Myios::rdbuf()->sungetc()))
				_St |= ios_base::badbit;
			_CATCH_IO_END }
		_Myios::setstate(_St);
		return (*this); }
	streamsize gcount() const
		{return (_Chcount); }
	int sync()
		{ios_base::iostate _St = ios_base::goodbit;
		int _Ans;
		if (_Myios::rdbuf() == 0)
			_Ans = -1;
		else if (_Myios::rdbuf()->pubsync() == -1)
			_St |= ios_base::badbit, _Ans = -1;
		else
			_Ans = 0;
		_Myios::setstate(_St);
		return (_Ans); }
	_Myt& seekg(pos_type _P)
		{if (!ios_base::fail())
			_Myios::rdbuf()->pubseekpos(_P, ios_base::in);
		return (*this); }
	_Myt& seekg(off_type _O, ios_base::seekdir _W)
		{if (!ios_base::fail())
			_Myios::rdbuf()->pubseekoff(_O, _W, ios_base::in);
		return (*this); }
	pos_type tellg()
		{if (!ios_base::fail())
			return (_Myios::rdbuf()->pubseekoff(0,
				ios_base::cur, ios_base::in));
		else
			return (pos_type(_BADOFF)); }
private:
	streamsize _Chcount;
	};
		// TEMPLATE CLASS basic_iostream
template<class _E, class _Tr>
	class basic_iostream : public basic_istream<_E, _Tr>,
		public basic_ostream<_E, _Tr> {
public:
	explicit basic_iostream(basic_streambuf<_E, _Tr> *_S)
		: basic_istream<_E, _Tr>(_S, false, true),
			basic_ostream<_E, _Tr>(_S)
		{}
	virtual ~basic_iostream()
		{}
	};
		// EXTRACTORS
template<class _E, class _Tr> inline
	basic_istream<_E, _Tr>& operator>>(
		basic_istream<_E, _Tr>& _I, _E *_X)
	{typedef basic_istream<_E, _Tr> _Myis;
	typedef ctype<_E> _Ctype;
	ios_base::iostate _St = ios_base::goodbit;
	_E *_S = _X;
	const typename _Myis::sentry _Ok(_I);
	if (_Ok)
		{const _Ctype& _Fac = _USE(_I.getloc(), _Ctype);
		_TRY_IO_BEGIN
		int _N = 0 < _I.width() ? _I.width() : INT_MAX;
		typename _Myis::int_type _C = _I.rdbuf()->sgetc();
		for (; 0 < --_N; _C = _I.rdbuf()->snextc())
			if (_Tr::eq_int_type(_Tr::eof(), _C))
				{_St |= ios_base::eofbit;
				break; }
			else if (_Fac.is(_Ctype::space,
				_Tr::to_char_type(_C)))
				break;
			else
				*_S++ = _Tr::to_char_type(_C);
		_CATCH_IO_(_I) }
	*_S = _E();
	_I.width(0);
	_I.setstate(_S == _X ? _St | ios_base::failbit : _St);
	return (_I); }
template<class _E, class _Tr> inline
	basic_istream<_E, _Tr>& operator>>(
		basic_istream<_E, _Tr>& _I, _E& _X)
	{typedef basic_istream<_E, _Tr> _Myis;
	typename _Myis::int_type _C;
	ios_base::iostate _St = ios_base::goodbit;
	const typename _Myis::sentry _Ok(_I);
	if (_Ok)
		{_TRY_IO_BEGIN
		_C = _I.rdbuf()->sbumpc();
		if (_Tr::eq_int_type(_Tr::eof(), _C))
			_St |= ios_base::eofbit | ios_base::failbit;
		else
			_X = _Tr::to_char_type(_C);
		_CATCH_IO_(_I) }
	_I.setstate(_St);
	return (_I); }
template<class _Tr> inline
	basic_istream<char, _Tr>& operator>>(
		basic_istream<char, _Tr>& _I, signed char *_X)
	{return (_I >> (char *)_X); }
template<class _Tr> inline
	basic_istream<char, _Tr>& operator>>(
		basic_istream<char, _Tr>& _I, signed char& _C)
	{return (_I >> (char&)_C); }
template<class _Tr> inline
	basic_istream<char, _Tr>& operator>>(
		basic_istream<char, _Tr>& _I, unsigned char *_X)
	{return (_I >> (char *)_X); }
template<class _Tr> inline
	basic_istream<char, _Tr>& operator>>(
		basic_istream<char, _Tr>& _I, unsigned char& _C)
	{return (_I >> (char&)_C); }
		// MANIPULATORS
template<class _E, class _Tr> inline
	basic_istream<_E, _Tr>&
		ws(basic_istream<_E, _Tr>& _I)
	{typedef basic_istream<_E, _Tr> _Myis;
	typedef ctype<_E> _Ctype;
	ios_base::iostate _St = ios_base::goodbit;
	const typename _Myis::sentry _Ok(_I, true);
	if (_Ok)
		{const _Ctype& _Fac = _USE(_I.getloc(), _Ctype);
		_TRY_IO_BEGIN
		for (typename _Tr::int_type _C = _I.rdbuf()->sgetc(); ;
			_C = _I.rdbuf()->snextc())
			if (_Tr::eq_int_type(_Tr::eof(), _C))
				{_St |= ios_base::eofbit;
				break; }
			else if (!_Fac.is(_Ctype::space,
				_Tr::to_char_type(_C)))
				break;
		_CATCH_IO_(_I) }
	_I.setstate(_St);
	return (_I); }
_STD_END

#pragma namemangling()

#pragma info(none)
#ifndef __CHKHDR__
#  pragma report(pop)
#endif
#pragma info(restore)

#endif /* _ISTREAM_ */

/*
 * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
 * Consult your license regarding permissions and restrictions.
V2.2:0081 */
