home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / IOSTREAM.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  22KB  |  744 lines

  1. //
  2. //  iostream.h    I/O streams
  3. //
  4. //  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  5. //
  6. #ifndef _IOSTREAM_H_INCLUDED
  7. #define _IOSTREAM_H_INCLUDED
  8.  
  9. #ifndef __cplusplus
  10. #error iostream.h is for use with C++
  11. #endif
  12. #ifndef _COMDEF_H_INCLUDED
  13.  #include <_comdef.h>
  14. #endif
  15.  
  16. #ifndef _WATCOM_EXCEPTION_DEFINED
  17. #define _WATCOM_EXCEPTION_DEFINED
  18. #define _WATCOM_EXCEPTION_DEFINED_
  19. struct __WATCOM_exception {
  20. #if defined(__AXP__) || defined(__PPC__)
  21.     void *__filler;
  22. #endif
  23. };
  24. #endif
  25.  
  26. // For multi-thread support.
  27. #ifndef __lock_it
  28.  
  29. class __lock;
  30.  
  31. #ifdef __SW_BM
  32. class _WPRTLINK __get_lock {
  33. public:
  34.     __get_lock( __lock * );
  35.     ~__get_lock();
  36. private:
  37.     __lock *__lk;
  38. };
  39. #define __lock_it( __l ) __get_lock __lock_name( __LINE__ )( __l )
  40. #define __lock_name( __ln ) __lock_glue( __lock__, __ln )
  41. #define __lock_glue( __pre, __lin ) __pre ## __lin
  42. #else 
  43. #define __lock_it( __l )
  44. #endif
  45. #endif
  46.  
  47. // Define EOF to be the same as that used with C, so that a user mixing
  48. // C and C++ won't get burned.
  49. #if !defined( EOF )
  50.     #define EOF (-1)
  51. #endif
  52.  
  53. // __NOT_EOF is useful for those functions that return "something other
  54. // than EOF" to indicate that everything is OK.
  55. #define __NOT_EOF 0
  56.  
  57. // Position in the stream (absolute value, 0 is first byte):
  58. typedef long streampos;
  59.  
  60. // Offset from current position in the stream:
  61. typedef long streamoff;
  62.  
  63. enum {
  64.     DEFAULT_PUTBACK_SIZE = 4,
  65.     DEFAULT_MAINBUF_SIZE = 512,
  66.     DEFAULT_BUF_SIZE     = DEFAULT_MAINBUF_SIZE + DEFAULT_PUTBACK_SIZE
  67. };
  68.  
  69. // These are referred to in class ios, but are defined later, or elsewhere:
  70. class _WPRTLINK __WATCOM_ios;
  71. class _WPRTLINK istream;
  72. class _WPRTLINK ostream;
  73. class _WPRTLINK streambuf;
  74.  
  75. // **************************** IOS ******************************************
  76. #if defined(_M_IX86)
  77.   #pragma pack(__push,1);
  78. #else
  79.   #pragma pack(__push,8);
  80. #endif
  81. class _WPRTLINK ios {
  82. public:
  83.     enum io_state {                     // Error state
  84.         goodbit = 0x00,                 // - no errors
  85.         badbit  = 0x01,                 // - operation failed, may not proceed
  86.         failbit = 0x02,                 // - operation failed, may proceed
  87.         eofbit  = 0x04                  // - end of file
  88.     };
  89.     typedef int iostate;
  90.     enum open_mode {                    // How to open a stream
  91.         in        = 0x0001,             // - open for input
  92.         out       = 0x0002,             // - open for output
  93.         atend     = 0x0004,             // - seek to end after opening
  94.         append    = 0x0008,             // - open for output, append to the end
  95.         truncate  = 0x0010,             // - discard contents after opening
  96.         nocreate  = 0x0020,             // - open only an existing file
  97.         noreplace = 0x0040,             // - open only a new file
  98.         text      = 0x0080,             // - open as text file
  99.         binary    = 0x0100,             // - open as binary file
  100.  
  101.         app       = append,             // Historical purposes
  102.         ate       = atend,
  103.         trunc     = truncate
  104.     };
  105.     typedef int openmode;
  106.     enum seek_dir {                     // Seek direction
  107.     beg      = 0x00,               // - seek from beginning
  108.     cur      = 0x01,               // - seek from current position
  109.         end       = 0x02                // - seek from end
  110.     };
  111.     typedef int seekdir;
  112.     enum fmt_flags {                    // Format flags
  113.         skipws     = 0x0001,            // - skip whitespace
  114.         left       = 0x0002,            // - align field to left edge
  115.         right      = 0x0004,            // - align field to right edge
  116.         internal   = 0x0008,            // - sign at left, value at right
  117.         dec        = 0x0010,            // - decimal conversion for integers
  118.         oct        = 0x0020,            // - octal conversion for integers
  119.         hex        = 0x0040,            // - hexadecimal conversion for integers
  120.         showbase   = 0x0080,            // - show dec/octal/hex base on output
  121.         showpoint  = 0x0100,            // - show decimal and digits on output
  122.         uppercase  = 0x0200,            // - use E,X (not e,x) on output numbers
  123.         showpos    = 0x0400,            // - use + for output positive numbers
  124.         scientific = 0x0800,            // - use scientific notation for output
  125.         fixed      = 0x1000,            // - use floating notation for output
  126.         unitbuf    = 0x2000,            // - flush stream after output
  127.         stdio      = 0x4000,            // - flush stdout/stderr after output
  128.  
  129.         #define _LAST_FORMAT_FLAG 0x00004000
  130.         #define _LAST_FLAG_BIT    0x80000000
  131.  
  132.         basefield  = dec | oct | hex,
  133.         adjustfield= left | right | internal,
  134.         floatfield = scientific | fixed,
  135.     };
  136.     typedef long fmtflags;
  137.  
  138.     class failure : public __WATCOM_exception {
  139.     iostate __cause;
  140.     public:
  141.     failure( iostate );        // - set the cause of failure
  142.     iostate cause() const;        // - query the cause of failure
  143.     };
  144.  
  145.     ios( streambuf *__sb );
  146.     ios( ios const & );
  147.     virtual ~ios();
  148.  
  149.     ios &operator = ( ios const & );
  150.         operator void * () const;
  151.     int operator !      () const;
  152.  
  153.     ostream   *tie( ostream *__ostrm );
  154.     ostream   *tie() const;
  155.     streambuf *rdbuf() const;
  156.     iostate    rdstate() const;
  157.     iostate    clear( iostate __state = 0 );
  158.     int        good() const;
  159.     int        bad()  const;
  160.     int        fail() const;
  161.     int        eof()  const;
  162.     iostate    exceptions( iostate __enable );
  163.     iostate    exceptions() const;
  164.     fmtflags   setf( fmtflags __onbits, fmtflags __mask );
  165.     fmtflags   setf( fmtflags __onbits );
  166.     fmtflags   unsetf( fmtflags __offbits );
  167.     fmtflags   flags( fmtflags __bits );
  168.     fmtflags   flags() const;
  169.     char       fill( char __fillchar );
  170.     char       fill() const;
  171.     int        precision( int __precision );
  172.     int        precision() const;
  173.     int        width( int __width );
  174.     int        width() const;
  175.     long      &iword( int __index );
  176.     void     *&pword( int __index );
  177.  
  178.     static void sync_with_stdio( void ) {};    // obsolete function
  179.  
  180.     static fmtflags bitalloc();
  181.     static int      xalloc();
  182.  
  183.     __lock *__i_lock;         // ios data member operations
  184.     static __lock *__x_lock; // xalloc/bitalloc operations
  185.  
  186. protected:
  187.     ios();
  188.  
  189.     void init( streambuf *__sb );
  190.     void setstate( ios::iostate __orbits );
  191.  
  192. private:
  193.     streambuf *__strmbuf;
  194.     ostream   *__tied_stream;
  195.     long       __format_flags;
  196.     int        __error_state;
  197.     int        __enabled_exceptions;
  198.     int        __float_precision;
  199.     int        __field_width;
  200.     void      *__xalloc_list;
  201.     char       __fill_character;
  202.  
  203.     static int       __xalloc_index;
  204.     static fmtflags  __last_format_flag;
  205.  
  206.     friend class __WATCOM_ios;
  207.     int : 0;
  208. };
  209. #pragma pack(__pop);
  210.  
  211. inline streambuf *ios::rdbuf() const {
  212.     return( __strmbuf );
  213. }
  214.  
  215. inline ios::iostate ios::rdstate() const {
  216.     return( __error_state );
  217. }
  218.  
  219. inline int ios::good() const {
  220.     return( __error_state == 0 );
  221. }
  222.  
  223. inline int ios::bad() const {
  224.     return( __error_state & ios::badbit );
  225. }
  226.  
  227. inline int ios::fail() const {
  228.     return( __error_state & (ios::failbit|ios::badbit) );
  229. }
  230.  
  231. inline int ios::eof() const {
  232.     return( __error_state & ios::eofbit );
  233. }
  234.  
  235. inline ios::iostate ios::exceptions() const {
  236.     return( __enabled_exceptions );
  237. }
  238.  
  239. inline ios::operator void * () const {
  240.     return( (void *) (fail()==0) );
  241. }
  242.  
  243. inline int ios::operator ! () const {
  244.     return( fail() );
  245. }
  246.  
  247. inline ios::fmtflags ios::setf( ios::fmtflags __onbits ) {
  248.     __lock_it( __i_lock );
  249.     ios::fmtflags __old_flags = __format_flags;
  250.     __format_flags           |= __onbits;
  251.     return( __old_flags );
  252. }
  253.  
  254. inline ios::fmtflags ios::setf( ios::fmtflags __onbits, ios::fmtflags __mask ) {
  255.     __lock_it( __i_lock );
  256.     ios::fmtflags __old_flags = __format_flags;
  257.     __format_flags           &= ~__mask;
  258.     __format_flags           |= __onbits & __mask;
  259.     return( __old_flags );
  260. }
  261.  
  262. inline ios::fmtflags ios::unsetf( ios::fmtflags __offbits ) {
  263.     __lock_it( __i_lock );
  264.     ios::fmtflags __old_flags = __format_flags;
  265.     __format_flags           &= ~__offbits;
  266.     return( __old_flags );
  267. }
  268.  
  269. inline ios::fmtflags ios::flags( ios::fmtflags __flags ) {
  270.     __lock_it( __i_lock );
  271.     ios::fmtflags __old_flags = __format_flags;
  272.     __format_flags            = __flags;
  273.     return( __old_flags );
  274. }
  275.  
  276. inline ios::fmtflags ios::flags() const {
  277.     return( __format_flags );
  278. }
  279.  
  280. inline char ios::fill( char __fillchar ) {
  281.     __lock_it( __i_lock );
  282.     char __old_fill  = __fill_character;
  283.     __fill_character = __fillchar;
  284.     return( __old_fill );
  285. }
  286.  
  287. inline char ios::fill() const {
  288.     return( __fill_character );
  289. }
  290.  
  291. inline int ios::precision( int __precision ) {
  292.     __lock_it( __i_lock );
  293.     int __old_precision = __float_precision;
  294.     __float_precision   = __precision;
  295.     return( __old_precision );
  296. }
  297.  
  298. inline int ios::precision() const {
  299.     return( __float_precision );
  300. }
  301.  
  302. inline int ios::width( int __width ) {
  303.     __lock_it( __i_lock );
  304.     int __old_width = __field_width;
  305.     __field_width   = __width;
  306.     return( __old_width );
  307. }
  308.  
  309. inline int ios::width() const {
  310.     return( __field_width );
  311. }
  312.  
  313. inline ostream *ios::tie( ostream *__ostrm ) {
  314.     __lock_it( __i_lock );
  315.     ostream *__old_tie = __tied_stream;
  316.     __tied_stream      = __ostrm;
  317.     return( __old_tie );
  318. }
  319.  
  320. inline ostream *ios::tie() const {
  321.     return( __tied_stream );
  322. }
  323.  
  324. // **************************** STREAMBUF ************************************
  325. // For compatibility with other vendors who include "streambuf" in IOSTREAM.H
  326. #ifndef _STREAMBUF_H_INCLUDED
  327.  #include <streambu.h>
  328. #endif
  329.  
  330. // **************************** ISTREAM **************************************
  331. #if defined(_M_IX86)
  332.   #pragma pack(__push,1);
  333. #else
  334.   #pragma pack(__push,8);
  335. #endif
  336. class _WPRTLINK istream : virtual public ios {
  337. public:
  338.     istream( streambuf *__sb );
  339.     istream( istream const &__istrm );
  340.     virtual ~istream();
  341.  
  342.     istream &operator = ( streambuf * __sb );
  343.     istream &operator = ( istream const &__istrm );
  344.     istream &operator >> (             char * __buf );
  345.     istream &operator >> (      signed char * __buf );
  346.     istream &operator >> (    unsigned char * __buf );
  347.     istream &operator >> (             char & __c );
  348.     istream &operator >> (      signed char & __c );
  349.     istream &operator >> (    unsigned char & __c );
  350.     istream &operator >> (     signed short & __i );
  351.     istream &operator >> (   unsigned short & __i );
  352.     istream &operator >> (       signed int & __i );
  353.     istream &operator >> (     unsigned int & __i );
  354.     istream &operator >> (      signed long & __i );
  355.     istream &operator >> (    unsigned long & __i );
  356.     istream &operator >> (   signed __int64 & __i );
  357.     istream &operator >> ( unsigned __int64 & __i );
  358.     istream &operator >> (            float & __f );
  359.     istream &operator >> (           double & __f );
  360.     istream &operator >> (      long double & __f );
  361.     istream &operator >> (        streambuf * __sb );
  362.     istream &operator >> ( ios &(*__f)( ios & ) );
  363.     istream &operator >> ( istream &(*__f)( istream & ) );
  364.  
  365.     int        ipfx( int __noskipws = 0 );
  366.     void       isfx();
  367.     int        get();
  368.     istream   &get(          char *__buf, int __len, char __delim = '\n' );
  369.     istream   &get(   signed char *__buf, int __len, char __delim = '\n' );
  370.     istream   &get( unsigned char *__buf, int __len, char __delim = '\n' );
  371.     istream   &get(          char &__c );
  372.     istream   &get(   signed char &__c );
  373.     istream   &get( unsigned char &__c );
  374.     istream   &get( streambuf &__sb, char __delim = '\n' );
  375.     istream   &getline(          char *__buf, int __len, char __delim = '\n' );
  376.     istream   &getline(   signed char *__buf, int __len, char __delim = '\n' );
  377.     istream   &getline( unsigned char *__buf, int __len, char __delim = '\n' );
  378.     istream   &ignore( int __num = 1, int __delim = EOF );
  379.     istream   &read(          char *__buf, int __len );
  380.     istream   &read(   signed char *__buf, int __len );
  381.     istream   &read( unsigned char *__buf, int __len );
  382.     istream   &seekg( streampos __position );
  383.     istream   &seekg( streamoff __offset, ios::seekdir __direction );
  384.     istream   &putback( char __c );
  385.     streampos  tellg();
  386.     int        gcount() const;
  387.     int        peek();
  388.     int        sync();
  389.  
  390. protected:
  391.     istream();
  392.     void     eatwhite();
  393.     istream &do_get( char &__c );
  394.     istream &do_rshift( char &__c );
  395.     istream &do_read( char *__buf, int __len );
  396.     int         ipfx0( void );
  397.     int         ipfx1( void );
  398.     int      do_ipfx( int __noskipws );
  399.  
  400. private:
  401.     int __last_read_length;
  402. };
  403. #pragma pack(__pop);
  404.  
  405. inline istream &istream::operator >> ( signed char *__buf ) {
  406.     return( *this >> (char *) __buf );
  407. }
  408.  
  409. inline istream &istream::operator >> ( unsigned char *__buf ) {
  410.     return( *this >> (char *) __buf );
  411. }
  412.  
  413. #ifdef __BIG_INLINE__
  414. inline istream &istream::operator >> ( char &__c ) {
  415.     __lock_it( __i_lock );
  416.     if( ipfx0() ) {
  417.         if( rdbuf()->in_avail() ) {
  418.         __c = (char)(rdbuf()->sgetchar());
  419.      } else {
  420.         do_rshift( __c );
  421.         }
  422.         isfx();
  423.     }
  424.     return( *this );
  425. }
  426. #endif
  427.  
  428. inline istream &istream::operator >> ( signed char &__c ) {
  429.     return( *this >> (char &) __c );
  430. }
  431.  
  432. inline istream &istream::operator >> ( unsigned char &__c ) {
  433.     return( *this >> (char &) __c );
  434. }
  435.  
  436. inline istream &istream::get( signed char *__buf, int __len, char __delim ) {
  437.     return( get( (char *)__buf, __len, __delim ) );
  438. }
  439.  
  440. inline istream &istream::get( unsigned char *__buf, int __len, char __delim ) {
  441.     return( get( (char *)__buf, __len, __delim ) );
  442. }
  443.  
  444. #ifdef __BIG_INLINE__
  445. inline istream &istream::get( char &__c ) {
  446.     __lock_it( __i_lock );
  447.     if( ipfx1() ) {
  448.         if( rdbuf()->in_avail() ) {
  449.         __c = (char)(rdbuf()->sgetchar());
  450.     } else {
  451.         do_get( __c );
  452.         }
  453.         isfx();
  454.     } else {
  455.     __last_read_length = 0;
  456.     }
  457.     return( *this );
  458. }
  459. #endif
  460.  
  461. inline istream &istream::get( signed char &__c ) {
  462.     return( get( (char &) __c ) );
  463. }
  464.  
  465. inline istream &istream::get( unsigned char &__c ) {
  466.     return( get( (char &) __c ) );
  467. }
  468.  
  469. inline istream &istream::getline( signed char *__buf, int __len,
  470.     char __delim ) {
  471.     return( getline( (char *)__buf, __len, __delim ) );
  472. }
  473.  
  474. inline istream &istream::getline( unsigned char *__buf, int __len,
  475.     char __delim ) {
  476.     return( getline( (char *)__buf, __len, __delim ) );
  477. }
  478.  
  479. #ifdef __BIG_INLINE__
  480. inline istream &istream::read( char *__buf, int __len ) {
  481.     __lock_it( __i_lock );
  482.     if( ipfx1() ) {
  483.         if( rdbuf()->in_avail() > __len ) {
  484.             __last_read_length = rdbuf()->sgetn( __buf, __len );
  485.         } else {
  486.         do_read( __buf , __len );
  487.     }
  488.         isfx();
  489.     } else {
  490.     __last_read_length = 0;
  491.     }
  492.     return( *this );
  493. }
  494. #endif
  495.  
  496. inline istream &istream::read( signed char *__buf, int __len ) {
  497.     return( read( (char *) __buf, __len ) );
  498. }
  499.  
  500. inline istream &istream::read( unsigned char *__buf, int __len ) {
  501.     return( read( (char *) __buf, __len ) );
  502. }
  503.  
  504. inline int istream::ipfx0( void ) {
  505.     __lock_it( __i_lock );
  506.     return( ((flags()&ios::skipws) || !good() || tie()) ? do_ipfx( 0 ) : 1);
  507. }
  508.  
  509. inline int istream::ipfx1( void ) {
  510.     __lock_it( __i_lock );
  511.     return( (!good() || tie()) ? do_ipfx( 1 ) : 1);
  512. }
  513.  
  514. inline void istream::isfx() {
  515. }
  516.  
  517. inline int istream::gcount() const {
  518.     return( __last_read_length );
  519. }
  520.  
  521. // **************************** OSTREAM **************************************
  522. #if defined(_M_IX86)
  523.   #pragma pack(__push,1);
  524. #else
  525.   #pragma pack(__push,8);
  526. #endif
  527. class _WPRTLINK ostream : virtual public ios {
  528. public:
  529.     ostream( streambuf *__sb );
  530.     ostream( ostream const &__ostrm );
  531.     virtual ~ostream();
  532.  
  533.     ostream &operator = ( streambuf *__sb );
  534.     ostream &operator = ( ostream const &__ostrm );
  535.     ostream &operator << (                char  __c );
  536.     ostream &operator << (         signed char  __c );
  537.     ostream &operator << (       unsigned char  __c );
  538.     ostream &operator << (        signed short  __s );
  539.     ostream &operator << (      unsigned short  __s );
  540.     ostream &operator << (          signed int  __i );
  541.     ostream &operator << (        unsigned int  __i );
  542.     ostream &operator << (         signed long  __l );
  543.     ostream &operator << (       unsigned long  __l );
  544.     ostream &operator << (      signed __int64  __l );
  545.     ostream &operator << (    unsigned __int64  __l );
  546.     ostream &operator << (               float  __f );
  547.     ostream &operator << (              double  __f );
  548.     ostream &operator << (         long double  __f );
  549.     ostream &operator << (                void *__p );
  550.     ostream &operator << (           streambuf *__sb );
  551.     ostream &operator << (          char const *__buf );
  552.     ostream &operator << (   signed char const *__buf );
  553.     ostream &operator << ( unsigned char const *__buf );
  554.     ostream &operator << ( ostream &(*__f)( ostream & ) );
  555.     ostream &operator << ( ios &(*__f)( ios & ) );
  556.  
  557.     int        opfx();
  558.     void       osfx();
  559.     ostream   &put(          char __c );
  560.     ostream   &put(   signed char __c );
  561.     ostream   &put( unsigned char __c );
  562.     ostream   &write(          char const *__buf, int __len );
  563.     ostream   &write(   signed char const *__buf, int __len );
  564.     ostream   &write( unsigned char const *__buf, int __len );
  565.     ostream   &flush();
  566.     ostream   &seekp( streampos __position );
  567.     ostream   &seekp( streamoff __offset, ios::seekdir __direction );
  568.     streampos  tellp();
  569.  
  570. protected:
  571.     ostream();
  572.     ostream &__outfloat( long double const & );
  573.     ostream &do_lshift( char __c);
  574.     int         do_opfx();
  575. };
  576. #pragma pack(__pop);
  577.  
  578. #ifdef __BIG_INLINE__
  579. inline ostream &ostream::operator << ( char __c ) {
  580.     __lock_it( __i_lock );
  581.     if( opfx() ) {
  582.     if( width() == 0 ) {
  583.         if( rdbuf()->sputc( __c ) == EOF ) {
  584.         setstate( ios::failbit );
  585.         }
  586.     } else {
  587.             do_lshift( __c );
  588.     }
  589.         osfx();
  590.     }
  591.     return( *this );
  592. }
  593. #endif
  594.  
  595. inline ostream &ostream::operator << ( signed char __c ) {
  596.     return( *this << (char) __c );
  597. }
  598.  
  599. inline ostream &ostream::operator << ( unsigned char __c ) {
  600.     return( *this << (char) __c );
  601. }
  602.  
  603. inline ostream &ostream::operator << ( signed short __s ) {
  604.     return( *this << (signed long) __s );
  605. }
  606.  
  607. inline ostream &ostream::operator << ( unsigned short __s ) {
  608.     return( *this << (unsigned long) __s );
  609. }
  610.  
  611. inline ostream &ostream::operator << ( signed int __i ) {
  612.     return( *this << (signed long) __i );
  613. }
  614.  
  615. inline ostream &ostream::operator << ( unsigned int __i ) {
  616.     return( *this << (unsigned long) __i );
  617. }
  618.  
  619. inline ostream &ostream::operator << ( float __f ) {
  620.     return( __outfloat( (long double)__f ) );
  621. }
  622.  
  623. inline ostream &ostream::operator << ( double __f ) {
  624.     return( __outfloat( (long double)__f ) );
  625. }
  626.  
  627. inline ostream &ostream::operator << ( long double __f ) {
  628.     return( __outfloat( __f ) );
  629. }
  630.  
  631. inline ostream &ostream::operator << ( signed char const *__buf ) {
  632.     return( *this << (char const *) __buf );
  633. }
  634.  
  635. inline ostream &ostream::operator << ( unsigned char const *__buf ) {
  636.     return( *this << (char const *) __buf );
  637. }
  638.  
  639. #ifdef __BIG_INLINE__
  640. inline ostream &ostream::put( char __c ) {
  641.     __lock_it( __i_lock );
  642.     if( opfx() ) {
  643.     if( rdbuf()->sputc( __c ) == EOF ) {
  644.         setstate( ios::failbit );
  645.     }
  646.     osfx();
  647.     }
  648.     return( *this );
  649. }
  650. #endif
  651.  
  652. inline ostream &ostream::put( signed char __c ) {
  653.     return( put( (char) __c ) );
  654. }
  655.  
  656. inline ostream &ostream::put( unsigned char __c ) {
  657.     return( put( (char) __c ) );
  658. }
  659.  
  660. #ifdef __BIG_INLINE__
  661. inline ostream &ostream::write( char const *__buf, int __len ) {
  662.     __lock_it( __i_lock );
  663.     if( opfx() ) {
  664.     if( __len  ) {
  665.         if( rdbuf()->sputn( __buf, __len ) != __len ) {
  666.         setstate( ios::failbit );
  667.         }
  668.     }
  669.     osfx();
  670.     }
  671.     return( *this );
  672. }
  673. #endif
  674.  
  675. inline ostream &ostream::write( signed char const *__buf, int __len ) {
  676.     return( write( (char const *) __buf, __len ) );
  677. }
  678.  
  679. inline ostream &ostream::write( unsigned char const *__buf, int __len ) {
  680.     return( write( (char const *) __buf, __len ) );
  681. }
  682.  
  683. inline int ostream::opfx() {
  684.     __lock_it( __i_lock );
  685.     if( !good() ) {
  686.         return 0;
  687.     } else if( tie() || ( flags() & ios::stdio ) ) {
  688.         return do_opfx();
  689.     } else {
  690.         return 1;
  691.     }
  692. }
  693.  
  694. inline void ostream::osfx() {
  695.     __lock_it( __i_lock );
  696.     if( flags() & ios::unitbuf ) {
  697.         flush();
  698.     }
  699. }
  700.  
  701. // **************************** IOSTREAM *************************************
  702. #if defined(_M_IX86)
  703.   #pragma pack(__push,1);
  704. #else
  705.   #pragma pack(__push,8);
  706. #endif
  707. class _WPRTLINK iostream : public istream, public ostream {
  708. public:
  709.     iostream( streambuf *__sb );
  710.     iostream( ios const &__strm );
  711.     virtual ~iostream();
  712.  
  713.     iostream & operator = ( streambuf *__sb );
  714.     iostream & operator = ( ios const &__strm );
  715.  
  716. protected:
  717.     iostream();
  718. };
  719. #pragma pack(__pop);
  720.  
  721. // **************************** MANIPULATORS *********************************
  722. _WPRTLINK extern ios &dec( ios & );
  723. _WPRTLINK extern ios &hex( ios & );
  724. _WPRTLINK extern ios &oct( ios & );
  725. _WPRTLINK extern istream &   ws( istream & );
  726. _WPRTLINK extern ostream & endl( ostream & );
  727. _WPRTLINK extern ostream & ends( ostream & );
  728. _WPRTLINK extern ostream &flush( ostream & );
  729.  
  730. // **************************** PREDEFINED STREAMS ***************************
  731. #ifdef M_I86HM
  732.  _WPRTLINK extern istream _WCFAR cin;
  733.  _WPRTLINK extern ostream _WCFAR cout;
  734.  _WPRTLINK extern ostream _WCFAR cerr;
  735.  _WPRTLINK extern ostream _WCFAR clog;
  736. #else
  737.  _WPRTLINK extern istream _WCNEAR cin;
  738.  _WPRTLINK extern ostream _WCNEAR cout;
  739.  _WPRTLINK extern ostream _WCNEAR cerr;
  740.  _WPRTLINK extern ostream _WCNEAR clog;
  741. #endif
  742.  
  743. #endif
  744.