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