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