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