home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / cxxinclude / iostream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-24  |  48.3 KB  |  1,595 lines

  1. /* Copyright (c) 1993             by SAS Institute Inc., Cary NC     */
  2.  
  3. #ifndef __IOSTREAM_H
  4. #define __IOSTREAM_H
  5.  
  6. #ifndef _STDDEFH
  7. #include <stddef.h>
  8. #endif
  9.  
  10. #ifndef _STRING_H
  11. #include <string.h>
  12. #endif
  13.  
  14. #ifndef _STDIO_H
  15. #include <stdio.h>
  16. #endif
  17.  
  18. #define __RENT
  19. #define __NORENT
  20.  
  21. #ifdef _OPTINLINE
  22. #define _INLINE_FUNC(x) x
  23. #else
  24. #define _INLINE_FUNC(x) ;
  25. #endif
  26.  
  27. typedef unsigned long _ulong;
  28.  
  29. class streambuf;
  30. class ostream;
  31. class istream;
  32.  
  33. typedef long streamoff;
  34.  
  35. struct streampos {
  36.  
  37.       streampos()
  38.         _INLINE_FUNC(
  39.           // Initialize as an uninitialize fpos_t.
  40.           {
  41.           _is_offset = 0;
  42.           _offset = 0;         
  43.           }
  44.         )
  45.  
  46.       streampos( long _o )
  47.         _INLINE_FUNC(
  48.           // Initialize as an offset '_o'.
  49.           //    Zero and EOF are the only valid  
  50.           //    initializers for file streampos's.
  51.           {
  52.           _is_offset = 1;
  53.           _offset = _o;
  54.           }
  55.         )
  56.  
  57.       operator long() 
  58.         _INLINE_FUNC(
  59.           // treat it as an offset, even if it's not.
  60.           {
  61.           return _offset + _fpos;
  62.           }
  63.         )
  64.  
  65.       fpos_t* fpos()
  66.         _INLINE_FUNC(
  67.           // Set the streampos to a fpos kind of streampos.
  68.           // Return a pointer to the contained fpos.
  69.           // A typical use of this function is
  70.           //        ::fsetpos( x_file, pos.fpos() );
  71.           //   which sets the 
  72.           {
  73.           return &_fpos;
  74.           }
  75.        )
  76.  
  77.       unsigned short _is_offset;
  78.       long _offset;
  79.       fpos_t _fpos;
  80.   
  81.     };
  82.  
  83. #ifndef zapeof
  84. #define zapeof(c) ((c)&UCHAR_MAX)
  85. #endif
  86.  
  87.  
  88. class ios {
  89.     public:
  90.       friend class Iostream_init;
  91.  
  92.       // State flags
  93.       enum io_state  { goodbit  = 0x00,   // no problems
  94.                        eofbit   = 0x01,   // end of file
  95.                        failbit  = 0x02,   // invalid format (i/o ok)
  96.                        badbit   = 0x04,   // i/o operation failed
  97.                        hardfail = 0x80    // unrecoverable error
  98.                        };
  99.  
  100.       // Open mode flags
  101.       enum open_mode { in        = 0x01,  // open for input
  102.                        out       = 0x02,  // open for output
  103.                        ate       = 0x04,  // open, seek to eof
  104.                        app       = 0x08,  // open for append
  105.                        trunc     = 0x10,  // truncate if file exists
  106.                        nocreate  = 0x20,  // open fails if file dont exists
  107.                        noreplace = 0x40,  // open fails if file already exists
  108.                        binary    = 0x80   // open binary file
  109.                        };
  110.  
  111.  
  112.       // Seek flags
  113.       enum seek_dir  { beg, cur, end };
  114.  
  115.  
  116.  
  117.       // Format flags
  118.       enum {
  119.         skipws     = 0x0001,   // skip whitespace on input
  120.  
  121.         left       = 0x0002,   // left-adjust output
  122.         right      = 0x0004,   // right-adjust output
  123.         internal   = 0x0008,   // padding after sign or base indicator
  124.  
  125.         dec        = 0x0010,   // decimal conversion
  126.         oct        = 0x0020,   // octal conversion
  127.         hex        = 0x0040,   // hexidecimal conversion
  128.  
  129.         showbase   = 0x0080,   // use base indecator on output
  130.         showpoint  = 0x0100,   // force decimal point (for floating output)
  131.         uppercase  = 0x0200,   // use upercase letters during output
  132.         showpos    = 0x0400,   // add + to positive integers
  133.  
  134.         scientific = 0x0800,   // use 1.2345e2 notation
  135.         fixed      = 0x1000,   // use 123.45   notation
  136.  
  137.         unitbuf    = 0x2000,   // flush all streams after insertion
  138.         stdio      = 0x4000,   // flush stdout, stderr after insertion
  139.         _firstfree = 0x8000    // first free formatting bit
  140.         };
  141.  
  142.        static const _ulong basefield;      // dec | oct | hex
  143.        static const _ulong adjustfield;    // left | right | internal
  144.        static const _ulong floatfield;     // scientific | fixed
  145.  
  146.  
  147.       // Constructors and destructors
  148.       ios( streambuf* _buf)
  149.         _INLINE_FUNC(
  150.           // set up streambuf as the buffer
  151.           {
  152.           init( _buf );
  153.           }
  154.         )
  155.   
  156.       virtual ~ios() _INLINE_FUNC({ delete [] x_user; })
  157.  
  158.       _ulong flags() 
  159.         _INLINE_FUNC(
  160.           // Return the current format flags
  161.           {
  162.           return x_flags; 
  163.           }
  164.         )
  165.  
  166.       _ulong flags( _ulong _f )
  167.         _INLINE_FUNC(
  168.           // Set format flags to 'f', return prev. flags
  169.           {
  170.           _ulong prev = x_flags;
  171.           x_flags = _f;
  172.           return prev;
  173.           }
  174.         )
  175.  
  176.       _ulong setf(_ulong _field)
  177.         _INLINE_FUNC(
  178.          // set flags set in field, return prev. values
  179.          {
  180.          _ulong prev = x_flags & _field;
  181.          x_flags |= _field;
  182.          return prev;
  183.          }
  184.         )
  185.  
  186.       _ulong unsetf(_ulong _field)
  187.         _INLINE_FUNC(
  188.           // clear flags set in field, return prev. values
  189.          {
  190.          _ulong prev = x_flags & _field;
  191.          x_flags &= ~_field;
  192.          return prev;
  193.          }
  194.        )
  195.  
  196.       _ulong setf(_ulong _setbits, _ulong _field)
  197.         _INLINE_FUNC(
  198.           // set flags set in field to values specified in setbits,
  199.           // ret. prev.
  200.          {
  201.          _ulong prev = x_flags & _field;
  202.          x_flags &= ~_field;
  203.          x_flags |= (_setbits & _field);
  204.          return prev;
  205.          }
  206.        )
  207.  
  208.       int      width()
  209.         _INLINE_FUNC(
  210.           // return the value of the width field
  211.           { return x_width; }
  212.         )
  213.  
  214.       int      width( int _w )
  215.         _INLINE_FUNC(
  216.          // set the value of the width field, return prev
  217.          {
  218.          int prev = x_width;
  219.          x_width = (short)_w;
  220.          return prev;
  221.          }
  222.        )
  223.  
  224.       ostream* tie() 
  225.         _INLINE_FUNC(
  226.           // return the tie'd ostream
  227.           { return x_tie; }
  228.         )
  229.  
  230.       ostream* tie( ostream* _s )
  231.         _INLINE_FUNC(
  232.           // Tie 's' to this ios
  233.           {
  234.           ostream* prev = x_tie;
  235.           x_tie = _s;
  236.           return prev;
  237.           }
  238.         )
  239.  
  240.       char fill()
  241.         _INLINE_FUNC(
  242.           // return the fill character
  243.           { return x_fill; }
  244.         )
  245.  
  246.       char fill( char _c )
  247.         _INLINE_FUNC(
  248.           // set the fill character, return prev.
  249.           {
  250.           char prev = x_fill;
  251.           x_fill = _c;
  252.           return prev;
  253.           }
  254.         )
  255.  
  256.       int precision() 
  257.         _INLINE_FUNC(
  258.           // return the precision value
  259.           { return x_precision; }
  260.         )
  261.  
  262.       int precision( int _w )
  263.         _INLINE_FUNC(
  264.          // set the precision value, return prev.
  265.          {
  266.          int prev = x_precision;
  267.          x_precision = (short)_w;
  268.          return prev;
  269.          }
  270.        )
  271.  
  272.       // read and set the state
  273.       int rdstate() _INLINE_FUNC({ return state; })
  274.       int eof()     _INLINE_FUNC({ return state & eofbit; })
  275.       int fail()  _INLINE_FUNC({ return state & (failbit | badbit | hardfail);})
  276.       int bad()     _INLINE_FUNC({ return state & (badbit | hardfail);})
  277.       int good()    _INLINE_FUNC({ return state == 0; })
  278.  
  279.       void clear( int _i = 0 ) _INLINE_FUNC({ state = _i; })
  280.  
  281.       operator void*()    _INLINE_FUNC( { return fail() ? 0 : this; })
  282.       int operator!()     _INLINE_FUNC( { return fail(); })
  283.  
  284.       streambuf* rdbuf() _INLINE_FUNC({ return bp; })
  285.  
  286.       // A no-op in our implementation
  287.       static void sync_with_stdio() {}
  288.  
  289.       static _ulong bitalloc()
  290.         _INLINE_FUNC(
  291.           {
  292.           _ulong temp = nextbit;
  293.           nextbit = nextbit << 1;
  294.           return temp;
  295.           }
  296.         )
  297.  
  298.       static int xalloc()
  299.         _INLINE_FUNC(
  300.           {
  301.           return nextword++;
  302.           }
  303.         )
  304.  
  305.       long&  iword( int _i ) _INLINE_FUNC({ return _uword(_i)._l;  })
  306.       void*& pword( int _i ) _INLINE_FUNC({ return _uword(_i)._vp; })
  307.  
  308.     protected:
  309.       // Allow initialization by init( streambuf* )
  310.       ios() {};
  311.       void init( streambuf* );
  312.  
  313.  
  314.  
  315.       streambuf* bp;              // The buffer to be manipulated
  316.  
  317.       int      state;             // the error state
  318.  
  319.       ostream* x_tie;             // non-NULL if this ios is tied to a stream
  320.       short    x_precision;       // the precision setting
  321.       char     x_fill;            // the fill character
  322.       short    x_width;           // the width setting
  323.  
  324.       _ulong   x_flags;           // the formatting flags
  325.  
  326.     private:
  327.        static _ulong nextbit;      // the next free formatting bit
  328.        static int nextword;        // the next free formating word
  329.  
  330.       union ios_user_union {
  331.           void* _vp;
  332.           long  _l;
  333.           };
  334.  
  335.       ios_user_union * x_user;    // the user allocated formatting words
  336.       int nuser;                  // # of userwords actual allocated
  337.                                   //    for this ios.
  338.  
  339.       ios_user_union& _uword(int i); // return referance to allocated word 'i'
  340.  
  341.       // Don't allow copying or assigning of ios'
  342.       ios(ios&);
  343.       ios& operator = ( ios& );
  344.       };
  345.  
  346. /***
  347. *  Manipulators
  348. *    example use: (format 15 in hex then decimal) 
  349. *       ostream << hex << 15 << dec << 15;
  350. *
  351. ****/
  352. #ifdef _OPTINLINE
  353. inline
  354. #endif
  355.  ios& dec( ios& _s )
  356.  _INLINE_FUNC(
  357.    {
  358.    _s.setf(ios::dec, ios::basefield);
  359.    return _s;
  360.    }
  361.  )
  362.  
  363. #ifdef _OPTINLINE
  364. inline
  365. #endif
  366. ios& hex( ios& _s )
  367.  _INLINE_FUNC(
  368.    {
  369.    _s.setf(ios::hex, ios::basefield);
  370.    return _s;
  371.    }
  372.  )
  373.  
  374. #ifdef _OPTINLINE
  375. inline
  376. #endif
  377. ios& oct( ios& _s )
  378.  _INLINE_FUNC(
  379.    {
  380.    _s.setf(ios::oct, ios::basefield);
  381.    return _s;
  382.    }
  383.  )
  384.  
  385.  
  386. /*****
  387. *
  388. *  class streambuf
  389. *     is the root class for all stream buffers.  Stream buffers
  390. *     act as an interface between where characters can be
  391. *     put and/or fetched.  Classes derived from 'streambuf'
  392. *     specify what happens when a character is put or fetched
  393. *     from the stream buffer. A streambuf is almost never
  394. *     used directly (classes derived from it are used instead),
  395. *     but more often acts a interface specification for derived
  396. *     classes.
  397. *
  398. ***/
  399.  
  400.  
  401.  
  402. class streambuf {
  403.     public:
  404.       // The constructor should be protected but are not for
  405.       // compatibility with older versions of streams.  Instead
  406.       // use a particular base class.
  407.       streambuf();
  408.                // Create a streambuf with no specific buffer.
  409.  
  410.       streambuf( char* p, int l );
  411.           
  412.       virtual ~streambuf()
  413.         _INLINE_FUNC(
  414.           {
  415.           if ( alloc )
  416.               delete [] x_base;
  417.           }
  418.         )
  419.  
  420.       int  in_avail()
  421.         _INLINE_FUNC(
  422.           // The number of characters currently in the get buffer
  423.           // (that have been read from the source but not fetched).
  424.           { return x_egptr - x_gptr; }
  425.         )
  426.  
  427.       int  out_waiting()
  428.         _INLINE_FUNC(
  429.           // The number of characters currently in the put buffer
  430.           // (that have not yet been sent to the sink).
  431.           { return x_pptr - x_pbase; }
  432.         )
  433.  
  434.  
  435.       int  sbumpc()
  436.         _INLINE_FUNC(
  437.           // Move the get pointer forward one character.
  438.           // Return the moved over character.
  439.           {
  440.           return ( in_avail() != 0 || underflow() != EOF )
  441.                 ? (unsigned char) (*x_gptr++)
  442.                 : EOF;
  443.           }
  444.         )
  445.  
  446.       int  sgetc()
  447.         _INLINE_FUNC(
  448.           // Return the character at the get pointer.
  449.           // Don't move the get pointer.
  450.           {
  451.           return ( in_avail() != 0 )
  452.                ? (unsigned char) (*x_gptr)
  453.                : underflow();
  454.           }
  455.         )
  456.  
  457.       int  sgetn( char* s, int n )
  458.         _INLINE_FUNC(
  459.           // Fill 's' with 'n' characters (if possible).
  460.           // Return the number of gotten characters.
  461.           {
  462.           if ( n <= ( x_egptr - x_gptr ) )
  463.               {
  464.               memcpy( s, x_gptr, n );
  465.               gbump( n );
  466.               return n;
  467.               }
  468.           else 
  469.               return xsgetn( s, n );
  470.           }
  471.        )
  472.  
  473.       int  snextc()
  474.         _INLINE_FUNC(
  475.           // Move the get pointer forward one character.
  476.           // Return the character at the new position.
  477.           {
  478.           if ( sbumpc() == EOF )
  479.               return EOF;
  480.           else
  481.               return sgetc();
  482.           }
  483.        )
  484.  
  485.       void stossc() _INLINE_FUNC({ sbumpc(); })
  486.                // Move the get pointer forward one character.
  487.  
  488.       int  sputbackc( char c )
  489.         _INLINE_FUNC(
  490.           // Move the get pointer back one character.
  491.           {
  492.           return ( x_eback < x_gptr )
  493.                      ? (unsigned char) (*--x_gptr = c)
  494.                      : pbackfail( (unsigned char) c);
  495.           }
  496.         )
  497.  
  498.       int  sputc( int c )
  499.         _INLINE_FUNC(
  500.           // Put 'c' in the position after the put pointer
  501.           // then move the put pointer past that character.
  502.           // Return 'c', or if error return EOF.
  503.           {
  504.           return ( x_pptr >= x_epptr )
  505.               ? overflow( c )
  506.               : (unsigned char) (*x_pptr++ = (char)c);
  507.           }
  508.         )
  509.  
  510.       int  sputn( const char* s, int n )
  511.         _INLINE_FUNC(
  512.           // Put 'n' characters after the put pointer.
  513.           // Move put pointer past them.
  514.           // Return number of character successfully put.
  515.           {
  516.           if ( n <= ( x_epptr - x_pptr ) )
  517.               {
  518.               memcpy( x_pptr, s, n );
  519.               pbump( n );
  520.               return n;
  521.               }
  522.           else
  523.               return xsputn( s, n );
  524.           }
  525.         )
  526.  
  527.       virtual int sync()
  528.         _INLINE_FUNC(
  529.           // Send any characters in the put buffer to the sink.
  530.           // Send any characters in the get area back to the source.
  531.           // Return 0 if successful, EOF if failure.
  532.           // The default version fails if in_avail or out_waiting
  533.           {
  534.           return ( in_avail() == 0 && out_waiting() == 0 )
  535.               ? 0 : EOF;
  536.           }
  537.         )
  538.  
  539.       virtual streampos seekoff( streamoff, 
  540.                                  ios::seek_dir,
  541.                                  int = ios::in|ios::out )
  542.         _INLINE_FUNC(
  543.           // Set the get and/or put pointers to a new position.
  544.           // Return the new position or EOF if error.
  545.           {
  546.           return EOF;
  547.           }
  548.         )
  549.  
  550.       virtual streampos seekpos( streampos _p, 
  551.                                  int _m = ios::in|ios::out )
  552.         _INLINE_FUNC(
  553.           // Set the get and/or put pointers to a new position.
  554.           // Return the new position or EOF if error.
  555.           {
  556.           return seekoff( streamoff(_p), ios::beg, _m );
  557.           }
  558.         )
  559.  
  560.  
  561.       virtual streambuf* setbuf( char*, size_t );
  562.                // Offer a buffer area to be used for the get and/or put areas.
  563.  
  564.    protected:
  565.       // The functions in this section are for use by classes derived from
  566.       // streambuf to implement a particular kind of stream buffer.
  567.       // 
  568.       // Conceptually a stream buffer consists of two optional areas:
  569.       //     a get area - characters waiting to be fetched by the user
  570.       //     a put area - characters put by the user.
  571.  
  572.  
  573.  
  574.  
  575.       // The following functions return pointers to the get and put
  576.       // areas for the stream buffer.  They may be null indicating
  577.       // that there is not (or not currently) a get or put area.
  578.  
  579.       char* pbase()
  580.         _INLINE_FUNC(
  581.           // First character position in the put area.
  582.           { return x_pbase; }
  583.         )
  584.  
  585.       char* pptr()
  586.         _INLINE_FUNC(
  587.           // Character position where the next put character will go to.
  588.           { return x_pptr; }
  589.         )
  590.  
  591.       char* epptr()
  592.         _INLINE_FUNC(
  593.           // Character position after the last position in the put area.
  594.           { return x_epptr; }
  595.         )
  596.  
  597.       char* eback()
  598.         _INLINE_FUNC(
  599.           // First character position in the get area.
  600.           { return x_eback; }
  601.         )
  602.  
  603.       char* gptr()
  604.         _INLINE_FUNC(
  605.           // Character position from which the next fetched character
  606.           // will come from.
  607.           { return x_gptr; }
  608.         )
  609.  
  610.       char* egptr()
  611.         _INLINE_FUNC(
  612.           // Character position after the last position in the put area.
  613.           { return x_egptr; }
  614.         )
  615.  
  616.       void setp(char* p, char* ep);
  617.           // Sets pbase() and pptr() to 'p' and epptr() to 'ep'.
  618.           // Required: p <= ep
  619.           // They may both be NULL.
  620.  
  621.           
  622.       void  setg(char* eb,char* g, char* eg);
  623.           // Sets eback() to 'eb'.
  624.           // Sets gptr() to 'g'.
  625.           // Sets egptr() to 'eg'.
  626.           // Required: (eb <= g) and (g <= eg)
  627.           // They may all be NULL.
  628.  
  629.  
  630.  
  631.       // The following functions provide for a place to store an array
  632.       // that can be used for the get and/or put areas.  This array
  633.       // is called the reserve area.  Stream buffers are not required
  634.       // to use these functions.
  635.  
  636.  
  637.       char* base()
  638.         _INLINE_FUNC(
  639.           // The beginning of a character array (buffer).
  640.           { return x_base; }
  641.         )
  642.  
  643.       char* ebuf()
  644.         _INLINE_FUNC(
  645.           // The end of the same array.
  646.           { return x_base + x_blen; }
  647.         )
  648.  
  649.       int   blen()
  650.         _INLINE_FUNC(
  651.           // ebuf() - base().
  652.           { return x_blen; }
  653.         )
  654.  
  655.       void setb(char* b, char* eb, int a = 0 );
  656.           // Set base() to 'b'.
  657.           // Set ebuf() to 'eb'.
  658.           // If 'a' is not zero then
  659.           // the reserve area will be deleted by a call to
  660.           // operator delete() the next time setb() is called
  661.           // or when this streambuf is destroyed.
  662.  
  663.       int allocate()
  664.         _INLINE_FUNC(
  665.           // Allocate a reserve area if needed:
  666.           //     if base() is NULL and unbuffered() is 0 then
  667.           //        return doallocate();
  668.           //     otherwise
  669.           //        return 0;
  670.           //
  671.           // This function is commonly needed by derived classes
  672.           // in their overflow() and underflow() functions
  673.           // (and maybe in other functions).  It is provided
  674.           // here for convenience.
  675.           {
  676.           if ( x_base == 0 && x_unbuf == 0 )
  677.               return doallocate() == EOF ? EOF : 1;
  678.           else
  679.               return 0;
  680.           }
  681.         )
  682.  
  683.       int   unbuffered() _INLINE_FUNC({ return x_unbuf; })
  684.       void  unbuffered( int unb ) _INLINE_FUNC({ x_unbuf = (char)unb; })
  685.           // These two functions respectively test and set the flag
  686.           // used by allocate().
  687.  
  688.  
  689.       // The following functions are used to specialize a stream buffer.
  690.       // 
  691.       // Usualy a class derived from streambuf will override at least
  692.       // overflow() and underflow(), although it may override all or
  693.       // none of them.
  694.  
  695.       virtual int overflow( int c = EOF );
  696.           // Called when the put area is full (or non-existent),
  697.           // although it may be called at other times.
  698.           // It should return EOF only to indicate errors.
  699.           //
  700.           // The purpose of this function is to send characters
  701.           // to the ultimate sink for this stream buffer.
  702.           //
  703.           // Commonly this function will add 'c' to the end of the
  704.           // put area if there is room; otherwise it will consume any
  705.           // characters in the put area as well as 'c', and reset
  706.           // the put area using setp().
  707.           //
  708.           // The default (streambuf) version of this function:
  709.           //     First calls allocate(), if it returns EOF then
  710.           //         streambuf::overflow() returns EOF.
  711.           //     if 'c' == EOF then
  712.           //         returns UCHAR_MAX
  713.           //     otherwise
  714.           //         'c' is added to the put area if there is room for it
  715.           //         and returns 'c'
  716.  
  717.       virtual int underflow();
  718.           // Called when the get area is empty (or non-existent),
  719.           // although it may be called at other times.
  720.           // It should return EOF to indicate errors or end of input,
  721.           // otherwise it should
  722.           //    1) insure that the get area contains at least one character
  723.           //    2) return the first character in that area.
  724.           //
  725.           // The purpose of this function is to provide characters
  726.           // from the ultimate source of this stream buffer.
  727.           //
  728.           // Commonly this function:
  729.           //     if in_avail() == 0
  730.           //         fill the get area with new characters
  731.           //         and reset the get area using setg().
  732.           //     always return *gptr().
  733.           //
  734.           // The default (streambuf) version of this function
  735.           // just returns EOF.
  736.           //
  737.  
  738.       virtual int xsputn(const char* s,int n);
  739.           // This function is called by sputn() if there is not
  740.           // enough room in the put area for 'n' characters.  It
  741.           // may also be called at other times.  It should return
  742.           // a value within 0 to 'n'-1 to indicate errors; 'n' otherwise.
  743.           //
  744.           // The intention is the same as overflow().
  745.           //
  746.           // The default (streambuf) version of this function calls
  747.           // streambuf::sputc() for each character in 's'.
  748.  
  749.       virtual int xsgetn(char*  s,int n);
  750.           // This function is called by sgetn() if there are not
  751.           // 'n' characters in the get area.  It may also be called at
  752.           // other times.  It should return a value within 0 to 'n'-1
  753.           // to indicate errors or end of input; 'n' otherwise.
  754.           //
  755.           // The intention is the same as underflow().
  756.           //
  757.           // The default (streambuf) version of this function calls
  758.           // streambuf::sbumpc() for each character in 's'.
  759.  
  760.  
  761.       virtual int pbackfail( int c ) _INLINE_FUNC({ return EOF; }
  762.           // Called by sputbackc() when eback() == gptr(). It may also
  763.           // be called at other times.
  764.           //
  765.           // It should reset the get area pointers so that gptr() is
  766.           // moved back one character, and so that gptr() points to 'c'.
  767.           // It may move the get area to accomplish this.
  768.           // It may assume 'c' is the same as the character before the
  769.           // get pointer.
  770.           //
  771.           // To indicate errors (including inability to do putback) this
  772.           // function should return EOF.
  773.           //
  774.           // The default (streambuf) version of this function returns EOF.
  775.       )
  776.  
  777.       virtual int doallocate();
  778.           // Called by allocate() if base() == NULL and unbuffered() == 0.
  779.           // It may also be called at other times.
  780.           // It should either set up a reserve area using setb() and
  781.           // return 0 or return EOF.
  782.           //
  783.           // The intention is that this function set up the reserve
  784.           // area (the base() and ebuf() pointers) for use by overflow()
  785.           // and/or underflow().  It is not required that it do this.
  786.           //
  787.           // The default (streambuf) version of this function attempts
  788.           // to allocate a buffer using operator new().  If this fails
  789.           // this function returns EOF.
  790.  
  791.  
  792.  
  793.       // The following functions are provided for more convienient
  794.       // manipulation to stream buffers by classes derived from streambuf.
  795.  
  796.       void  pbump( int n ) _INLINE_FUNC({ x_pptr += n; })
  797.       void  gbump( int n ) _INLINE_FUNC({ x_gptr += n; })
  798.           // These functions move pptr() and gptr() respectively.
  799.           // 'n' may be any integer.  These functions do no bounds
  800.           // checking.
  801.  
  802.       static const char* _modestr( int mode );
  803.           // convert a combination of open_mode bits to a 
  804.           //   mode string for fopen or afopen.  
  805.  
  806.     private:
  807.       char* x_base;
  808.  
  809.       char* x_pbase;
  810.       char* x_pptr;
  811.       char* x_epptr;
  812.  
  813.       char* x_eback;
  814.       char* x_gptr;
  815.       char* x_egptr;
  816.  
  817.       long  x_blen;
  818.  
  819.       char  alloc;
  820.       char  x_unbuf;
  821.     
  822.       static char _dummy;
  823.     };
  824.  
  825.  
  826. /*
  827.  
  828. class istream
  829.  
  830.    is the root base for those classes that only do input.
  831.    It includes all the basic extraction functions on basic
  832.    C++ types, as well as a number of unformatted input
  833.    functions, as well as functions that allow moving the file
  834.    position pointer.
  835.  
  836. */
  837.  
  838. class istream : virtual public ios {
  839.     public:
  840.       istream( streambuf* _b ) : ios( _b ) {}
  841.           // Initializes an istream and associates a streambuf
  842.           // with it.
  843.  
  844.       virtual ~istream() {}
  845.           // Clean up the istream.
  846.  
  847.  
  848.     public:
  849.       int  ipfx( int need = 0 );
  850.           // Input prefix function:
  851.           //     This function does those things that happen
  852.           //     before each formatted operation:
  853.           //     1) If istream's error state is non-zero
  854.           //            then return 0 immediately.
  855.           //     2) If necessary, flush the ios (if any) tied to
  856.           //            this istream.  It is necessary if 'need'
  857.           //            is zero or if there are less than 'need'
  858.           //            characters available for input.
  859.           //     3) If ios::skipws is set and 'need' is 0 then
  860.           //            skip any leading white space in input
  861.           //            (return 0 if error occurs during this skipping).
  862.           //     4) Return 1.
  863.  
  864.       void isfx() {}
  865.  
  866.  
  867.       // The following functions named operator >> are called
  868.       // extraction operators.  They are formmatted input functions.
  869.       // 
  870.       // They each call ipfx(0), and do nothing else if it returns 0.
  871.       // They then extract leading characters from the input streambuf
  872.       // according to the type of their argument and formatting flags
  873.       // in the ios.  They all always return the istream.  Errors are
  874.       // indicated by setting the error flags in ios.
  875.       // 
  876.       // ios::failbit means that the characters in the input stream
  877.       //     did not match the expected input format.
  878.       // ios::badbit means that an error occured during extraction
  879.       //     of charaters from the streambuf.
  880.  
  881.       istream&  operator>>( unsigned char* _c )
  882.          _INLINE_FUNC({ return *this >> (char*)_c; })
  883.       istream&  operator>>( signed char* _c )
  884.          _INLINE_FUNC({ return *this >> (char*)_c; })
  885.       istream&  operator>>( char* );
  886.           // Extract characters up to the next white space character.
  887.           // The terminating whitespace character is not extracted.
  888.           // If width() is non-zero extract no more than width() - 1
  889.           // characters, and reset width() to zero.
  890.           // Add a terminating null character (this is done even if
  891.           // an error happens during extraction).
  892.  
  893.  
  894.  
  895.       istream&  operator>>( char& );
  896.       istream&  operator>>( unsigned char& );
  897.       istream&  operator>>( signed char& );
  898.           // Extract a single character, and store it in the argument.
  899.  
  900.  
  901.       istream&  operator>>(short&);
  902.       istream&  operator>>(unsigned short&);
  903.  
  904.       istream&  operator>>(int&);
  905.       istream&  operator>>(unsigned int&);
  906.  
  907.       istream&  operator>>(long&);
  908.       istream&  operator>>(unsigned long&);
  909.           // There may be a leading sign character (+ or -).
  910.           // If any of ios::dec, ios::oct, or ios::hex is set
  911.           //    characters will be extracted and converted
  912.           //    according to which bit is set.
  913.           // If none of the above bits is set, then these functions
  914.           //    expect one of the following formats:
  915.           //       0xhhh
  916.           //       0Xhhh
  917.           //       0ooo
  918.           //        ddd
  919.           //  Extraction stops when it reaches a non-allowable-digit.
  920.           // An allowable-digit is 0-7 for octal conversion, 0-9 for decimal
  921.           // conversion, and 0-9 and a-f and A-F for hexadecimal conversion.
  922.           // 
  923.           // ios::failbit will be set if no digits are found.
  924.  
  925.  
  926.       istream&  operator>>( float& );
  927.       istream&  operator>>( double& );
  928.       istream&  operator>>( long double& );
  929.           // Expects a C++ style floating point number.
  930.           // ios::failbit will be set if there are no digits to
  931.           // extract, or if the format is not correct.
  932.  
  933.       istream&  operator>>( streambuf* );
  934.           // All characters are extracted from the istream and inserted
  935.           // into the streambuf.  Extraction stops when an EOF is
  936.           // found in the istream.
  937.  
  938.  
  939.       // The following two functions are syntatically like extractors
  940.       // but are not.
  941.  
  942.       istream&  operator>>(istream& (*f)(istream&)) 
  943.         _INLINE_FUNC({ return (*f)(*this); })
  944.       istream&  operator>>(ios& (*f)(ios&))
  945.         _INLINE_FUNC({ (*f)(*this); return *this; })
  946.           // These two functions are for support of simple
  947.           // manipulators.  The parameter functions are called with
  948.           // the stream or ios as arguments.  It is expected
  949.           // that the functions will manipulate the stream in
  950.           // some way.
  951.  
  952.       // The following functions are the unformatted input functions.
  953.       // They each call ipfx(1) first, and do nothing else if it
  954.       // returns zero.
  955.  
  956.       istream&  get(          char* c, int len, char delim='\n');
  957.           // Extract up to 'len'-1 characters.
  958.           // Extraction stops when it reaches a 'delim' character (delim
  959.           // is not extracted), when EOF is reached, or when 'len'-1 
  960.           // characters have been found.  Store a terminating null 
  961.           // character in the array.  ios::failbit is set only if 
  962.           // EOF is reached before any characters are extracted.
  963.  
  964.       istream&  get( unsigned char* c, int len, char delim='\n')
  965.         _INLINE_FUNC(
  966.           { return get((char*)c, len, delim ); })
  967.  
  968.       istream&  get(   signed char* c, int len, char delim='\n')
  969.         _INLINE_FUNC(
  970.           { return get((char*)c, len, delim ); })
  971.  
  972.       istream&  getline( char* b, int len, char delim='\n');
  973.           // Same as get except that the terminating 'delim' character
  974.           // (if found) IS extracted.  A terminating null character is
  975.           // always stored in the array.
  976.  
  977.       istream&  getline( unsigned char* b, int len, char delim='\n')
  978.         _INLINE_FUNC(
  979.           { return getline((char*)b, len, delim); })
  980.  
  981.       istream&  getline( signed char* b, int len, char delim='\n')
  982.         _INLINE_FUNC(
  983.           { return getline((char*)b, len, delim); })
  984.  
  985.       istream&  get( streambuf& sb, char delim ='\n');
  986.           // Extract characters up to the next 'delim' character or
  987.           // EOF, and insert them into 'sb'.  'delim' is not extracted
  988.           // or inserted.  ios::failbit is set if an error occurs while
  989.           // inserting into 'sb'.
  990.  
  991.       istream&  get(  signed char& c);
  992.       istream&  get(unsigned char& c);
  993.       istream&  get(char& c);
  994.           // Extract a single character.
  995.           // ios::failbit is set if istream is already at EOF.
  996.  
  997.  
  998.       int       get();
  999.           // Extract a single character and return it.
  1000.           // EOF is returned if istream is already at EOF.
  1001.           // ios::failbit is never set.
  1002.  
  1003.       istream&  ignore( int n=1, int delim = EOF );
  1004.           // Extract up to the next 'n' characters, or up to the
  1005.           // next 'delim' character.
  1006.           // ios::failbit is never set.
  1007.  
  1008.       istream&  read(unsigned char* s, int n)
  1009.         _INLINE_FUNC( { return read((char*)s, n ); })
  1010.       istream&  read(  signed char* s, int n)
  1011.         _INLINE_FUNC( { return read((char*)s, n ); })
  1012.       istream&  read(         char* s, int n);
  1013.           // Extract the next 'n' characters and store them
  1014.           // into the array pointed to by 's'.
  1015.           // ios::failbit is set if EOF is reached before 'n' characters
  1016.           // are extracted.
  1017.  
  1018.       int       gcount() 
  1019.         _INLINE_FUNC({ return x_gcount; })
  1020.           // Returns the number of characters extracted by the last
  1021.           // unformatted extraction function.  Formatted extraction
  1022.           // functions may change the value of this function in
  1023.           // unexpected ways.
  1024.  
  1025.       int       peek();
  1026.           // Returns EOF if ipfx(1) returns 0 or if stream is at EOF.
  1027.           // Otherwise returns next character in stream without
  1028.           // extracting it.
  1029.  
  1030.       istream&  putback(char c)
  1031.         _INLINE_FUNC(
  1032.           // Do nothing if error state is not good.
  1033.           // Move the get pointer of the streambuf back one character.
  1034.           // 'c' must be the character before the get pointer before
  1035.           // this function is called ('c' must be the character
  1036.           // being backed up over).  ios::badbit will be set if
  1037.           // the streambuf cannot move the get pointer back.
  1038.           {
  1039.           if ( !state )
  1040.               rdbuf()->sputbackc(c);
  1041.           return *this;
  1042.           }
  1043.        )
  1044.  
  1045.       int       sync()
  1046.         _INLINE_FUNC(
  1047.         { return rdbuf()->sync(); }
  1048.           // Calls sync() on the associated streambuf.
  1049.           // Returns whatever the streambuf call returns.
  1050.         )
  1051.  
  1052.       istream&  seekg( streampos p )
  1053.         _INLINE_FUNC(
  1054.           // Move the get pointer of the associated streambuf.
  1055.           // 'p' is a value returned by a previous tellg().
  1056.           {
  1057.           clear(~ios::eofbit & rdstate());
  1058.           rdbuf()->seekpos(p, ios::in);
  1059.           return *this;
  1060.           }
  1061.         )
  1062.  
  1063.       istream&  seekg(streamoff o, ios::seek_dir d)
  1064.         _INLINE_FUNC(
  1065.           // Move the get pointer of the associated streambuf.
  1066.           // 'o' and 'd' are explained in streambuf::seekoff().
  1067.           {
  1068.           clear(~ios::eofbit & rdstate());
  1069.           rdbuf()->seekoff(o, d, ios::in);
  1070.           return *this;
  1071.           }
  1072.        )
  1073.  
  1074.       streampos tellg()
  1075.         _INLINE_FUNC(
  1076.           // Return the current streampos of the get pointer of
  1077.           // the associated streambuf.
  1078.           {
  1079.           return rdbuf()->seekoff( 0, ios::cur, ios::in );
  1080.           }
  1081.         )
  1082.  
  1083.     protected:
  1084.  
  1085.       istream() : ios() {}
  1086.           // Initialize istream.  Call the defualt constructor for
  1087.           // the ios.  To be used by constructors for classes derived
  1088.           // from this one.  Don't use the public constructor, which
  1089.           // is only for use when istream is not used as a base.
  1090.           // Initialize the streambuf pointer by directly calling
  1091.           // ios::ios(streambuf*) in the mem-initializer list of
  1092.           // your constructors, or by calling ios::init(streambuf*)
  1093.           // from within your constructors.
  1094.  
  1095.  
  1096.     private:
  1097.       int x_gcount;
  1098.       static char _buffer[100];
  1099.       int _fillbufi(int& base);
  1100.       int _fillbuff();
  1101.     };
  1102.  
  1103.  
  1104. istream& ws(istream&);
  1105.     // This function skips any leading white space in the associated
  1106.     // streambuf.
  1107.  
  1108.  
  1109.  
  1110.  
  1111. /*
  1112.  
  1113. class ostream
  1114.  
  1115.    is the root base for those classes that only do output.
  1116.    It includes all the basic insertion operators on basic
  1117.    C++ types, as well as a number of unformatted output
  1118.    operators and operators that allow moving the file position
  1119.    pointer.
  1120.  
  1121. */
  1122.  
  1123.  
  1124. class ostream : virtual public ios {
  1125.     public:
  1126.       ostream(streambuf* _b ) : ios( _b ) {}
  1127.       virtual ~ostream() {}
  1128.  
  1129.     public:
  1130.       /* The prefix and suffix functions:
  1131.          Certain operations are defined to happen either
  1132.          before or after formatted output through a ostream.
  1133.          The prefix operations are done by "ostream::opfx",
  1134.          and the suffix operations by "ostream::osfx".
  1135.       */
  1136.  
  1137.  
  1138.       int  opfx();
  1139.           /*
  1140.              Do prefix operations, return 0 if error.
  1141.  
  1142.              This function does the prefix operations for an ostream.
  1143.              In particular it does the following:
  1144.                   1) If the error state is not good
  1145.                          it returns immediately, doing nothing else.
  1146.                   2) If this stream is tied (see tie) to another
  1147.                          the other is flushed (see flush).
  1148.                   Returns 0 if error state is not good.
  1149.                           1 otherwise.
  1150.  
  1151.              By convention this function is called before
  1152.              any formatted output operation on a stream.  If it returns
  1153.              0 (meaning error state in stream) the output operation is
  1154.              not done.  Each of of the built-in inserters follows this
  1155.              convention.  Use- written formatted output functions
  1156.              should also follow this convention by calling this function
  1157.              and cheking the return code before doing any unformatted
  1158.              output.  User-written functions that do no unformatted
  1159.              output calls may also call opfx, but need not since
  1160.              all formatted output functions should already be calling
  1161.              opfx.
  1162.  
  1163.           */
  1164.  
  1165.  
  1166.       void osfx();
  1167.           /*
  1168.           Do posfix operations on stream.
  1169.  
  1170.           If ios::unitbuf is set
  1171.               flush this ostream.
  1172.           If ios::stdio is set
  1173.                flush stdout and stderr.
  1174.  
  1175.           This function should be called at the end of any
  1176.           formatted output function that does unformatted
  1177.           output on the ostream.  It need not be called
  1178.           if the last output operation on the ostream was
  1179.           formatted.
  1180.           */
  1181.  
  1182.  
  1183.       /*
  1184.       The following functions named "operator <<" are called
  1185.       inserters (because they insert values into the output stream).
  1186.  
  1187.       All inserters are formatted output operations and
  1188.       as such follow the formatted output conventions
  1189.       mentioned above.
  1190.  
  1191.       All of the inserters do the following.  First they
  1192.       call opfx(), and if it returns an error they do nothing
  1193.       else.  They then choose a representation for their argument
  1194.       based on the type and value of the argument, and based on the
  1195.       formatting flags set in the stream.  The rules for choosing
  1196.       a representation are presented below for each function.
  1197.  
  1198.       The representation is always a sequence of characters of
  1199.       some length.  Once the representation is choosen the
  1200.       it will be placed within a field that is at least ios.width()
  1201.       characters wide.  If ios.width() is zero the field will be as
  1202.       wide as the representation.  The position of the representation
  1203.       within the field is determined by the following format flags:
  1204.           ios::right
  1205.               The representation will be to the far right of
  1206.               the field (leading padding will be used).
  1207.           ios::left
  1208.               The representation will be to the far left of the
  1209.               field (trailing padding will be used).
  1210.           ios::internal
  1211.               The sign and base indicators will be to the far
  1212.               left of the field, and the digits will be on the
  1213.               far right (internal padding will be used).
  1214.  
  1215.       The rest of the field will be filled by characters whose
  1216.       value is ios.fill().
  1217.  
  1218.       Once the representation is chosen and the field padded
  1219.       to be at least ios.width() characters wide, ios.width()
  1220.       is reset to zero, and osfx() is called.
  1221.  
  1222.       All inserters indicate errors by setting state flags
  1223.       in the ostream.  They each always return a reference
  1224.       to the ostream.
  1225.  
  1226.       */
  1227.  
  1228.       ostream&  operator<<( signed char _c )  
  1229.         _INLINE_FUNC( { return *this << (char)_c; })
  1230.       ostream&  operator<<( unsigned char _c )
  1231.         _INLINE_FUNC( { return *this << (char)_c; })
  1232.       ostream&  operator<<( char );
  1233.           // This representation is the value of the charater
  1234.           // treated as char's.
  1235.  
  1236.       ostream&  operator<<( const unsigned char* _c ) 
  1237.         _INLINE_FUNC(
  1238.           { return *this << (const char*)_c; })
  1239.  
  1240.       ostream&  operator<<( const signed char* _c )
  1241.         _INLINE_FUNC(
  1242.           { return *this << (const char*)_c; })
  1243.  
  1244.       ostream&  operator<<( const char* );
  1245.           /*
  1246.           The representation is the sequence of pointed-to
  1247.           characters treated as plain chars, up to but not
  1248.           including a '\0' character.
  1249.           */
  1250.  
  1251.       ostream&  operator<<( short _i ) 
  1252.         _INLINE_FUNC(
  1253.           { return *this << (long)_i; })
  1254.       ostream&  operator<<( unsigned short _i )
  1255.         _INLINE_FUNC(
  1256.           { return *this << (unsigned long)_i; })
  1257.  
  1258.       ostream&  operator<<( int _i)
  1259.         _INLINE_FUNC(
  1260.           { return *this << (long)_i; })
  1261.       ostream&  operator<<( unsigned int _i )
  1262.         _INLINE_FUNC(
  1263.           { return *this << (unsigned long)_i; })
  1264.  
  1265.       ostream&  operator<<( long );
  1266.       ostream&  operator<<( unsigned long );
  1267.           /*
  1268.           The representation is a sequence of digits representing
  1269.           the value of the argument.   If the value is negative
  1270.           there will be a leading '-'.  Formatting flags within
  1271.           the ostream affect the representation as follows:
  1272.  
  1273.           ios::showpos
  1274.              if set and the value is positive, there will be
  1275.              a leading '+'.
  1276.  
  1277.           ios::dec ios::oct ios::hex
  1278.              determine the base used for the representation.
  1279.  
  1280.           ios::showbase
  1281.              if set the base of the representation will be indicated
  1282.              in the representation as follows:
  1283.                 decimal - no change to the representations.
  1284.                 octal - there will be a leading zero in the
  1285.                     digits of the representation.  If the value
  1286.                     is zero there will be only one zero digit.
  1287.                 hexadecimal - there will be a leading "0x" in
  1288.                     the digits of the representation.  If
  1289.                     ios::uppercase is set, a leading "0X" is
  1290.                     used instead.
  1291.  
  1292.              If the sign indication ('+' or '-') exists it is
  1293.              before the base indication.
  1294.           */
  1295.  
  1296.  
  1297.       ostream&  operator<<( float _f );
  1298.       ostream&  operator<<( double );
  1299.           /*
  1300.           The representation is a sequence of characters representing
  1301.           a floating point value in one of two formats.
  1302.  
  1303.           Fixed notation is "sddd.ddd" where the digits are decimal
  1304.           and 's' is optional ('+' or '-').
  1305.           The number of digits after the '.' is determined by
  1306.           ios.precision(), 6 is the default.  The decimal point
  1307.           is shown only if digits follow it.
  1308.  
  1309.           Scientific notation is "sd.dddesdd" where digits are decimal
  1310.           and 's' is optional ('+' or '-').  Their is always one
  1311.           digit before the decimal point.  The number of digits after
  1312.           the point is determined by ios.precision(), the default is 6.
  1313.           The value of the digits after the 'e' is called the exponent.
  1314.  
  1315.           The representation is affected by the following ios format
  1316.           flags:
  1317.  
  1318.           ios::fixed or ios::scientific
  1319.               determines the overall representation.  If neither
  1320.               is set then the overall format is scientific if
  1321.               the exponent would be less then -4 or greater than the
  1322.               precision.  Fixed is chosen otherwise.
  1323.  
  1324.           ios::showpoint
  1325.               if set the decimal point is always be shown followed by
  1326.               at least one digit.
  1327.               If it is NOT set and if all digits after the decimal
  1328.               point would be zero, they and the decimal point are
  1329.               dropped.
  1330.  
  1331.            ios::uppercase
  1332.                if set then the 'e' in scientific notation will be 'E'
  1333.                instead.
  1334.  
  1335.            ios::showpos
  1336.                If set then a leading '+' will be output for positive
  1337.                values.
  1338.            */
  1339.  
  1340.       ostream&  operator<<( void* );
  1341.           /*
  1342.           The value of the pointer is converted to an unsigned long
  1343.           and then represented as if ios::hex and ios::showbase
  1344.           were set.
  1345.           */
  1346.  
  1347.       ostream&  operator<<(streambuf*);
  1348.           /*
  1349.           If the stream state is good, all the characters in
  1350.           the argument are fetched from it, and inserted into
  1351.           the output stream.  No padding is done.
  1352.           */
  1353.  
  1354.       /*
  1355.       These two functions are for support of simple
  1356.       manipulators.  The parameter functions are called with
  1357.       the stream or ios as arguments.  It is expected
  1358.       that the functions will manipulate the stream in
  1359.       some way.
  1360.       */
  1361.  
  1362.       ostream&  operator<< (ostream& (*f)(ostream&))
  1363.         _INLINE_FUNC(
  1364.           { return (*f)( *this ); }
  1365.         )
  1366.  
  1367.       ostream&  operator<< (ios& (*f)(ios&) )
  1368.         _INLINE_FUNC(
  1369.           { (*f)( *this ); return *this; }
  1370.         )
  1371.  
  1372.       /*
  1373.       The following functions are for support of unformatted
  1374.       output to a stream.  Because they are unformatted operations
  1375.       they do not call opfx() and osfx().
  1376.  
  1377.       All inserters indicate errors by setting state flags
  1378.       in the ostream.  They each always return a reference
  1379.       to the ostream.
  1380.  
  1381.       */
  1382.  
  1383.       ostream& put( char _c ) 
  1384.         _INLINE_FUNC(
  1385.           // Inserts its argument into the stream.
  1386.           {
  1387.           if ( opfx() != 0 ) 
  1388.               rdbuf()->sputc( (unsigned char) _c );
  1389.           return *this;
  1390.           }
  1391.         )
  1392.  
  1393.       ostream&  write( const signed char* _s, int _n ) 
  1394.         _INLINE_FUNC(
  1395.           { return write( (const char*)_s, _n ); })
  1396.  
  1397.       ostream&  write( const unsigned char* _s, int _n )
  1398.         _INLINE_FUNC(
  1399.           { return write( (const char*)_s, _n ); })
  1400.  
  1401.       ostream&  write( const char* _s, int _n )
  1402.         _INLINE_FUNC(
  1403.          // Inserts 'n' characters starting at 's' into the stream.
  1404.          // The characters are treated as plain chars independent
  1405.          // of their actual type.
  1406.          {
  1407.          if ( opfx() != 0 ) 
  1408.              rdbuf()->sputn( _s, _n );
  1409.          return *this;
  1410.          }
  1411.        )
  1412.  
  1413.       ostream&  flush()
  1414.         _INLINE_FUNC(
  1415.           {
  1416.           rdbuf()->sync();
  1417.           return *this;
  1418.           }
  1419.         )
  1420.  
  1421.       streampos tellp()
  1422.         _INLINE_FUNC(
  1423.          // Returns the stream's current put pointer position.
  1424.          { return rdbuf()->seekoff( 0, ios::cur, ios::out ); }
  1425.         )
  1426.  
  1427.       ostream&  seekp( streampos _p, ios::seek_dir = ios::beg )
  1428.         _INLINE_FUNC(
  1429.          // Repositions the stream's put pointer.
  1430.          // See streambuf::seekpos.
  1431.         {
  1432.         rdbuf()->seekpos( _p, ios::out );
  1433.         return *this;
  1434.         }
  1435.        )
  1436.  
  1437.       ostream&  seekp( streamoff _o, ios::seek_dir _d )
  1438.         _INLINE_FUNC(
  1439.          // Repositions the stream's put pointer.
  1440.          // See streambuf::seekoff 
  1441.         {
  1442.         rdbuf()->seekoff( _o, _d, ios::out );
  1443.         return *this;
  1444.         }
  1445.        )
  1446.  
  1447.  
  1448.     protected:
  1449.  
  1450.       ostream() : ios() {}
  1451.  
  1452.     private:
  1453.  
  1454.       void _output_integer( int, unsigned long, int = 0 );
  1455.       static char _dummy;
  1456.  
  1457.     };
  1458.  
  1459.  
  1460. // The manipulators
  1461. //  example: 
  1462. //     cout << flush;
  1463. //     cout << endl;
  1464. //
  1465.  
  1466. #ifdef _OPTINLINE
  1467. inline
  1468. #endif
  1469. ostream& flush( ostream& _o )
  1470.   _INLINE_FUNC(
  1471.     // Calls o.flush().
  1472.     {
  1473.     _o.flush();
  1474.     return _o;
  1475.     }
  1476.   )
  1477.  
  1478. #ifdef _OPTINLINE
  1479. inline
  1480. #endif
  1481. ostream& endl( ostream& _o )
  1482.   _INLINE_FUNC(
  1483.     // Inserts a '\n' character into ostream.
  1484.     {
  1485.     _o << '\n' << flush;
  1486.     return _o;
  1487.     }
  1488.   )
  1489.  
  1490. #ifdef _OPTINLINE
  1491. inline
  1492. #endif
  1493. ostream& ends( ostream& _o )
  1494.   _INLINE_FUNC(
  1495.     // Inserts a '\0' character into ostream.
  1496.     {
  1497.     _o << '\0';
  1498.     return _o;
  1499.     }
  1500.   )
  1501.  
  1502. /*
  1503.  
  1504. class iostream
  1505.     is both an istream and an ostream, and includes all the
  1506.     operations of both subclasses.
  1507.  
  1508.     It adds only constructors of its own.
  1509. */
  1510.  
  1511. class iostream : public ostream, public istream {
  1512.  
  1513.     public:
  1514.       iostream( streambuf* _b ) : ios(_b), istream(), ostream() {}
  1515.       virtual ~iostream() {}
  1516.  
  1517.     protected:
  1518.       iostream() : istream(), ostream() {}
  1519.  
  1520.     private:
  1521.       static char _dummy;
  1522.     };
  1523.  
  1524.  
  1525. class istream_withassign : public istream
  1526.     {
  1527.     public:
  1528.       istream_withassign() : ios( 0 ) {}
  1529.       istream_withassign( streambuf* _b ) : ios( _b ) {}
  1530.       istream_withassign( istream& _i ) : ios( _i.rdbuf() ) {}
  1531.       virtual ~istream_withassign() {}
  1532.       istream_withassign& operator = ( streambuf* _b ) 
  1533.         _INLINE_FUNC(
  1534.           { init( _b ); return *this; })
  1535.       istream_withassign& operator = ( istream& _i ) 
  1536.         _INLINE_FUNC(
  1537.           { init( _i.rdbuf() ); return *this; })
  1538.     private:
  1539.       static char _dummy;
  1540.     };
  1541.  
  1542. class ostream_withassign : public ostream
  1543.     {
  1544.     public:
  1545.       ostream_withassign() : ios( 0 ) {}
  1546.       ostream_withassign( streambuf* _b ) : ios( _b) {}
  1547.       ostream_withassign( ostream& _o ) : ios( _o.rdbuf() ) {}
  1548.       virtual ~ostream_withassign() {}
  1549.       ostream_withassign& operator=( streambuf* _b ) 
  1550.         _INLINE_FUNC(
  1551.           { init( _b ); return *this; })
  1552.       ostream_withassign& operator=( ostream& _o ) 
  1553.         _INLINE_FUNC(
  1554.           { init( _o.rdbuf() ); return *this; })
  1555.     private:
  1556.       static char _dummy;
  1557.     };
  1558.  
  1559. class iostream_withassign : public iostream
  1560.     {
  1561.     public:
  1562.       iostream_withassign() : ios( 0 ) {}
  1563.       iostream_withassign( streambuf* _b ) : ios( _b ) {}
  1564.       iostream_withassign( ios& _s ) : ios( _s.rdbuf() ) {}
  1565.       virtual ~iostream_withassign() {}
  1566.       iostream_withassign& operator=( streambuf* _b ) 
  1567.         _INLINE_FUNC(
  1568.           { init( _b ); return *this; })
  1569.       iostream_withassign& operator=( ios& _s ) 
  1570.         _INLINE_FUNC(
  1571.           { init( _s.rdbuf() ); return *this; })
  1572.     private:
  1573.       static char _dummy;
  1574.     };
  1575.  
  1576. class Iostream_init
  1577.     {
  1578.     public:
  1579.       Iostream_init();
  1580.       ~Iostream_init();
  1581.     };
  1582.  
  1583. static Iostream_init iostream_init;
  1584.      /* iostream_init can be __NORENT because it contains */
  1585.      /*    no data.                                       */
  1586.  
  1587. extern istream_withassign& cin;
  1588. extern ostream_withassign& cout;
  1589. extern ostream_withassign& cerr;
  1590. extern ostream_withassign& clog;
  1591.  
  1592.  
  1593. #endif /* __IOSTREAM_H */
  1594.  
  1595.