home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / INCLUDE.ZIP / IOSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  29.1 KB  |  726 lines

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