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

  1. // xiosbase internal header (from <ios>)
  2.  
  3. #if     _MSC_VER > 1000
  4. #pragma once
  5. #endif
  6.  
  7. #ifndef _XIOSBASE_
  8. #define _XIOSBASE_
  9. #include <xlocale>
  10.  
  11. #ifdef  _MSC_VER
  12. #pragma pack(push,8)
  13. #endif  /* _MSC_VER */
  14. _STD_BEGIN
  15.                 // CLASS ios_base
  16. class _CRTIMP ios_base {
  17. public:
  18.                         // CLASS failure
  19.         class failure : public runtime_error {
  20.         public:
  21.                 explicit failure(const string &_S)
  22.                         : runtime_error(_S) {}
  23.                 virtual ~failure()
  24.                         {}
  25.         protected:
  26.                 virtual void _Doraise() const
  27.                         {_RAISE(*this); }
  28.         };
  29.         enum _Fmtflags {skipws = 0x0001, unitbuf = 0x0002,
  30.                 uppercase = 0x0004, showbase = 0x0008,
  31.                 showpoint = 0x0010, showpos = 0x0020,
  32.                 left = 0x0040, right = 0x0080, internal = 0x0100,
  33.                 dec = 0x0200, oct = 0x0400, hex = 0x0800,
  34.                 scientific = 0x1000, fixed = 0x2000, boolalpha = 0x4000,
  35.                 adjustfield = 0x01c0, basefield = 0x0e00,
  36.                 floatfield = 0x3000, _Fmtmask = 0x7fff, _Fmtzero = 0};
  37.         enum _Iostate {goodbit = 0x0, eofbit = 0x1,
  38.                 failbit = 0x2, badbit = 0x4, _Statmask = 0x7};
  39.         enum _Openmode {in = 0x01, out = 0x02, ate = 0x04,
  40.                 app = 0x08, trunc = 0x10, binary = 0x20};
  41.         enum seekdir {beg = 0, cur = 1, end = 2};
  42.         enum event {erase_event, imbue_event, copyfmt_event};
  43.         typedef void (__cdecl *event_callback)(event, ios_base&, int);
  44.         _BITMASK(_Fmtflags, fmtflags);
  45.         _BITMASK(_Iostate, iostate);
  46.         _BITMASK(_Openmode, openmode);
  47.         typedef short io_state, open_mode, seek_dir;
  48.                         // CLASS Init
  49.         class _CRTIMP Init {
  50.         public:
  51.                 Init();
  52.                 ~Init();
  53.         private:
  54.                 static int _Init_cnt;
  55.                 };
  56.         ios_base& operator=(const ios_base& _R)
  57.                 {if (this != &_R)
  58.                         {_State = _R._State;
  59.                         copyfmt(_R); }
  60.                 return (*this); }
  61.         operator void *() const
  62.                 {return (fail() ? 0 : (void *)this); }
  63.         bool operator!() const
  64.                 {return (fail()); }
  65.         void clear(iostate = goodbit, bool = false);
  66.         void clear(io_state _St)
  67.                 {clear((iostate)_St); }
  68.         iostate rdstate() const
  69.                 {return (_State); }
  70.         void setstate(iostate _St, bool _Ex = false)
  71.                 {if (_St != goodbit)
  72.                         clear((iostate)((int)rdstate() | (int)_St), _Ex); }
  73.         void setstate(io_state _St)
  74.                 {setstate((iostate)_St); }
  75.         bool good() const
  76.                 {return (rdstate() == goodbit); }
  77.         bool eof() const
  78.                 {return ((int)rdstate() & (int)eofbit); }
  79.         bool fail() const
  80.                 {return (((int)rdstate() & ((int)badbit | (int)failbit)) != 0); }
  81.         bool bad() const
  82.                 {return (((int)rdstate() & (int)badbit) != 0); }
  83.         iostate exceptions() const
  84.                 {return (_Except); }
  85.         void exceptions(iostate _Ne)
  86.                 {_Except = _Ne & _Statmask;
  87.                 clear(_State); }
  88.         void exceptions(io_state _St)
  89.                 {exceptions((iostate)_St); }
  90.         fmtflags flags() const
  91.                 {return (_Fmtfl); }
  92.         fmtflags flags(fmtflags _Nf)
  93.                 {fmtflags _Of = _Fmtfl;
  94.                 _Fmtfl = _Nf & _Fmtmask;
  95.                 return (_Of); }
  96.         fmtflags setf(fmtflags _Nf)
  97.                 {ios_base::fmtflags _Of = _Fmtfl;
  98.                 _Fmtfl |= _Nf & _Fmtmask;
  99.                 return (_Of); }
  100.         fmtflags setf(fmtflags _Nf, fmtflags _M)
  101.                 {ios_base::fmtflags _Of = _Fmtfl;
  102.                 _Fmtfl = (_Fmtfl & ~_M) | (_Nf & _M & _Fmtmask);
  103.                 return (_Of); }
  104.         void unsetf(fmtflags _M)
  105.                 {_Fmtfl &= ~_M; }
  106.         streamsize precision() const
  107.                 {return (_Prec); }
  108.         streamsize precision(int _Np)
  109.                 {streamsize _Op = _Prec;
  110.                 _Prec = _Np;
  111.                 return (_Op); }
  112.         streamsize width() const
  113.                 {return (_Wide); }
  114.         streamsize width(streamsize _Nw)
  115.                 {streamsize _Ow = _Wide;
  116.                 _Wide = _Nw;
  117.                 return (_Ow); }
  118.         locale getloc() const
  119.                 {return (_Loc); }
  120.         locale imbue(const locale&);
  121.         static int __cdecl xalloc()
  122.                 {_Lockit _Lk;
  123.                 return (_Index++); }
  124.         long& iword(int _Idx)
  125.                 {return (_Findarr(_Idx)._Lo); }
  126.         void *& pword(int _Idx)
  127.                 {return (_Findarr(_Idx)._Vp); }
  128.         void register_callback(event_callback, int);
  129.         ios_base& copyfmt(const ios_base&);
  130.         virtual ~ios_base();
  131.         static bool __cdecl sync_with_stdio(bool _Sfl = true)
  132.                 {_Lockit _Lk;
  133.                 const bool _Osfl = _Sync;
  134.                 _Sync = _Sfl;
  135.                 return (_Osfl); }
  136. protected:
  137.         ios_base()
  138.                 : _Loc(_Noinit), _Stdstr(0) {}
  139.         void _Addstd();
  140.         void _Init();
  141. private:
  142.                         // STRUCT _Iosarray
  143.         struct _Iosarray {
  144.         public:
  145.                 _Iosarray(int _Idx, _Iosarray *_Link)
  146.                         : _Next(_Link), _Index(_Idx), _Lo(0), _Vp(0) {}
  147.                 _Iosarray *_Next;
  148.                 int _Index;
  149.                 long _Lo;
  150.                 void *_Vp;
  151.                 };
  152.                         // STRUCT _Fnarray
  153.         struct _Fnarray {
  154.                 _Fnarray(int _Idx, event_callback _P, _Fnarray *_Link)
  155.                         : _Next(_Link), _Index(_Idx), _Pfn(_P) {}
  156.                 _Fnarray *_Next;
  157.                 int _Index;
  158.                 event_callback _Pfn;
  159.                 };
  160.         void _Callfns(event);
  161.         _Iosarray& _Findarr(int);
  162.         void _Tidy();
  163.         iostate _State, _Except;
  164.         fmtflags _Fmtfl;
  165.         int _Prec, _Wide;
  166.         _Iosarray *_Arr;
  167.         _Fnarray *_Calls;
  168.         locale _Loc;
  169.         size_t _Stdstr;
  170.         static int _Index;
  171.         static bool _Sync;
  172.         };
  173. _BITMASK_OPS(ios_base::_Fmtflags)
  174. _BITMASK_OPS(ios_base::_Iostate)
  175. _BITMASK_OPS(ios_base::_Openmode)
  176. _STD_END
  177. #ifdef  _MSC_VER
  178. #pragma pack(pop)
  179. #endif  /* _MSC_VER */
  180.  
  181. #endif /* _XIOSBASE_ */
  182.  
  183. /*
  184.  * Copyright (c) 1995 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  185.  * Consult your license regarding permissions and restrictions.
  186.  */
  187.