home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / INCLUDE / IOS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-06  |  8.9 KB  |  316 lines

  1. /***
  2. *ios.h - definitions/declarations for the ios class.
  3. *
  4. *    Copyright (c) 1990-1997, 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. *       [Public]
  12. *
  13. ****/
  14.  
  15. #if _MSC_VER > 1000
  16. #pragma once
  17. #endif
  18.  
  19. #ifdef __cplusplus
  20.  
  21. #ifndef _INC_IOS
  22. #define _INC_IOS
  23.  
  24. #if !defined(_WIN32) && !defined(_MAC)
  25. #error ERROR: Only Mac or Win32 targets supported!
  26. #endif
  27.  
  28.  
  29. #ifdef    _MSC_VER
  30. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  31. // alignment.
  32. #pragma pack(push,8)
  33.  
  34. #include <useoldio.h>
  35.  
  36. #endif    // _MSC_VER
  37.  
  38. /* Define _CRTIMP */
  39.  
  40. #ifndef _CRTIMP
  41. #ifdef    _NTSDK
  42. /* definition compatible with NT SDK */
  43. #define _CRTIMP
  44. #else    /* ndef _NTSDK */
  45. /* current definition */
  46. #ifdef    _DLL
  47. #define _CRTIMP __declspec(dllimport)
  48. #else    /* ndef _DLL */
  49. #define _CRTIMP
  50. #endif    /* _DLL */
  51. #endif    /* _NTSDK */
  52. #endif    /* _CRTIMP */
  53.  
  54.  
  55. #ifdef _MT
  56.  
  57. typedef struct __CRT_LIST_ENTRY {
  58.    struct __CRT_LIST_ENTRY *Flink;
  59.    struct __CRT_LIST_ENTRY *Blink;
  60. } _CRT_LIST_ENTRY;
  61.  
  62. typedef struct _CRT_CRITICAL_SECTION_DEBUG {
  63.     unsigned short Type;
  64.     unsigned short CreatorBackTraceIndex;
  65.     struct _CRT_CRITICAL_SECTION *CriticalSection;
  66.     _CRT_LIST_ENTRY ProcessLocksList;
  67.     unsigned long EntryCount;
  68.     unsigned long ContentionCount;
  69.     unsigned long Depth;
  70.     void * OwnerBackTrace[ 5 ];
  71. } _CRT_CRITICAL_SECTION_DEBUG, *_PCRT_CRITICAL_SECTION_DEBUG;
  72.  
  73. typedef struct _CRT_CRITICAL_SECTION {
  74.     _PCRT_CRITICAL_SECTION_DEBUG DebugInfo;
  75.  
  76.     //
  77.     //  The following three fields control entering and exiting the critical
  78.     //  section for the resource
  79.     //
  80.  
  81.     long LockCount;
  82.     long RecursionCount;
  83.     void * OwningThread;        // from the thread's ClientId->UniqueThread
  84.     void * LockSemaphore;
  85.     unsigned long Reserved;
  86. } _CRT_CRITICAL_SECTION, *_PCRT_CRITICAL_SECTION;
  87.  
  88. extern "C" {
  89. _CRTIMP void __cdecl _mtlock(_PCRT_CRITICAL_SECTION);
  90. _CRTIMP void __cdecl _mtunlock(_PCRT_CRITICAL_SECTION);
  91. }
  92.  
  93. #endif /* _MT */
  94.  
  95. #ifndef NULL
  96. #define NULL    0
  97. #endif
  98.  
  99. #ifndef EOF
  100. #define EOF    (-1)
  101. #endif
  102.  
  103. #ifdef    _MSC_VER
  104. // C4514: "unreferenced inline function has been removed"
  105. #pragma warning(disable:4514) // disable C4514 warning
  106. // #pragma warning(default:4514)    // use this to reenable, if desired
  107. #endif    // _MSC_VER
  108.  
  109. class _CRTIMP streambuf;
  110. class _CRTIMP ostream;
  111.  
  112. class _CRTIMP ios {
  113.  
  114. public:
  115.     enum io_state {  goodbit = 0x00,
  116.              eofbit  = 0x01,
  117.              failbit = 0x02,
  118.              badbit  = 0x04 };
  119.  
  120.     enum open_mode { in        = 0x01,
  121.              out       = 0x02,
  122.              ate       = 0x04,
  123.              app       = 0x08,
  124.              trunc     = 0x10,
  125.              nocreate  = 0x20,
  126.              noreplace = 0x40,
  127.              binary    = 0x80 };
  128.  
  129.     enum seek_dir { beg=0, cur=1, end=2 };
  130.  
  131.     enum {  skipws     = 0x0001,
  132.         left       = 0x0002,
  133.         right      = 0x0004,
  134.         internal   = 0x0008,
  135.         dec        = 0x0010,
  136.         oct        = 0x0020,
  137.         hex        = 0x0040,
  138.         showbase   = 0x0080,
  139.         showpoint  = 0x0100,
  140.         uppercase  = 0x0200,
  141.         showpos    = 0x0400,
  142.         scientific = 0x0800,
  143.         fixed      = 0x1000,
  144.         unitbuf    = 0x2000,
  145.         stdio      = 0x4000
  146.                  };
  147.  
  148.     static const long basefield;    // dec | oct | hex
  149.     static const long adjustfield;    // left | right | internal
  150.     static const long floatfield;    // scientific | fixed
  151.  
  152.     ios(streambuf*);            // differs from ANSI
  153.     virtual ~ios();
  154.  
  155.     inline long flags() const;
  156.     inline long flags(long _l);
  157.  
  158.     inline long setf(long _f,long _m);
  159.     inline long setf(long _l);
  160.     inline long unsetf(long _l);
  161.  
  162.     inline int width() const;
  163.     inline int width(int _i);
  164.  
  165.     inline ostream* tie(ostream* _os);
  166.     inline ostream* tie() const;
  167.  
  168.     inline char fill() const;
  169.     inline char fill(char _c);
  170.  
  171.     inline int precision(int _i);
  172.     inline int precision() const;
  173.  
  174.     inline int rdstate() const;
  175.     inline void clear(int _i = 0);
  176.  
  177. //  inline operator void*() const;
  178.     operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  179.     inline int operator!() const;
  180.  
  181.     inline int  good() const;
  182.     inline int  eof() const;
  183.     inline int  fail() const;
  184.     inline int  bad() const;
  185.  
  186.     inline streambuf* rdbuf() const;
  187.  
  188.     inline long & iword(int) const;
  189.     inline void * & pword(int) const;
  190.  
  191.     static long bitalloc();
  192.     static int xalloc();
  193.     static void sync_with_stdio();
  194.  
  195. #ifdef    _MT
  196.     inline void __cdecl setlock();
  197.     inline void __cdecl clrlock();
  198.     void __cdecl lock() { if (LockFlg<0) _mtlock(lockptr()); };
  199.     void __cdecl unlock() { if (LockFlg<0) _mtunlock(lockptr()); }
  200.     inline void __cdecl lockbuf();
  201.     inline void __cdecl unlockbuf();
  202. #else
  203.     void __cdecl lock() { }
  204.     void __cdecl unlock() { }
  205.     void __cdecl lockbuf() { }
  206.     void __cdecl unlockbuf() { }
  207. #endif
  208.  
  209. protected:
  210.     ios();
  211.     ios(const ios&);            // treat as private
  212.     ios& operator=(const ios&);
  213.     void init(streambuf*);
  214.  
  215.     enum { skipping, tied };
  216.     streambuf*    bp;
  217.  
  218.     int     state;
  219.     int     ispecial;            // not used
  220.     int     ospecial;            // not used
  221.     int     isfx_special;        // not used
  222.     int     osfx_special;        // not used
  223.     int     x_delbuf;            // if set, rdbuf() deleted by ~ios
  224.  
  225.     ostream* x_tie;
  226.     long    x_flags;
  227.     int     x_precision;
  228.     char    x_fill;
  229.     int     x_width;
  230.  
  231.     static void (*stdioflush)();    // not used
  232.  
  233. #ifdef    _MT
  234.     static void lockc() { _mtlock(& x_lockc); }
  235.     static void unlockc() { _mtunlock( & x_lockc); }
  236.     _PCRT_CRITICAL_SECTION lockptr() { return & x_lock; }
  237. #else
  238.     static void lockc() { }
  239.     static void unlockc() { }
  240. #endif
  241.  
  242. public:
  243.     int    delbuf() const { return x_delbuf; }
  244.     void    delbuf(int _i) { x_delbuf = _i; }
  245.  
  246. private:
  247.     static long x_maxbit;
  248.     static int x_curindex;
  249.     static int sunk_with_stdio;        // make sure sync_with done only once
  250. #ifdef    _MT
  251. #define MAXINDEX 7
  252.     static long x_statebuf[MAXINDEX+1];  // used by xalloc()
  253.     static int fLockcInit;        // used to see if x_lockc initialized
  254.     static _CRT_CRITICAL_SECTION x_lockc; // used to lock static (class) data members
  255.     int LockFlg;            // enable locking flag
  256.     _CRT_CRITICAL_SECTION x_lock;    // used for multi-thread lock on object
  257. #else
  258.     static long * x_statebuf;  // used by xalloc()
  259. #endif
  260. };
  261.  
  262. #include <streamb.h>
  263.  
  264. inline _CRTIMP ios& __cdecl dec(ios& _strm) { _strm.setf(ios::dec,ios::basefield); return _strm; }
  265. inline _CRTIMP ios& __cdecl hex(ios& _strm) { _strm.setf(ios::hex,ios::basefield); return _strm; }
  266. inline _CRTIMP ios& __cdecl oct(ios& _strm) { _strm.setf(ios::oct,ios::basefield); return _strm; }
  267.  
  268. inline long ios::flags() const { return x_flags; }
  269. inline long ios::flags(long _l){ long _lO; _lO = x_flags; x_flags = _l; return _lO; }
  270.  
  271. inline long ios::setf(long _l,long _m){ long _lO; lock(); _lO = x_flags; x_flags = (_l&_m) | (x_flags&(~_m)); unlock(); return _lO; }
  272. inline long ios::setf(long _l){ long _lO; lock(); _lO = x_flags; x_flags |= _l; unlock(); return _lO; }
  273. inline long ios::unsetf(long _l){ long _lO; lock(); _lO = x_flags; x_flags &= (~_l); unlock(); return _lO; }
  274.  
  275. inline int ios::width() const { return x_width; }
  276. inline int ios::width(int _i){ int _iO; _iO = (int)x_width; x_width = _i; return _iO; }
  277.  
  278. inline ostream* ios::tie(ostream* _os){ ostream* _osO; _osO = x_tie; x_tie = _os; return _osO; }
  279. inline ostream* ios::tie() const { return x_tie; }
  280. inline char ios::fill() const { return x_fill; }
  281. inline char ios::fill(char _c){ char _cO; _cO = x_fill; x_fill = _c; return _cO; }
  282. inline int ios::precision(int _i){ int _iO; _iO = (int)x_precision; x_precision = _i; return _iO; }
  283. inline int ios::precision() const { return x_precision; }
  284.  
  285. inline int ios::rdstate() const { return state; }
  286.  
  287. // inline ios::operator void *() const { if(state&(badbit|failbit) ) return 0; return (void *)this; }
  288. inline int ios::operator!() const { return state&(badbit|failbit); }
  289.  
  290. inline int  ios::bad() const { return state & badbit; }
  291. inline void ios::clear(int _i){ lock(); state = _i; unlock(); }
  292. inline int  ios::eof() const { return state & eofbit; }
  293. inline int  ios::fail() const { return state & (badbit | failbit); }
  294. inline int  ios::good() const { return state == 0; }
  295.  
  296. inline streambuf* ios::rdbuf() const { return bp; }
  297.  
  298. inline long & ios::iword(int _i) const { return x_statebuf[_i] ; }
  299. inline void * & ios::pword(int _i) const { return (void * &)x_statebuf[_i]; }
  300.  
  301. #ifdef    _MT
  302.     inline void ios::setlock() { LockFlg--; if (bp) bp->setlock(); }
  303.     inline void ios::clrlock() { if (LockFlg <= 0) LockFlg++; if (bp) bp->clrlock(); }
  304.     inline void ios::lockbuf() { bp->lock(); }
  305.     inline void ios::unlockbuf() { bp->unlock(); }
  306. #endif
  307.  
  308. #ifdef    _MSC_VER
  309. // Restore default packing
  310. #pragma pack(pop)
  311. #endif    // _MSC_VER
  312.  
  313. #endif    // _INC_IOS
  314.  
  315. #endif /* __cplusplus */
  316.