home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 2.ddi / INCLUDE.ZIP / IOSTREAM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  28.2 KB  |  722 lines

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