home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / include / Iostream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-02  |  24.6 KB  |  758 lines

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