home *** CD-ROM | disk | FTP | other *** search
/ ftp.uni-stuttgart.de/pub/systems/acorn/ / Acorn.tar / Acorn / acornet / dev / c / gcc / g++lib.spk / h / iostream < prev    next >
Text File  |  1993-12-07  |  8KB  |  225 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<<(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. #ifndef RISCOS
  83. #ifdef __GNUG__
  84.     ostream& operator<<(long long n);
  85.     ostream& operator<<(unsigned long long n);
  86. #endif
  87. #endif
  88.     ostream& operator<<(short n) {return operator<<((int)n);}
  89.     ostream& operator<<(unsigned short n) {return operator<<((unsigned int)n);}
  90.     ostream& operator<<(double n);
  91.     ostream& operator<<(float n) { return operator<<((double)n); }
  92.     ostream& operator<<(__omanip func) { return (*func)(*this); }
  93.     ostream& operator<<(__manip func) {(*func)(*this); return *this;}
  94.     ostream& operator<<(streambuf*);
  95. };
  96.  
  97. class istream : virtual public ios
  98. {
  99.     // NOTE: If fields are changed, you must fix _fake_istream in stdstreams.C!
  100.     _G_ssize_t _gcount;
  101.  
  102.     int _skip_ws();
  103.   public:
  104.     istream() { _gcount = 0; }
  105.     istream(streambuf* sb, ostream*tied=NULL);
  106.     streambuf* istreambuf() const { return _strbuf; }
  107.     istream& get(char* ptr, int len, char delim = '\n');
  108.     istream& get(unsigned char* ptr, int len, char delim = '\n')
  109.     { return get((char*)ptr, len, delim); }
  110.     istream& get(char& c);
  111.     istream& get(unsigned char& c) { return get((char&)c); }
  112.     istream& getline(char* ptr, int len, char delim = '\n');
  113.     istream& getline(unsigned char* ptr, int len, char delim = '\n')
  114.     { return getline((char*)ptr, len, delim); }
  115. #ifndef _G_BROKEN_SIGNED_CHAR
  116.     istream& get(signed char& c)  { return get((char&)c); }
  117.     istream& get(signed char* ptr, int len, char delim = '\n')
  118.     { return get((char*)ptr, len, delim); }
  119.     istream& getline(signed char* ptr, int len, char delim = '\n')
  120.     { return getline((char*)ptr, len, delim); }
  121. #endif
  122.     istream& read(char *ptr, int n);
  123.     istream& read(unsigned char *ptr, int n) { return read((char*)ptr, n); }
  124. #ifndef _G_BROKEN_SIGNED_CHAR
  125.     istream& read(signed char *ptr, int n) { return read((char*)ptr, n); }
  126. #endif
  127.     istream& read(void *ptr, int n) { return read((char*)ptr, n); }
  128.     // Should get() and/or peek() set failbit and/or eofbit? FIXME!
  129.     istream& get(streambuf& sb, char delim = '\n');
  130.     istream& gets(char **s, char delim = '\n');
  131.     int ipfx(int need) {
  132.     if (!good()) { set(ios::failbit); return 0; }
  133.     if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
  134.     if (!need && (flags() & ios::skipws)) return _skip_ws();
  135.     return 1;
  136.     }
  137.     int ipfx0() { // Optimized version of ipfx(0).
  138.     if (!good()) { set(ios::failbit); return 0; }
  139.     if (_tie) _tie->flush();
  140.     if (flags() & ios::skipws) return _skip_ws();
  141.     return 1;
  142.     }
  143.     int ipfx1() { // Optimized version of ipfx(1).
  144.     if (!good()) { set(ios::failbit); return 0; }
  145.     if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
  146.     return 1;
  147.     }
  148.     int get() { if (!ipfx1()) return EOF;
  149.         int ch = _strbuf->sbumpc();
  150.         if (ch == EOF) set(ios::eofbit);
  151.         return ch; }
  152.     int peek() { if (!ipfx1()) return EOF;
  153.         int ch = _strbuf->sgetc();
  154.         if (ch == EOF) set(ios::eofbit);
  155.         return ch; }
  156.     _G_ssize_t gcount() { return _gcount; }
  157.     istream& ignore(int n=1, int delim = EOF);
  158.     istream& seekg(streampos);
  159.     istream& seekg(streamoff, _seek_dir);
  160.     streampos tellg();
  161.     istream& putback(char ch) {
  162.     if (good() && _strbuf->sputbackc(ch) == EOF) clear(ios::badbit);
  163.     return *this;}
  164.     istream& unget() {
  165.     if (good() && _strbuf->sungetc() == EOF) clear(ios::badbit);
  166.     return *this;}
  167.     istream& scan(const char *format ...);
  168.     istream& vscan(const char *format, _G_va_list args);
  169. #ifdef _STREAM_COMPAT
  170.     istream& unget(char ch) { return putback(ch); }
  171.     int skip(int i);
  172. #endif
  173.  
  174.     istream& operator>>(char*);
  175.     istream& operator>>(unsigned char* p) { return operator>>((char*)p); }
  176. #ifndef _G_BROKEN_SIGNED_CHAR
  177.     istream& operator>>(signed char*p) { return operator>>((char*)p); }
  178. #endif
  179.     istream& operator>>(char& c);
  180.     istream& operator>>(unsigned char& c) {return operator>>((char&)c);}
  181. #ifndef _G_BROKEN_SIGNED_CHAR
  182.     istream& operator>>(signed char& c) {return operator>>((char&)c);}
  183. #endif
  184.     istream& operator>>(int&);
  185.     istream& operator>>(long&);
  186. #ifdef __GNUG__
  187.     istream& operator>>(long long&);
  188. #endif
  189.     istream& operator>>(short&);
  190.     istream& operator>>(unsigned int&);
  191.     istream& operator>>(unsigned long&);
  192. #ifdef __GNUG__
  193.     istream& operator>>(unsigned long long&);
  194. #endif
  195.     istream& operator>>(unsigned short&);
  196.     istream& operator>>(float&);
  197.     istream& operator>>(double&);
  198.     istream& operator>>( __manip func) {(*func)(*this); return *this;}
  199.     istream& operator>>(__imanip func) { return (*func)(*this); }
  200.     istream& operator>>(streambuf*);
  201. };
  202.  
  203.  
  204. class iostream : public istream, public ostream
  205. {
  206.     _G_ssize_t _gcount;
  207.   public:
  208.     iostream() { _gcount = 0; }
  209.     iostream(streambuf* sb, ostream*tied=NULL);
  210. };
  211.  
  212. extern istream cin;
  213. extern ostream cout, cerr, clog; // clog->rdbuf() == cerr->rdbuf()
  214.  
  215. struct Iostream_init { } ;  // Compatibility hack for AT&T library.
  216.  
  217. inline ios& dec(ios& i)
  218. { i.setf(ios::dec, ios::dec|ios::hex|ios::oct); return i; }
  219. inline ios& hex(ios& i)
  220. { i.setf(ios::hex, ios::dec|ios::hex|ios::oct); return i; }
  221. inline ios& oct(ios& i)
  222. { i.setf(ios::oct, ios::dec|ios::hex|ios::oct); return i; }
  223.  
  224. #endif /*!_IOSTREAM_H*/
  225.