home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / INC.PAK / IOSTREAM.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  35KB  |  857 lines

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