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