home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / support / g++include / iostream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  7.9 KB  |  227 lines

  1. //    This is part of the iostream library, providing -*- C++ -*- input/output.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef _IOSTREAM_H
  19. #ifdef __GNUG__
  20. #pragma interface
  21. #endif
  22. #define _IOSTREAM_H
  23.  
  24. #include <streambuf.h>
  25.  
  26. class istream; class ostream;
  27. typedef ios& (*__manip)(ios&);
  28. typedef istream& (*__imanip)(istream&);
  29. typedef ostream& (*__omanip)(ostream&);
  30.  
  31. extern istream& ws(istream& ins);
  32. extern ostream& flush(ostream& outs);
  33. extern ostream& endl(ostream& outs);
  34. extern ostream& ends(ostream& outs);
  35.  
  36. class ostream : virtual public ios
  37. {
  38.     // NOTE: If fields are changed, you must fix _fake_ostream in stdstreams.C!
  39.     void do_osfx();
  40.   public:
  41.     ostream() { }
  42.     ostream(streambuf* sb, ostream* tied=NULL);
  43.     int opfx() {
  44.     if (!good()) return 0; else { if (_tie) _tie->flush(); return 1;} }
  45.     void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
  46.               do_osfx(); }
  47.     streambuf* ostreambuf() const { return _strbuf; }
  48.     ostream& flush();
  49.     ostream& put(char c) { _strbuf->sputc(c); return *this; }
  50.     ostream& put(unsigned char c) { return put((char)c); }
  51.  
  52.     ostream& write(const char *s, int n);
  53.     ostream& write(const unsigned char *s, int n) { return write((const char*)s, n);}
  54. #ifndef _G_BROKEN_SIGNED_CHAR
  55.     ostream& put(signed char c) { return put((char)c); }
  56.     ostream& write(const signed char *s, int n) { return write((const char*)s, n);}
  57. #endif
  58.     ostream& write(const void *s, int n) { return write((const char*)s, n);}
  59.     ostream& seekp(streampos);
  60.     ostream& seekp(streamoff, _seek_dir);
  61.     streampos tellp();
  62.     ostream& form(const char *format ...);
  63.     ostream& vform(const char *format, _G_va_list args);
  64.  
  65.     ostream& operator<<(char c);
  66.     ostream& operator<<(unsigned char c) { return (*this) << (char)c; }
  67. #ifndef _G_BROKEN_SIGNED_CHAR
  68.     ostream& operator<<(signed char c) { return (*this) << (char)c; }
  69. #endif
  70.     ostream& operator<<(const char *s);
  71.     ostream& operator<<(const unsigned char *s)
  72.     { return (*this) << (const char*)s; }
  73. #ifndef _G_BROKEN_SIGNED_CHAR
  74.     ostream& operator<<(const signed char *s)
  75.     { return (*this) << (const char*)s; }
  76. #endif
  77.     ostream& operator<<(const void *p);
  78.     ostream& operator<<(int n);
  79.     ostream& operator<<(unsigned int n);
  80.     ostream& operator<<(long n);
  81.     ostream& operator<<(unsigned long n);
  82. #ifdef __GNUG__
  83.     ostream& operator<<(long long n);
  84.     ostream& operator<<(unsigned long long n);
  85. #endif
  86.     ostream& operator<<(short n) {return operator<<((int)n);}
  87.     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
  88.     ostream& operator<<(double n);
  89.     ostream& operator<<(float n) { return operator<<((double)n); }
  90.     ostream& operator<<(__omanip func) { return (*func)(*this); }
  91.     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
  92.     ostream& operator<<(streambuf*);
  93. };
  94.  
  95. class istream : virtual public ios
  96. {
  97.     // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
  98.     _G_ssize_t _gcount;
  99.  
  100.     int _skip_ws();
  101.   public:
  102.     istream() { _gcount = 0; }
  103.     istream(streambuf* sb, ostream*tied=NULL);
  104.     streambuf* istreambuf() const { return _strbuf; }
  105.     istream& get(char* ptr, int len, char delim = '\n');
  106.     istream& get(unsigned char* ptr, int len, char delim = '\n')
  107.     { return get((char*)ptr, len, delim); }
  108.     istream& get(char& c);
  109.     istream& get(unsigned char& c) { return get((char&)c); }
  110.     istream& getline(char* ptr, int len, char delim = '\n');
  111.     istream& getline(unsigned char* ptr, int len, char delim = '\n')
  112.     { return getline((char*)ptr, len, delim); }
  113. #ifndef _G_BROKEN_SIGNED_CHAR
  114.     istream& get(signed char& c)  { return get((char&)c); }
  115.     istream& get(signed char* ptr, int len, char delim = '\n')
  116.     { return get((char*)ptr, len, delim); }
  117.     istream& getline(signed char* ptr, int len, char delim = '\n')
  118.     { return getline((char*)ptr, len, delim); }
  119. #endif
  120.     istream& read(char *ptr, int n);
  121.     istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
  122. #ifndef _G_BROKEN_SIGNED_CHAR
  123.     istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
  124. #endif
  125.     istream& read(void *ptr, int n) { return read((char*)ptr, n); }
  126.     istream& get(streambuf& sb, char delim = '\n');
  127.     istream& gets(char **s, char delim = '\n');
  128.     int ipfx(int need) {
  129.     if (!good()) { set(ios::failbit); return 0; }
  130.     else {
  131.       if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
  132.       if (!need && (flags() & ios::skipws)) return _skip_ws();
  133.       else return 1;
  134.     }
  135.     }
  136.     int ipfx0() { // Optimized version of ipfx(0).
  137.     if (!good()) { set(ios::failbit); return 0; }
  138.     else {
  139.       if (_tie) _tie->flush();
  140.       if (flags() & ios::skipws) return _skip_ws();
  141.       else return 1;
  142.     }
  143.     }
  144.     int ipfx1() { // Optimized version of ipfx(1).
  145.     if (!good()) { set(ios::failbit); return 0; }
  146.     else {
  147.       if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
  148.       return 1;
  149.     }
  150.     }
  151.     void isfx() { }
  152.     int get() { if (!ipfx1()) return EOF;
  153.         else { int ch = _strbuf->sbumpc();
  154.                if (ch == EOF) set(ios::eofbit);
  155.                return ch;
  156.              } }
  157.     int peek();
  158.     _G_ssize_t gcount() { return _gcount; }
  159.     istream& ignore(int n=1, int delim = EOF);
  160.     istream& seekg(streampos);
  161.     istream& seekg(streamoff, _seek_dir);
  162.     streampos tellg();
  163.     istream& putback(char ch) {
  164.     if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
  165.     return *this;}
  166.     istream& unget() {
  167.     if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
  168.     return *this;}
  169.     istream& scan(const char *format ...);
  170.     istream& vscan(const char *format, _G_va_list args);
  171. #ifdef _STREAM_COMPAT
  172.     istream& unget(char ch) { return putback(ch); }
  173.     int skip(int i);
  174. #endif
  175.  
  176.     istream& operator>>(char*);
  177.     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
  178. #ifndef _G_BROKEN_SIGNED_CHAR
  179.     istream& operator>>(signed char*p) { return operator>>((char*)p); }
  180. #endif
  181.     istream& operator>>(char& c);
  182.     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
  183. #ifndef _G_BROKEN_SIGNED_CHAR
  184.     istream& operator>>(signed char& c) {return operator>>((char&)c);}
  185. #endif
  186.     istream& operator>>(int&);
  187.     istream& operator>>(long&);
  188. #ifdef __GNUG__
  189.     istream& operator>>(long long&);
  190. #endif
  191.     istream& operator>>(short&);
  192.     istream& operator>>(unsigned int&);
  193.     istream& operator>>(unsigned long&);
  194. #ifdef __GNUG__
  195.     istream& operator>>(unsigned long long&);
  196. #endif
  197.     istream& operator>>(unsigned short&);
  198.     istream& operator>>(float&);
  199.     istream& operator>>(double&);
  200.     istream& operator>>( __manip func) {(*func)(*this); return *this;}
  201.     istream& operator>>(__imanip func) { return (*func)(*this); }
  202.     istream& operator>>(streambuf*);
  203. };
  204.  
  205.  
  206. class iostream : public istream, public ostream
  207. {
  208.     _G_ssize_t _gcount;
  209.   public:
  210.     iostream() { _gcount = 0; }
  211.     iostream(streambuf* sb, ostream*tied=NULL);
  212. };
  213.  
  214. extern istream cin;
  215. extern ostream cout, cerr, clog; // clog->rdbuf() == cerr->rdbuf()
  216.  
  217. struct Iostream_init { } ;  // Compatibility hack for AT&T library.
  218.  
  219. inline ios& dec(ios& i)
  220. { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
  221. inline ios& hex(ios& i)
  222. { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
  223. inline ios& oct(ios& i)
  224. { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
  225.  
  226. #endif /*!_IOSTREAM_H*/
  227.