home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / IOSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-03  |  34.7 KB  |  864 lines

  1. /*  iostream.h -- basic stream I/O declarations
  2.  
  3.     There are some inline functions here which generate a LOT of code
  4.     (as much as 300 bytes), but are available inline because AT&T did
  5.     it that way.  We have also made them true functions in the library
  6.     and conditionally deleted the inline code from this header.
  7.  
  8.     If you really want these big functions to be inline, #define the
  9.     macro name _BIG_INLINE_ before including this header.
  10.  
  11.     Programs will compile and link correctly even if some modules are
  12.     compiled with _BIG_INLINE_ and some are not.
  13. */
  14.  
  15. /* $Copyright: 1990$ */
  16. /* $Revision:   8.2  $ */
  17.  
  18. #ifndef __cplusplus
  19. #error Must use C++ for the type iostream.
  20. #endif
  21.  
  22. #ifndef __IOSTREAM_H
  23. #define __IOSTREAM_H
  24.  
  25. #if !defined(___DEFS_H)
  26. #include <_defs.h>
  27. #endif
  28.  
  29. #if !defined(__STRING_H)
  30. #include <string.h>    // to get strnicmp, memcpy and NULL
  31. #endif
  32.  
  33.  
  34. #if !defined(RC_INVOKED)
  35.  
  36. #pragma pack(push, 1)
  37.  
  38. #if defined(__BCOPT__)
  39. #if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  40. #pragma option -po-     // disable Object data calling convention
  41. #endif
  42. #endif
  43.  
  44. #if !defined(__TINY__)
  45. #pragma option -RT
  46. #endif
  47.  
  48. #pragma option -Vo-     // set standard C++ options
  49.  
  50. #if defined(__STDC__)
  51. #pragma warn -nak
  52. #endif
  53.  
  54. #endif  /* !RC_INVOKED */
  55.  
  56.  
  57. // Definition of EOF must match the one in <stdio.h>
  58. #define EOF (-1)
  59.  
  60. // extract a char from int i, ensuring that zapeof(EOF) != EOF
  61. #define zapeof(i) ((unsigned char)(i))
  62.  
  63. typedef long streampos;
  64. typedef long streamoff;
  65.  
  66. _CLASSDEF(ios)
  67. _CLASSDEF(streambuf)
  68. _CLASSDEF(istream)
  69. _CLASSDEF(ostream)
  70. _CLASSDEF(iostream)
  71. _CLASSDEF(istream_withassign)
  72. _CLASSDEF(ostream_withassign)
  73. _CLASSDEF(iostream_withassign)
  74.  
  75. class _EXPCLASS ios {
  76. public:
  77.     // stream status bits
  78.     enum io_state   {
  79.         goodbit  = 0x00,    // no bit set: all is ok
  80.         eofbit   = 0x01,    // at end of file
  81.         failbit  = 0x02,    // last I/O operation failed
  82.         badbit   = 0x04,    // invalid operation attempted
  83.         hardfail = 0x80     // unrecoverable error
  84.         };
  85.  
  86.     // stream operation mode
  87.     enum open_mode  {
  88.         in   = 0x01,        // open for reading
  89.         out  = 0x02,        // open for writing
  90.         ate  = 0x04,        // seek to eof upon original open
  91.         app  = 0x08,        // append mode: all additions at eof
  92.         trunc    = 0x10,    // truncate file if already exists
  93.         nocreate = 0x20,    // open fails if file doesn't exist
  94.         noreplace= 0x40,    // open fails if file already exists
  95.         binary   = 0x80     // binary (not text) file
  96.         };
  97.  
  98.     // stream seek direction
  99.     enum seek_dir { beg=0, cur=1, end=2 };
  100.  
  101.     // formatting flags
  102.     enum    {
  103.         skipws    = 0x0001, // skip whitespace on input
  104.         left      = 0x0002, // left-adjust output
  105.         right     = 0x0004, // right-adjust output
  106.         internal  = 0x0008, // padding after sign or base indicator
  107.         dec       = 0x0010, // decimal conversion
  108.         oct       = 0x0020, // octal conversion
  109.         hex       = 0x0040, // hexadecimal conversion
  110.         showbase  = 0x0080, // use base indicator on output
  111.         showpoint = 0x0100, // force decimal point (floating output)
  112.         uppercase = 0x0200, // upper-case hex output
  113.         showpos   = 0x0400, // add '+' to positive integers
  114.         scientific= 0x0800, // use 1.2345E2 floating notation
  115.         fixed     = 0x1000, // use 123.45 floating notation
  116.         unitbuf   = 0x2000, // flush all streams after insertion
  117.         stdio     = 0x4000, // flush stdout, stderr after insertion
  118.         boolalpha = 0x8000  // insert/extract bools as text or numeric
  119.         };
  120.  
  121.     // constants for second parameter of seft()
  122. static  const long basefield;       // dec | oct | hex
  123. static  const long adjustfield;     // left | right | internal
  124. static  const long floatfield;      // scientific | fixed
  125.  
  126.     // constructor, destructor
  127.             _RTLENTRY ios(streambuf _FAR *);
  128. virtual     _RTLENTRY ~ios();
  129.  
  130.     // for reading/setting/clearing format flags
  131.     long    _RTLENTRY flags();
  132.     long    _RTLENTRY flags(long);
  133.     long    _RTLENTRY setf(long _setbits, long _field);
  134.     long    _RTLENTRY setf(long);
  135.     long    _RTLENTRY unsetf(long);
  136.  
  137.     // reading/setting field width
  138.     int     _RTLENTRY width();
  139.     int     _RTLENTRY width(int);
  140.  
  141.     // reading/setting padding character
  142.     char    _RTLENTRY fill();
  143.     char    _RTLENTRY fill(char);
  144.  
  145.     // reading/setting digits of floating precision
  146.     int     _RTLENTRY precision(int);
  147.     int     _RTLENTRY precision();
  148.  
  149.     // reading/setting ostream tied to this stream
  150.     ostream _FAR * _RTLENTRY tie(ostream _FAR *);
  151.     ostream _FAR * _RTLENTRY tie();
  152.  
  153.     // find out about current stream state
  154.     int     _RTLENTRY rdstate();       // return the stream state
  155.     int     _RTLENTRY eof();           // non-zero on end of file
  156.     int     _RTLENTRY fail();          // non-zero if an operation failed
  157.     int     _RTLENTRY bad();           // non-zero if error occurred
  158.     int     _RTLENTRY good();          // non-zero if no state bits set
  159.     void    _RTLENTRY clear(int = 0);  // set the stream state
  160.             _RTLENTRY operator void _FAR * (); // zero if state failed
  161.     int     _RTLENTRY operator! ();    // non-zero if state failed
  162.  
  163.     streambuf _FAR * _RTLENTRY rdbuf();        // get the assigned streambuf
  164.  
  165.     // for declaring additional flag bits and user words
  166. static long _RTLENTRY bitalloc();  // acquire a new flag bit, value returned
  167. static int  _RTLENTRY xalloc();    // acquire a new user word, index returned
  168.     long    _FAR & _RTLENTRY iword(int);  // return the nth user word as an int
  169.     void    _FAR * _FAR & _RTLENTRY pword(int);  // return the nth user word as a pointer
  170.  
  171. static void _RTLENTRY sync_with_stdio();
  172.  
  173.     // obsolete, for streams 1.2 compatibility
  174.     int     _RTLENTRY skip(int);
  175.  
  176.     int     delbuf() {return x_delbuf;}
  177.     int     delbuf(int _new) {int _x=x_delbuf;x_delbuf=_new;return _x;}
  178. protected:
  179.     // additional state flags for ispecial and ospecial
  180.     enum { skipping = 0x100, tied = 0x200 };
  181.  
  182.     streambuf _FAR * bp;    // the associated streambuf
  183.     ostream _FAR * x_tie;   // the tied ostream, if any
  184.     int     state;          // status bits
  185.     int     ispecial;       // istream status bits  ***
  186.     int     ospecial;       // ostream status bits  ***
  187.     long    x_flags;        // formatting flag bits
  188.     int     x_precision;    // floating-point precision on output
  189.     int     x_width;        // field width on output
  190.     int     x_fill;         // padding character on output
  191.     int     isfx_special;   // unused       ***
  192.     int     osfx_special;   // unused       ***
  193.     int     x_delbuf;       // unused       ***
  194.     int     assign_private; // unused       ***
  195. /*
  196.  * The data members marked with *** above are not documented in the AT&T
  197.  * release of streams, so we cannot guarantee compatibility with any
  198.  * other streams release in the use or values of these data members.
  199.  * If you can document any expected behavior of these data members, we
  200.  * will try to adjust our implementation accordingly.
  201.  */
  202.  
  203.             _RTLENTRY ios();       // null constructor, does not initialize
  204.  
  205.     void    _RTLENTRY init(streambuf _FAR *);  // the actual initialization
  206.  
  207.     void    _RTLENTRY setstate(int);       // set all status bits
  208.  
  209. static  void _RTLENTRY (*stdioflush)();
  210.  
  211. private:
  212.     // for extra flag bits and user words
  213. static  long    nextbit;
  214. static  int usercount;
  215.     union ios_user_union _FAR *userwords;
  216.     int     nwords;
  217.     void    _RTLENTRY usersize(int);
  218.  
  219.     // these declarations prevent automatic copying of an ios
  220.             _RTLENTRY ios(ios _FAR &);           // declared but not defined
  221.     void    _RTLENTRY operator= (ios _FAR &);    // declared but not defined
  222.  
  223. };
  224. inline streambuf _FAR * _RTLENTRY ios::rdbuf() { return bp; }
  225. inline ostream _FAR * _RTLENTRY ios::tie() { return x_tie; }
  226. inline char     _RTLENTRY ios::fill() { return (char)x_fill; }
  227. inline int      _RTLENTRY ios::precision() { return x_precision; }
  228. inline int      _RTLENTRY ios::rdstate() { return state; }
  229. inline int      _RTLENTRY ios::eof() { return state & eofbit; }
  230. inline int      _RTLENTRY ios::fail()
  231.                         { return state & (failbit | badbit | hardfail); }
  232. inline int      _RTLENTRY ios::bad() { return state & (badbit | hardfail); }
  233. inline int      _RTLENTRY ios::good() { return state == 0; }
  234. inline long     _RTLENTRY ios::flags() { return x_flags; }
  235. inline int      _RTLENTRY ios::width() { return x_width; }
  236. inline int      _RTLENTRY ios::width(int _w)
  237.                         { int _i = x_width; x_width = _w; return _i; }
  238. inline char     _RTLENTRY ios::fill(char _c)
  239.                         { char _x = (char)x_fill; x_fill = _c; return _x; }
  240. inline int      _RTLENTRY ios::precision(int _p)
  241.                         { int _x = x_precision; x_precision = _p; return _x; }
  242. inline          _RTLENTRY ios::operator void _FAR *()
  243.                         { return fail() ? 0 : this; }
  244. inline int      _RTLENTRY ios::operator! () { return fail(); }
  245.  
  246.  
  247. class _EXPCLASS streambuf {
  248. public:
  249.     // constructors and destructors
  250.         _RTLENTRY streambuf();                 // make empty streambuf
  251.         _RTLENTRY streambuf(char _FAR *, int); // make streambuf with
  252.                                             // given char array
  253. virtual _RTLENTRY ~streambuf();
  254.  
  255.     // use the provided char array for the buffer if possible
  256. virtual streambuf _FAR * _RTLENTRY setbuf(char _FAR *, int);
  257.  
  258.     // obsolete, for streams 1.2 compatibility
  259.     streambuf _FAR *  _RTLENTRY setbuf(char _FAR *, int, int);
  260.  
  261.     // getting (extracting) characters
  262.     int     _RTLENTRY sgetc();         // peek at next char
  263.     int     _RTLENTRY snextc();        // advance to and return next char
  264.     int     _RTLENTRY sbumpc();        // return current char and advance
  265.     void    _RTLENTRY stossc();        // advance to next character
  266.     int     _RTLENTRY sgetn(char _FAR *, int);     // get next n chars
  267. virtual int _RTLENTRY do_sgetn(char _FAR *, int);  // implementation of sgetn
  268. virtual int _RTLENTRY underflow();     // fill empty buffer
  269.     int     _RTLENTRY sputbackc(char); // return char to input
  270. virtual int _RTLENTRY pbackfail(int);  // implementation of sputbackc
  271.     int     _RTLENTRY in_avail();      // number of avail chars in buffer
  272.  
  273.     // putting (inserting) characters
  274.     int     _RTLENTRY sputc(int);          // put one char
  275.     int     _RTLENTRY sputn(const char _FAR *, int); // put n chars from string
  276. virtual int _RTLENTRY do_sputn(const char _FAR * s, int n); // implementation of sputn
  277. virtual int _RTLENTRY overflow(int = EOF); // flush buffer and make more room
  278.     int     _RTLENTRY out_waiting();       // number of unflushed chars
  279.  
  280.     // moving around in stream
  281. virtual streampos _RTLENTRY seekoff(streamoff, ios::seek_dir,
  282.                                  int = (ios::in | ios::out));
  283. virtual streampos _RTLENTRY seekpos(streampos, int = (ios::in | ios::out));
  284. virtual int _RTLENTRY sync();
  285.  
  286. #if defined(__FLAT__)
  287.     // locking and unlocking file handle associated with stream
  288. virtual void _RTLENTRY lock();
  289. virtual void _RTLENTRY unlock();
  290. #endif
  291.  
  292.     void    _RTLENTRY dbp();       // for debugging streambuf implementations
  293.  
  294. protected:
  295.     char _FAR * _RTLENTRY base();  // return start of buffer area
  296.     char _FAR * _RTLENTRY ebuf();  // return end+1 of buffer area
  297.     int     _RTLENTRY blen();      // return length of buffer area
  298.     char _FAR * _RTLENTRY pbase(); // return start of put area
  299.     char _FAR * _RTLENTRY pptr();  // return next location in put area
  300.     char _FAR * _RTLENTRY epptr(); // return end+1 of put area
  301.     char _FAR * _RTLENTRY eback(); // return base of putback section of get area
  302.     char _FAR * _RTLENTRY gptr();  // return next location in get area
  303.     char _FAR * _RTLENTRY egptr(); // return end+1 of get area
  304.     void    _RTLENTRY setp(char _FAR *, char _FAR *); // initialize the put pointers
  305.     void    _RTLENTRY setg(char _FAR *, char _FAR *, char _FAR *); // initialize the get pointers
  306.     void    _RTLENTRY pbump(int);  // advance the put pointer
  307.     void    _RTLENTRY gbump(int);  // advance the get pointer
  308.     void    _RTLENTRY setb(char _FAR *, char _FAR *, int = 0 );    // set the buffer area
  309.     void    _RTLENTRY unbuffered(int);// set the buffering state
  310.     int     _RTLENTRY unbuffered();    // non-zero if not buffered
  311.     int     _RTLENTRY allocate();  // set up a buffer area
  312. virtual int _RTLENTRY doallocate();    // implementation of allocate
  313.  
  314. private:
  315.     short   alloc_;     // non-zero if buffer should be deleted
  316.     short   unbuf_;     // non-zero if unbuffered
  317.     char _FAR * base_;  // start of buffer area
  318.     char _FAR * ebuf_;  // end+1 of buffer area
  319.     char _FAR * pbase_; // start of put area
  320.     char _FAR * pptr_;  // next put location
  321.     char _FAR * epptr_; // end+1 of put area
  322.     char _FAR * eback_; // base of putback section of get area
  323.     char _FAR * gptr_;  // next get location
  324.     char _FAR * egptr_; // end+1 of get area
  325.  
  326.     int     _RTLENTRY do_snextc(); // implementation of snextc
  327.  
  328.     // these declarations prevent copying of a streambuf
  329.             _RTLENTRY streambuf(streambuf _FAR &);   // declared but not defined
  330.     void    _RTLENTRY operator= (streambuf _FAR &);  // declared but not defined
  331. };
  332. inline char _FAR * _RTLENTRY streambuf::base()  { return base_; }
  333. inline char _FAR * _RTLENTRY streambuf::pbase() { return pbase_; }
  334. inline char _FAR * _RTLENTRY streambuf::pptr()  { return pptr_; }
  335. inline char _FAR * _RTLENTRY streambuf::epptr() { return epptr_; }
  336. inline char _FAR * _RTLENTRY streambuf::gptr()  { return gptr_; }
  337. inline char _FAR * _RTLENTRY streambuf::egptr() { return egptr_; }
  338. inline char _FAR * _RTLENTRY streambuf::eback() { return eback_; }
  339. inline char _FAR * _RTLENTRY streambuf::ebuf()  { return ebuf_; }
  340. inline int   _RTLENTRY streambuf::unbuffered()  { return unbuf_; }
  341. inline int   _RTLENTRY streambuf::blen() { return (int)(ebuf_ - base_);}
  342. inline void _RTLENTRY streambuf::pbump(int _n) { pptr_ += _n; }
  343. inline void _RTLENTRY streambuf::gbump(int _n) { gptr_ += _n; }
  344. inline void _RTLENTRY streambuf::unbuffered(int _unb) { unbuf_ = (short)(_unb != 0); }
  345. inline int  _RTLENTRY streambuf::in_avail()
  346.                 { return (egptr_ > gptr_) ? (int)(egptr_ - gptr_) : 0; }
  347. inline int  _RTLENTRY streambuf::out_waiting()
  348.                 { return pptr_ ? (int)(pptr_ - pbase_) : 0; }
  349. inline int  _RTLENTRY streambuf::allocate() {
  350.                 return (base_ || unbuf_) ? 0 : doallocate();
  351.                 }
  352. inline int  _RTLENTRY streambuf::sgetc() {
  353.                 return (gptr_ >= egptr_) ? underflow() :
  354.                    (unsigned char)(*gptr_);
  355.                 }
  356. inline int  _RTLENTRY streambuf::snextc() {
  357.                 return (! gptr_ || (++gptr_ >= egptr_)) ?
  358.                     do_snextc() :
  359.                     (unsigned char)(*gptr_);
  360.                 }
  361. inline int  _RTLENTRY streambuf::sbumpc() {
  362.                 return (gptr_ >= egptr_ && underflow() == EOF) ?
  363.                     EOF :
  364.                     (unsigned char)(*gptr_++);
  365.                 }
  366. inline void _RTLENTRY streambuf::stossc() {
  367.                 if( gptr_ >= egptr_ ) underflow();
  368.                 else ++gptr_;
  369.                 }
  370. inline int  _RTLENTRY streambuf::sputbackc(char _c) {
  371.                 return (gptr_ > eback_) ?
  372.                     (unsigned char)(*--gptr_ = _c) :
  373.                     pbackfail(_c);
  374.                 }
  375. inline int  _RTLENTRY streambuf::sputc(int _c) {
  376.                 return (pptr_ >= epptr_) ?
  377.                     overflow((unsigned char)_c) :
  378.                     (unsigned char)(*pptr_++ = (char)_c);
  379.                 }
  380. #ifdef _BIG_INLINE_
  381. inline int  _RTLENTRY streambuf::sputn(const char _FAR * _s, int _n) {
  382.                 if( _n <= (epptr_ - pptr_) ) {
  383.                     memcpy(pptr_, _s, _n);
  384.                     pbump(_n);
  385.                     return _n;
  386.                 }
  387.                 return do_sputn(_s, _n);
  388.                 }
  389. inline int  _RTLENTRY streambuf::sgetn(char _FAR * _s, int _n) {
  390.                 if( _n <= (egptr_ - gptr_) ) {
  391.                     memcpy(_s, gptr_, _n);
  392.                     gbump(_n);
  393.                     return _n;
  394.                 }
  395.                 return do_sgetn(_s, _n);
  396.                 }
  397. #endif
  398.  
  399. #if defined(__FLAT__)
  400. inline void _RTLENTRY streambuf::lock() {}
  401. inline void _RTLENTRY streambuf::unlock() {}
  402. #endif
  403.  
  404. class _EXPCLASS istream : virtual public ios {
  405. public:
  406.         // constructor and destructor
  407.         _RTLENTRY istream(streambuf _FAR *);
  408. virtual _RTLENTRY ~istream();
  409.  
  410.         // Obsolete constructors, for streams 1.2 compatibility
  411.         // obsolete: set skip via format, tie via tie() function
  412.         _RTLENTRY istream(streambuf _FAR *, int _sk, ostream _FAR * _t=0);
  413.         // obsolete: use strstream
  414.         _RTLENTRY istream(int _sz, char _FAR *, int _sk=1);
  415.         // obsolete: use fstream
  416.         _RTLENTRY istream(int _fd, int _sk=1, ostream _FAR * _t=0);
  417.  
  418.     int _RTLENTRY ipfx(int = 0);       // input prefix function
  419.     int _RTLENTRY ipfx0();     // same as ipfx(0)
  420.     int _RTLENTRY ipfx1();     // same as ipfx(1)
  421.     void _RTLENTRY isfx()      { } // unused input suffix function
  422.  
  423.     // set/read the get pointer's position
  424.     istream _FAR & _RTLENTRY seekg(streampos);
  425.     istream _FAR & _RTLENTRY seekg(streamoff, ios::seek_dir);
  426.     streampos _RTLENTRY tellg();
  427.  
  428.     int _RTLENTRY sync();
  429.  
  430.     /*
  431.      * Unformatted extraction operations
  432.      */
  433.     // extract characters into an array
  434.     istream _FAR & _RTLENTRY get(         char _FAR *, int, char = '\n');
  435.     istream _FAR & _RTLENTRY get(  signed char _FAR *, int, char = '\n');
  436.     istream _FAR & _RTLENTRY get(unsigned char _FAR *, int, char = '\n');
  437.     istream _FAR & _RTLENTRY read(         char _FAR *, int);
  438.     istream _FAR & _RTLENTRY read(  signed char _FAR *, int);
  439.     istream _FAR & _RTLENTRY read(unsigned char _FAR *, int);
  440.  
  441.     // extract characters into an array up to termination char
  442.     istream _FAR & _RTLENTRY getline(         char _FAR *, int, char = '\n');
  443.     istream _FAR & _RTLENTRY getline(  signed char _FAR *, int, char = '\n');
  444.     istream _FAR & _RTLENTRY getline(unsigned char _FAR *, int, char = '\n');
  445.  
  446.     // extract characters into a streambuf up to termination char
  447.     istream _FAR & _RTLENTRY get(streambuf _FAR &, char = '\n');
  448.  
  449.     // extract a single character
  450.     istream _FAR & _RTLENTRY get(         char _FAR &);
  451.     istream _FAR & _RTLENTRY get(  signed char _FAR &);
  452.     istream _FAR & _RTLENTRY get(unsigned char _FAR &);
  453.     int            _RTLENTRY get();
  454.  
  455.     int      _RTLENTRY peek();     // return next char without extraction
  456.     int      _RTLENTRY gcount();   // number of unformatted chars last extracted
  457.     istream _FAR & _RTLENTRY putback(char);  // push back char into input
  458.  
  459.     // extract and discard chars but stop at delim
  460.     istream _FAR & _RTLENTRY ignore(int = 1, int = EOF);
  461.  
  462.     /*
  463.      * Formatted extraction operations
  464.      */
  465.     istream _FAR & _RTLENTRY operator>> (bool _FAR &);
  466.     istream _FAR & _RTLENTRY operator>> (istream _FAR & (_RTLENTRY *_f)(istream _FAR &));
  467.     istream _FAR & _RTLENTRY operator>> (ios _FAR & (_RTLENTRY *_f)(ios _FAR &) );
  468.     istream _FAR & _RTLENTRY operator>> (         char _FAR *);
  469.     istream _FAR & _RTLENTRY operator>> (  signed char _FAR *);
  470.     istream _FAR & _RTLENTRY operator>> (unsigned char _FAR *);
  471.     istream _FAR & _RTLENTRY operator>> (         char _FAR &);
  472.     istream _FAR & _RTLENTRY operator>> (  signed char _FAR &);
  473.     istream _FAR & _RTLENTRY operator>> (unsigned char _FAR &);
  474.     istream _FAR & _RTLENTRY operator>> (short _FAR &);
  475.     istream _FAR & _RTLENTRY operator>> (int _FAR &);
  476.     istream _FAR & _RTLENTRY operator>> (long _FAR &);
  477.     istream _FAR & _RTLENTRY operator>> (unsigned short _FAR &);
  478.     istream _FAR & _RTLENTRY operator>> (unsigned int _FAR &);
  479.     istream _FAR & _RTLENTRY operator>> (unsigned long _FAR &);
  480.     istream _FAR & _RTLENTRY operator>> (float _FAR &);
  481.     istream _FAR & _RTLENTRY operator>> (double _FAR &);
  482.     istream _FAR & _RTLENTRY operator>> (long double _FAR &);
  483.  
  484.     // extract from this istream, insert into streambuf
  485.     istream _FAR & _RTLENTRY operator>> (streambuf _FAR *);
  486.  
  487. protected:
  488.             _RTLENTRY istream();
  489.     void    _RTLENTRY eatwhite();      // extract consecutive whitespace
  490.  
  491. private:
  492.     int gcount_;    // chars extracted by last unformatted operation
  493.     signed char _RTLENTRY do_get();    // implementation of get
  494. };
  495. inline int  _RTLENTRY istream::gcount() { return gcount_; }
  496. inline int  _RTLENTRY istream::ipfx0()  { return ipfx(0); }
  497. inline int  _RTLENTRY istream::ipfx1()  { return ipfx(1); }
  498. #ifdef _BIG_INLINE_
  499. inline istream _FAR & _RTLENTRY istream::operator>> (char _FAR & _c) {
  500.                 if( ipfx0() )
  501.                     _c = bp->in_avail() ? bp->sbumpc() : do_get();
  502.                 return *this;
  503.                 }
  504. inline istream _FAR & _RTLENTRY istream::operator>> (signed char _FAR & _c) {
  505.                 if( ipfx0() )
  506.                     _c = bp->in_avail() ? bp->sbumpc() : do_get();
  507.                 return *this;
  508.                 }
  509. inline istream _FAR & _RTLENTRY istream::operator>> (unsigned char _FAR & _c) {
  510.                 if( ipfx0() )
  511.                     _c = bp->in_avail() ? bp->sbumpc() : do_get();
  512.                 return *this;
  513.                 }
  514. #endif
  515. inline istream _FAR & _RTLENTRY istream::operator>> (signed char  _FAR * _p) {
  516.                 return  *this >> (char _FAR *)_p;
  517.                 }
  518. inline istream _FAR & _RTLENTRY istream::operator>> (unsigned char  _FAR * _p) {
  519.                 return  *this >> (char _FAR *)_p;
  520.                 }
  521. inline istream _FAR & _RTLENTRY istream::get(signed char  _FAR * _p, int _l, char _t) {
  522.                 return get((char _FAR *)_p, _l, _t);
  523.                 }
  524. inline istream _FAR & _RTLENTRY istream::get(unsigned char  _FAR * _p, int _l, char _t) {
  525.                 return get((char _FAR *)_p, _l, _t);
  526.                 }
  527. inline istream _FAR & _RTLENTRY istream::read(signed char  _FAR * _p, int _l) {
  528.                 return read((char _FAR *)_p, _l);
  529.                 }
  530. inline istream _FAR & _RTLENTRY istream::read(unsigned char  _FAR * _p, int _l) {
  531.                 return read((char _FAR *)_p, _l);
  532.                 }
  533. inline istream _FAR & _RTLENTRY istream::getline(signed char  _FAR * _p, int _l, char _t) {
  534.                 return getline((char _FAR *) _p, _l, _t);
  535.                 }
  536. inline istream _FAR & _RTLENTRY istream::getline(unsigned char  _FAR * _p, int _l, char _t) {
  537.                 return getline((char _FAR *) _p, _l, _t);
  538.                 }
  539. inline int      _RTLENTRY istream::sync() { return bp->sync(); }
  540. inline istream _FAR & _RTLENTRY istream::operator>> (istream _FAR & (_RTLENTRY *_f)(istream _FAR &)) {
  541.                 return (*_f)(*this);
  542.                 }
  543. #ifdef _BIG_INLINE_
  544. inline istream _FAR & _RTLENTRY istream::get(char _FAR & _c) {
  545.                 if( ipfx1() )
  546.                     if( bp->in_avail() ) {
  547.                         gcount_ = 1;
  548.                         _c = bp->sbumpc();
  549.                     }
  550.                 else _c = do_get();
  551.                 return *this;
  552.                 }
  553. inline istream _FAR & _RTLENTRY istream::get(signed char _FAR & _c) {
  554.                 if( ipfx1() )
  555.                     if( bp->in_avail()) {
  556.                         gcount_ = 1;
  557.                         _c = bp->sbumpc();
  558.                     }
  559.                 else _c = do_get();
  560.                 return *this;
  561.                 }
  562. inline istream _FAR & _RTLENTRY istream::get(unsigned char _FAR & _c) {
  563.                 if( ipfx1() )
  564.                     if( bp->in_avail() ) {
  565.                         gcount_ = 1;
  566.                         _c = bp->sbumpc();
  567.                     }
  568.                 else _c = do_get();
  569.                 return *this;
  570.                 }
  571. inline int _RTLENTRY istream::get() {
  572.                 if( ipfx1() ) {
  573.                     int _c = bp->sbumpc();
  574.                     if( _c == EOF ) setstate(eofbit);
  575.                     else gcount_ = 1;
  576.                     return _c;
  577.                 }
  578.                 else return EOF;
  579.                 }
  580. #endif
  581. inline int  _RTLENTRY istream::peek() { return ipfx1() ? bp->sgetc() : EOF; }
  582.  
  583.  
  584. class _EXPCLASS ostream : virtual public ios {
  585. public:
  586.     // constructors and destructor
  587.         _RTLENTRY ostream(streambuf _FAR *);
  588. virtual _RTLENTRY ~ostream();
  589.     // Obsolete constructors, for streams 1.2 compatibility
  590.         _RTLENTRY ostream(int _fd); // obsolete, use fstream
  591.         _RTLENTRY ostream(int _sz, char _FAR *); // obsolete, use strstream
  592.  
  593.     int _RTLENTRY opfx();      // output prefix function
  594.     void _RTLENTRY osfx();     // output suffix function
  595.     ostream _FAR & _RTLENTRY flush();
  596.  
  597.     // set/read the put pointer's position
  598.     ostream _FAR & _RTLENTRY seekp(streampos);
  599.     ostream _FAR & _RTLENTRY seekp(streamoff, ios::seek_dir);
  600.     streampos _RTLENTRY tellp();
  601.  
  602.     /*
  603.      * Unformatted insertion operations
  604.      */
  605.     ostream _FAR & _RTLENTRY put(         char);  // insert the character
  606.     ostream _FAR & _RTLENTRY put(signed   char);  // insert the character
  607.     ostream _FAR & _RTLENTRY put(unsigned char);  // insert the character
  608.     ostream _FAR & _RTLENTRY write(const          char _FAR *, int); // insert the string
  609.     ostream _FAR & _RTLENTRY write(const   signed char _FAR *, int); // insert the string
  610.     ostream _FAR & _RTLENTRY write(const unsigned char _FAR *, int); // insert the string
  611.  
  612.     /*
  613.      * Formatted insertion operations
  614.      */
  615.     // insert "true" or "false" for bool
  616.     ostream _FAR & _RTLENTRY ostream::operator<< (bool);
  617.  
  618.     // insert the character
  619.     ostream _FAR & _RTLENTRY operator<< (         char);
  620.     ostream _FAR & _RTLENTRY operator<< (  signed char);
  621.     ostream _FAR & _RTLENTRY operator<< (unsigned char);
  622.  
  623.     // for the following, insert character representation of numeric value
  624.     ostream _FAR & _RTLENTRY operator<< (short);
  625.     ostream _FAR & _RTLENTRY operator<< (unsigned short);
  626.     ostream _FAR & _RTLENTRY operator<< (int);
  627.     ostream _FAR & _RTLENTRY operator<< (unsigned int);
  628.     ostream _FAR & _RTLENTRY operator<< (long);
  629.     ostream _FAR & _RTLENTRY operator<< (unsigned long);
  630. #if defined(__FLAT__)
  631.     ostream _FAR & _RTLENTRY operator<< (__int64);
  632.     ostream _FAR & _RTLENTRY operator<< (unsigned __int64);
  633. #endif   
  634.     ostream _FAR & _RTLENTRY operator<< (float);
  635.     ostream _FAR & _RTLENTRY operator<< (double);
  636.     ostream _FAR & _RTLENTRY operator<< (long double);
  637.  
  638.     // insert the null-terminated string
  639.     ostream _FAR & _RTLENTRY operator<< (const          char _FAR *);
  640.     ostream _FAR & _RTLENTRY operator<< (const   signed char _FAR *);
  641.     ostream _FAR & _RTLENTRY operator<< (const unsigned char _FAR *);
  642.  
  643.     // insert character representation of the value of the pointer
  644.     ostream _FAR & _RTLENTRY operator<< (void _FAR *);
  645.  
  646.     // extract from streambuf, insert into this ostream
  647.     ostream _FAR & _RTLENTRY operator<< (streambuf _FAR *);
  648.  
  649.     // manipulators
  650.     ostream _FAR & _RTLENTRY operator<< (ostream _FAR & (_RTLENTRY *_f)(ostream _FAR &));
  651.     ostream _FAR & _RTLENTRY operator<< (ios _FAR & (_RTLENTRY *_f)(ios _FAR &));
  652.  
  653. protected:
  654.     int     _RTLENTRY do_opfx();   // implementation of opfx
  655.     void    _RTLENTRY do_osfx();   // implementation of osfx
  656.             _RTLENTRY ostream();
  657.  
  658. private:
  659.     void    _RTLENTRY outstr(const char _FAR *, const char _FAR *);
  660. };
  661. inline int  _RTLENTRY ostream::opfx() { return ospecial ? do_opfx() : 1; }
  662. inline void _RTLENTRY ostream::osfx() { if( x_flags & (stdio | unitbuf) ) do_osfx(); }
  663. #ifdef _BIG_INLINE_
  664. inline ostream _FAR & _RTLENTRY ostream::operator<< (char _c) {
  665.                 if( opfx() )
  666.                     if( bp->sputc(_c) == EOF ) setstate(badbit);
  667.                         osfx();
  668.                 return *this;
  669.                 }
  670. #endif
  671. inline ostream _FAR & _RTLENTRY ostream::operator<< (signed char _c) {
  672.                 return *this << (char)_c;
  673.                 }
  674. inline ostream _FAR & _RTLENTRY ostream::operator<< (unsigned char _c) {
  675.                 return *this << (char)_c;
  676.                 }
  677. inline ostream _FAR & _RTLENTRY ostream::operator<< (const char _FAR * _s) {
  678.                 outstr(_s, (const char _FAR *)0);
  679.                 return *this;
  680.                 }
  681. inline ostream _FAR & _RTLENTRY ostream::operator<< (const signed char _FAR * _s) {
  682.                 outstr((const char _FAR *)_s, (const char _FAR *)0);
  683.                 return *this;
  684.                 }
  685. inline ostream _FAR & _RTLENTRY ostream::operator<< (const unsigned char _FAR * _s) {
  686.                 outstr((const char _FAR *)_s, (const char _FAR *)0);
  687.                 return *this;
  688.                 }
  689. inline ostream _FAR & _RTLENTRY ostream::operator<< (short _i)
  690.                 { return *this << (long) _i; }
  691. inline ostream _FAR & _RTLENTRY ostream::operator<< (unsigned short _i)
  692.                 { return *this << (unsigned long) _i; }
  693. inline ostream _FAR & _RTLENTRY ostream::operator<< (int _i)
  694.                 { return *this << (long) _i; }
  695. inline ostream _FAR & _RTLENTRY ostream::operator<< (unsigned int _i)
  696.                 { return *this << (unsigned long) _i; }
  697. inline ostream _FAR & _RTLENTRY ostream::operator<< (float _f)
  698.                 { return *this << (long double) _f; }
  699. inline ostream _FAR & _RTLENTRY ostream::operator<< (double _d)
  700.                 { return *this << (long double) _d; }
  701. inline ostream _FAR & _RTLENTRY ostream::operator<< (ostream _FAR & (_RTLENTRY *_f)(ostream _FAR &))
  702.                 { return (*_f)(*this); }
  703. inline ostream _FAR & _RTLENTRY ostream::write(const signed char _FAR * _s, int _n)
  704.                 { return write((const char _FAR *)_s, _n); }
  705. inline ostream _FAR & _RTLENTRY ostream::write(const unsigned char _FAR * _s, int _n)
  706.                 { return write((const char _FAR *)_s, _n); }
  707. inline ostream _FAR & _RTLENTRY ostream::put(char _c) {
  708.                 if( bp->sputc(_c) == EOF ) setstate(badbit);
  709.                 return *this;
  710.                 }
  711. inline ostream _FAR & _RTLENTRY ostream::put(signed char _c)
  712.                 { return put((char) _c); }
  713. inline ostream _FAR & _RTLENTRY ostream::put(unsigned char _c)
  714.                 { return put((char) _c); }
  715. #ifdef _BIG_INLINE_
  716. inline ostream _FAR & _RTLENTRY ostream::write(const char _FAR * _s, int _n) {
  717.                 if( ! fail() )
  718.                     if( bp->sputn(_s, _n) != _n )
  719.                         setstate(badbit);
  720.                 return *this;
  721.                 }
  722. #endif
  723.  
  724.  
  725. class _EXPCLASS iostream : public istream, public ostream {
  726. public:
  727.         _RTLENTRY iostream(streambuf _FAR *);
  728. virtual _RTLENTRY ~iostream();
  729.  
  730. protected:
  731.         _RTLENTRY iostream();
  732. };
  733.  
  734.  
  735. class _EXPCLASS istream_withassign : public istream {
  736. public:
  737.         // does no initialization
  738.         _RTLENTRY istream_withassign();
  739.  
  740. virtual _RTLENTRY ~istream_withassign();
  741.  
  742.     // gets buffer from istream and does entire initialization
  743.     istream_withassign _FAR & _RTLENTRY operator= (istream _FAR &);
  744.  
  745.     // associates streambuf with stream and does entire initialization
  746.     istream_withassign _FAR & _RTLENTRY operator= (streambuf _FAR *);
  747. };
  748.  
  749.  
  750. class _EXPCLASS ostream_withassign : public ostream {
  751. public:
  752.         // does no initialization
  753.         _RTLENTRY ostream_withassign();
  754.  
  755. virtual _RTLENTRY ~ostream_withassign();
  756.  
  757.     // gets buffer from istream and does entire initialization
  758.     ostream_withassign _FAR & _RTLENTRY operator= (ostream _FAR &);
  759.  
  760.     // associates streambuf with stream and does entire initialization
  761.     ostream_withassign _FAR & _RTLENTRY operator= (streambuf _FAR *);
  762. };
  763.  
  764.  
  765. class _EXPCLASS iostream_withassign : public iostream {
  766. public:
  767.         // does no initialization
  768.         _RTLENTRY iostream_withassign();
  769.  
  770. virtual _RTLENTRY ~iostream_withassign();
  771.  
  772.     // gets buffer from stream and does entire initialization
  773.     iostream_withassign _FAR & _RTLENTRY operator= (ios _FAR &);
  774.  
  775.     // associates streambuf with stream and does entire initialization
  776.     iostream_withassign _FAR & _RTLENTRY operator= (streambuf _FAR *);
  777. };
  778.  
  779. #if defined(__FLAT__)
  780.  
  781. /*
  782.  * The predefined streams
  783.  */
  784. extern istream_withassign _RTLENTRY _EXPDATA cin;
  785. extern ostream_withassign _RTLENTRY _EXPDATA cout;
  786. extern ostream_withassign _RTLENTRY _EXPDATA cerr;
  787. extern ostream_withassign _RTLENTRY _EXPDATA clog;
  788.  
  789. /*
  790.  * Manipulators
  791.  */
  792.  
  793. ostream _FAR &  _RTLENTRY _EXPFUNC endl(ostream _FAR &); // insert newline and flush
  794. ostream _FAR &  _RTLENTRY _EXPFUNC ends(ostream _FAR &); // insert null to terminate string
  795. ostream _FAR &  _RTLENTRY _EXPFUNC flush(ostream _FAR &);// flush the ostream
  796. ios _FAR &      _RTLENTRY _EXPFUNC dec(ios _FAR &);      // set conversion base to decimal
  797. ios _FAR &      _RTLENTRY _EXPFUNC hex(ios _FAR &);      // set conversion base to hexadecimal
  798. ios _FAR &      _RTLENTRY _EXPFUNC oct(ios _FAR &);      // set conversion base to octal
  799. istream _FAR &  _RTLENTRY _EXPFUNC ws(istream _FAR &);   // extract whitespace characters
  800.  
  801. ios&            _RTLENTRY _EXPFUNC lock(ios&);     // lock file handle
  802. ios&            _RTLENTRY _EXPFUNC unlock(ios&);   // unlock file handle
  803.  
  804. #else /* __FLAT__  */
  805.  
  806. /*
  807.  * The predefined streams
  808.  */
  809. extern istream_withassign _RTLENTRY  cin;
  810. extern ostream_withassign _RTLENTRY  cout;
  811. extern ostream_withassign _RTLENTRY  cerr;
  812. extern ostream_withassign _RTLENTRY  clog;
  813.  
  814. /*
  815.  * Manipulators
  816.  */
  817.  
  818. ostream _FAR &  _RTLENTRY  endl(ostream _FAR &); // insert newline and flush
  819. ostream _FAR &  _RTLENTRY  ends(ostream _FAR &); // insert null to terminate string
  820. ostream _FAR &  _RTLENTRY  flush(ostream _FAR &);// flush the ostream
  821. ios _FAR &      _RTLENTRY  dec(ios _FAR &);      // set conversion base to decimal
  822. ios _FAR &      _RTLENTRY  hex(ios _FAR &);      // set conversion base to hexadecimal
  823. ios _FAR &      _RTLENTRY  oct(ios _FAR &);      // set conversion base to octal
  824. istream _FAR &  _RTLENTRY  ws(istream _FAR &);   // extract whitespace characters
  825.  
  826. ios&            _RTLENTRY  lock(ios&);     // lock file handle
  827. ios&            _RTLENTRY  unlock(ios&);   // unlock file handle
  828.  
  829. #endif
  830.  
  831. #if !defined(__FLAT__)
  832. /*
  833.  * Initialization call for Easy Windows
  834.  */
  835. extern "C" void  _RTLENTRY _InitEasyWin(void);
  836. #endif
  837.  
  838.  
  839. #if !defined(RC_INVOKED)
  840.  
  841. #pragma option -Vo.     // restore user C++ options
  842.  
  843. #if !defined(__TINY__)
  844. #pragma option -RT.
  845. #endif
  846.  
  847. #if defined(__BCOPT__)
  848. #if !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
  849. #pragma option -po.     // restore Object data calling convention
  850. #endif
  851. #endif
  852.  
  853. /* restore default packing */
  854. #pragma pack(pop)
  855.  
  856. #if defined(__STDC__)
  857. #pragma warn .nak
  858. #endif
  859.  
  860. #endif  /* !RC_INVOKED */
  861.  
  862.  
  863. #endif  /* __IOSTREAM_H */
  864.