home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 4.ddi / INCLUDE / IOS.H$ / IOS
Encoding:
Text File  |  1992-01-23  |  5.8 KB  |  195 lines

  1. /***
  2. *ios.h - definitions/declarations for the ios class.
  3. *
  4. *    Copyright (c) 1990-1992, Microsoft Corporation.  All rights reserved.
  5. *
  6. *Purpose:
  7. *    This file defines the classes, values, macros, and functions
  8. *    used by the ios class.
  9. *    [AT&T C++]
  10. *
  11. ****/
  12.  
  13. #ifndef _INC_IOS
  14. #define _INC_IOS
  15.  
  16.  
  17. #ifdef M_I86HM        // fold huge member pointers into far
  18. #define _HFAR_ __far
  19. #else
  20. #define _HFAR_
  21. #endif
  22.  
  23. #ifndef EOF
  24. #define EOF (-1)
  25. #endif
  26.  
  27. // Force word packing to avoid possible -Zp override
  28. #pragma pack(2)
  29.  
  30. #pragma warning(disable:4505)        // disable unwanted /W4 warning
  31. // #pragma warning(default:4505)    // use this to reenable, if necessary
  32.  
  33. class streambuf;
  34. class ostream;
  35.  
  36. class ios {
  37.  
  38. public:
  39.     enum io_state {  goodbit = 0x00,
  40.              eofbit  = 0x01,
  41.              failbit = 0x02,
  42.              badbit  = 0x04 };
  43.  
  44.     enum open_mode { in        = 0x01,
  45.              out       = 0x02,
  46.              ate       = 0x04,
  47.              app       = 0x08,
  48.              trunc     = 0x10,
  49.              nocreate  = 0x20,
  50.              noreplace = 0x40,
  51.              binary    = 0x80 };    // CONSIDER: not in latest spec.
  52.  
  53.     enum seek_dir { beg=0, cur=1, end=2 };
  54.  
  55.     enum {  skipws     = 0x0001,
  56.         left       = 0x0002,
  57.         right      = 0x0004,
  58.         internal   = 0x0008,
  59.         dec        = 0x0010,
  60.         oct        = 0x0020,
  61.         hex        = 0x0040,
  62.         showbase   = 0x0080,
  63.         showpoint  = 0x0100,
  64.         uppercase  = 0x0200,
  65.         showpos    = 0x0400,
  66.         scientific = 0x0800,
  67.         fixed      = 0x1000,
  68.         unitbuf    = 0x2000,
  69.         stdio      = 0x4000
  70.                  };
  71.  
  72.     static const long basefield;    // dec | oct | hex
  73.     static const long adjustfield;    // left | right | internal
  74.     static const long floatfield;    // scientific | fixed
  75.  
  76.     ios(streambuf*);            // differs from ANSI
  77.     virtual ~ios();
  78.  
  79.     inline long flags() const;
  80.     inline long flags(long _l);
  81.  
  82.     inline long setf(long _f,long _m);
  83.     inline long setf(long _l);
  84.     inline long unsetf(long _l);
  85.  
  86.     inline int width() const;
  87.     inline int width(int _i);
  88.  
  89.     inline ostream* tie(ostream* _os);
  90.     inline ostream* tie() const;
  91.  
  92.     inline char fill() const;
  93.     inline char fill(char _c);
  94.  
  95.     inline int precision(int _i);
  96.     inline int precision() const;
  97.  
  98.     inline int rdstate() const;
  99.     inline void clear(int _i = 0);
  100.  
  101. //  inline operator void*() const;
  102.     operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  103.     inline int operator!() const;
  104.  
  105.     inline int  good() const;
  106.     inline int  eof() const;
  107.     inline int  fail() const;
  108.     inline int  bad() const;
  109.  
  110.     inline streambuf* rdbuf() const;
  111.  
  112.     inline long _HFAR_ & iword(int) const;
  113.     inline void _HFAR_ * _HFAR_ & pword(int) const;
  114.  
  115.     static long bitalloc();
  116.     static int xalloc();
  117.     static void sync_with_stdio();
  118.  
  119. protected:
  120.     ios();
  121.     ios(const ios&);            // treat as private
  122.     ios& operator=(const ios&);
  123.     void init(streambuf*);
  124.  
  125.     enum { skipping, tied };
  126.     streambuf*    bp;
  127.  
  128.     int     state;
  129.     int     ispecial;            // not used
  130.     int     ospecial;            // not used
  131.     int     isfx_special;        // not used
  132.     int     osfx_special;        // not used
  133.     int     x_delbuf;            // if set, rdbuf() deleted by ~ios
  134.  
  135.     ostream* x_tie;
  136.     long    x_flags;
  137.     short   x_precision;
  138.     char    x_fill;
  139.     short   x_width;
  140.  
  141.     static void (*stdioflush)();    // not used
  142. public:
  143.     int    delbuf() const { return x_delbuf; }
  144.     void    delbuf(int _i) { x_delbuf = _i; }
  145.  
  146. private:
  147.     static long x_maxbit;
  148.     static long _HFAR_ * x_statebuf;  // used by xalloc()
  149.     static int x_curindex;
  150. // consider: make interal static to ios::sync_with_stdio()
  151.     static int sunk_with_stdio;        // make sure sync_with done only once
  152. };
  153.  
  154. inline ios& dec(ios& _strm) { _strm.setf(ios::dec,ios::basefield); return _strm; }
  155. inline ios& hex(ios& _strm) { _strm.setf(ios::hex,ios::basefield); return _strm; }
  156. inline ios& oct(ios& _strm) { _strm.setf(ios::oct,ios::basefield); return _strm; }
  157.  
  158. inline long ios::flags() const { return x_flags; }
  159. inline long ios::flags(long _l){ long _lO; _lO = x_flags; x_flags = _l; return _lO; }
  160.  
  161. inline long ios::setf(long _l,long _m){ long _lO; _lO = x_flags; x_flags = (_l&_m) | (x_flags&(~_m)); return _lO; }
  162. inline long ios::setf(long _l){ long _lO; _lO = x_flags; x_flags |= _l; return _lO; }
  163. inline long ios::unsetf(long _l){ long _lO; _lO = x_flags; x_flags &= (~_l); return _lO; }
  164.  
  165. inline int ios::width() const { return x_width; }
  166. inline int ios::width(int _i){ int _iO; _iO = (int)x_width; x_width = (short)_i; return _iO; }
  167.  
  168. inline ostream* ios::tie(ostream* _os){ ostream* _osO; _osO = x_tie; x_tie = _os; return _osO; }
  169. inline ostream* ios::tie() const { return x_tie; }
  170. inline char ios::fill() const { return x_fill; }
  171. inline char ios::fill(char _c){ char _cO; _cO = x_fill; x_fill = _c; return _cO; }
  172. inline int ios::precision(int _i){ int _iO; _iO = (int)x_precision; x_precision = (short)_i; return _iO; }
  173. inline int ios::precision() const { return x_precision; }
  174.  
  175. inline int ios::rdstate() const { return state; }
  176.  
  177. // inline ios::operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  178. inline int ios::operator!() const { return state&(badbit|failbit); }
  179.  
  180. inline int  ios::bad() const { return state & badbit; }
  181. inline void ios::clear(int _i){ state = _i; }
  182. inline int  ios::eof() const { return state & eofbit; }
  183. inline int  ios::fail() const { return state & (badbit | failbit); }
  184. inline int  ios::good() const { return state == 0; }
  185.  
  186. inline streambuf* ios::rdbuf() const { return bp; }
  187.  
  188. inline long _HFAR_ & ios::iword(int _i) const { return x_statebuf[_i] ; }
  189. inline void _HFAR_ * _HFAR_ & ios::pword(int _i) const { return (void _HFAR_ * _HFAR_ &)x_statebuf[_i]; }
  190.  
  191. // Restore default packing
  192. #pragma pack()
  193.  
  194. #endif        // !_INC_IOS
  195.