home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / ios < prev    next >
Text File  |  1998-06-16  |  5KB  |  187 lines

  1. // ios standard header
  2.  
  3. #if     _MSC_VER > 1000 /*IFSTRIP=IGN*/
  4. #pragma once
  5. #endif
  6.  
  7. #ifndef _IOS_
  8. #define _IOS_
  9. #include <streambuf>
  10.  
  11. #ifdef  _MSC_VER
  12. #pragma pack(push,8)
  13. #endif  /* _MSC_VER */
  14. _STD_BEGIN
  15.         // TEMPLATE CLASS basic_ios
  16. template<class _E, class _Tr = char_traits<_E> >
  17.     class basic_ios : public ios_base {
  18. public:
  19.     typedef basic_ios<_E, _Tr> _Myt;
  20.     typedef basic_ostream<_E, _Tr> _Myos;
  21.     typedef basic_streambuf<_E, _Tr> _Mysb;
  22.     typedef ctype<_E> _Ctype;
  23.     explicit basic_ios(_Mysb *_S)
  24.         {init(_S); }
  25.     basic_ios(const _Myt& _R)
  26.         {init(0), *this = _R; }
  27.     virtual ~basic_ios()
  28.         {}
  29.     typedef _E char_type;
  30.     typedef _Tr traits_type;
  31.     typedef _Tr::int_type int_type;
  32.     typedef _Tr::pos_type pos_type;
  33.     typedef _Tr::off_type off_type;
  34.     void clear(iostate _St = goodbit, bool _Ex = false)
  35.         {ios_base::clear(_Sb == 0 ? (int)_St | (int)badbit
  36.             : (int)_St, _Ex); }
  37.     void clear(io_state _St)
  38.         {clear((iostate)_St); }
  39.     void setstate(iostate _St, bool _Ex = false)
  40.         {if (_St != goodbit)
  41.             clear((iostate)((int)rdstate() | (int)_St), _Ex); }
  42.     void setstate(io_state _St)
  43.         {setstate((iostate)_St); }
  44.     _Myt& copyfmt(const _Myt& _R)
  45.         {_Tiestr = _R.tie();
  46.         _Fillch = _R.fill();
  47.         ios_base::copyfmt(_R);
  48.         return (*this); }
  49.     _Myos *tie() const
  50.         {return (_Tiestr); }
  51.     _Myos *tie(_Myos *_N)
  52.         {_Myos *_O = _Tiestr;
  53.         _Tiestr = _N;
  54.         return (_O); }
  55.     _Mysb *rdbuf() const
  56.         {return (_Sb); }
  57.     _Mysb *rdbuf(_Mysb *_N)
  58.         {_Mysb *_O = _Sb;
  59.         _Sb = _N;
  60.         clear();
  61.         return (_O); }
  62.     locale imbue(const locale& _Ln)
  63.         {if (rdbuf() != 0)
  64.             rdbuf()->pubimbue(_Ln);
  65.         return (ios_base::imbue(_Ln)); }
  66.     _E fill() const
  67.         {return (_Fillch); }
  68.     _E fill(_E _Nf)
  69.         {_E _Of = _Fillch;
  70.         _Fillch = _Nf;
  71.         return (_Of); }
  72.     char narrow(_E _C, char _D = '\0') const
  73.         {const _Ctype& _Fac = _USE(getloc(), _Ctype);
  74.         return (_Fac.narrow(_C, _D)); }
  75.     _E widen(char _C) const
  76.         {const _Ctype& _Fac = _USE(getloc(), _Ctype);
  77.         return (_Fac.widen(_C)); }
  78. protected:
  79.     void init(_Mysb *_S = 0,
  80.         bool _Isstd = false)
  81.         {_Sb = _S;
  82.         _Tiestr = 0;
  83.         _Fillch = _WIDEN(_E, ' ');
  84.         _Init();
  85.         if (_Sb == 0)
  86.             setstate(badbit);
  87.         if (_Isstd)
  88.             _Addstd(); }
  89.     basic_ios()
  90.         {}
  91. private:
  92.     _Mysb *_Sb;
  93.     _Myos *_Tiestr;
  94.     _E _Fillch;
  95.     };
  96.  
  97. #ifdef _DLL
  98. #ifdef __FORCE_INSTANCE
  99. template class _CRTIMP2 basic_ios<char, char_traits<char> >;
  100. template class _CRTIMP2 basic_ios<wchar_t, char_traits<wchar_t> >;
  101. #else        // __FORCE_INSTANCE
  102. #pragma warning(disable:4231) /* the extern before template is a non-standard extension */
  103. extern template class _CRTIMP2 basic_ios<char, char_traits<char> >;
  104. extern template class _CRTIMP2 basic_ios<wchar_t, char_traits<wchar_t> >;
  105. #pragma warning(default:4231) /* restore previous warning */
  106. #endif        // __FORCE_INSTANCE
  107. #endif        // _DLL
  108.  
  109.         // MANIPULATORS
  110. inline ios_base& __cdecl boolalpha(ios_base& _I)
  111.     {_I.setf(ios_base::boolalpha);
  112.     return (_I); }
  113. inline ios_base& __cdecl dec(ios_base& _I)
  114.     {_I.setf(ios_base::dec, ios_base::basefield);
  115.     return (_I); }
  116. inline ios_base& __cdecl fixed(ios_base& _I)
  117.     {_I.setf(ios_base::fixed, ios_base::floatfield);
  118.     return (_I); }
  119. inline ios_base& __cdecl hex(ios_base& _I)
  120.     {_I.setf(ios_base::hex, ios_base::basefield);
  121.     return (_I); }
  122. inline ios_base& __cdecl internal(ios_base& _I)
  123.     {_I.setf(ios_base::internal, ios_base::adjustfield);
  124.     return (_I); }
  125. inline ios_base& __cdecl left(ios_base& _I)
  126.     {_I.setf(ios_base::left, ios_base::adjustfield);
  127.     return (_I); }
  128. inline ios_base& __cdecl noboolalpha(ios_base& _I)
  129.     {_I.unsetf(ios_base::boolalpha);
  130.     return (_I); }
  131. inline ios_base& __cdecl noshowbase(ios_base& _I)
  132.     {_I.unsetf(ios_base::showbase);
  133.     return (_I); }
  134. inline ios_base& __cdecl noshowpoint(ios_base& _I)
  135.     {_I.unsetf(ios_base::showpoint);
  136.     return (_I); }
  137. inline ios_base& __cdecl noshowpos(ios_base& _I)
  138.     {_I.unsetf(ios_base::showpos);
  139.     return (_I); }
  140. inline ios_base& __cdecl noskipws(ios_base& _I)
  141.     {_I.unsetf(ios_base::skipws);
  142.     return (_I); }
  143. inline ios_base& __cdecl nounitbuf(ios_base& _I)
  144.     {_I.unsetf(ios_base::unitbuf);
  145.     return (_I); }
  146. inline ios_base& __cdecl nouppercase(ios_base& _I)
  147.     {_I.unsetf(ios_base::uppercase);
  148.     return (_I); }
  149. inline ios_base& __cdecl oct(ios_base& _I)
  150.     {_I.setf(ios_base::oct, ios_base::basefield);
  151.     return (_I); }
  152. inline ios_base& __cdecl right(ios_base& _I)
  153.     {_I.setf(ios_base::right, ios_base::adjustfield);
  154.     return (_I); }
  155. inline ios_base& __cdecl scientific(ios_base& _I)
  156.     {_I.setf(ios_base::scientific, ios_base::floatfield);
  157.     return (_I); }
  158. inline ios_base& __cdecl showbase(ios_base& _I)
  159.     {_I.setf(ios_base::showbase);
  160.     return (_I); }
  161. inline ios_base& __cdecl showpoint(ios_base& _I)
  162.     {_I.setf(ios_base::showpoint);
  163.     return (_I); }
  164. inline ios_base& __cdecl showpos(ios_base& _I)
  165.     {_I.setf(ios_base::showpos);
  166.     return (_I); }
  167. inline ios_base& __cdecl skipws(ios_base& _I)
  168.     {_I.setf(ios_base::skipws);
  169.     return (_I); }
  170. inline ios_base& __cdecl unitbuf(ios_base& _I)
  171.     {_I.setf(ios_base::unitbuf);
  172.     return (_I); }
  173. inline ios_base& __cdecl uppercase(ios_base& _I)
  174.     {_I.setf(ios_base::uppercase);
  175.     return (_I); }
  176. _STD_END
  177. #ifdef  _MSC_VER
  178. #pragma pack(pop)
  179. #endif  /* _MSC_VER */
  180.  
  181. #endif /* _IOS_ */
  182.  
  183. /*
  184.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  185.  * Consult your license regarding permissions and restrictions.
  186.  */
  187.