home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / stream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  4.6 KB  |  157 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23.  
  24. #ifndef _stream_h
  25. #pragma once
  26. #define _stream_h 1
  27.  
  28. #include <File.h>
  29.  
  30. class whitespace                // a class used only to input and
  31. {                               // discard white space characters
  32.   char filler;                     
  33. };
  34.  
  35. class ostream: private File
  36. {
  37. public:
  38.            File::open;      File::close;
  39.            File::remove;    File::filedesc;  File::is_open;
  40.            File::raw;       File::put;       File::check_state;
  41.            File::iocount;   File::error;     File::name;
  42.            File::setname;   File::rdstate;   File::flush;
  43.            File::eof;       File::fail;      File::bad;
  44.            File::good;      File::clear;     File::failif;
  45.            File::setbuf;    File::writable;  File::readable;
  46.            
  47.  
  48.            ostream();
  49.            ostream(const char* filename, io_mode m, access_mode a);
  50.            ostream(const char* filename, const char* m);
  51.            ostream(int filedesc, io_mode m = io_writeonly);
  52.            ostream(FILE* fileptr);
  53.            ostream(int sz, char* buf);
  54.  
  55.            ~ostream();
  56.  
  57.   void*    operator void*();
  58.  
  59.   ostream& form(const char* fmt, ...);           
  60.  
  61.   ostream& operator << (char   c);
  62.   ostream& operator << (short  n);
  63.   ostream& operator << (unsigned short n);
  64.   ostream& operator << (int    n);
  65.   ostream& operator << (unsigned int n);
  66.   ostream& operator << (long   n);
  67.   ostream& operator << (unsigned long n);
  68.   ostream& operator << (float  n);
  69.   ostream& operator << (double n);
  70.   ostream& operator << (const char* s);
  71. };
  72.  
  73.  
  74. class istream: private File
  75. {
  76. protected:
  77.   ostream* tied_to;        // unused, but maintained for AT&T compatibility
  78.   void     _flush();
  79.  
  80. public:
  81.            File::open;      File::close;     File::get;  File::gets;
  82.            File::remove;    File::filedesc;  File::is_open;
  83.            File::raw;       File::unget;     File::getline;
  84.            File::iocount;   File::error;     File::name;
  85.            File::setname;   File::rdstate;   File::putback;
  86.            File::eof;       File::fail;      File::bad;
  87.            File::good;      File::clear;     File::failif;
  88.            File::setbuf;    File::writable;  File::readable;
  89.            File::check_state;
  90.  
  91.            istream();
  92.            istream(const char* filename, io_mode m, access_mode a);
  93.            istream(const char* filename, const char* m);
  94.            istream(int filedesc, io_mode m = io_readonly);
  95.            istream(FILE* fileptr);
  96.            istream(int sz, char* buf);
  97.  
  98.            ~istream();
  99.  
  100.   void*    operator void*();
  101.  
  102.   ostream* tie(ostream* s);
  103.  
  104.   istream& scan(const char* fmt, ...);
  105.  
  106.   istream& operator >> (char&   c);
  107.   istream& operator >> (short&  n);
  108.   istream& operator >> (unsigned short& n);
  109.   istream& operator >> (int&    n);
  110.   istream& operator >> (unsigned int& n);
  111.   istream& operator >> (long&   n);
  112.   istream& operator >> (unsigned long& n);
  113.   istream& operator >> (float&  n);
  114.   istream& operator >> (double& n);
  115.   istream& operator >> (char*   s);
  116.   istream& operator >> (whitespace& w);
  117. };
  118.  
  119. void eatwhite(istream& s);
  120.  
  121.  
  122. // pre-declared streams
  123.  
  124. extern istream  cin;             // stdin
  125. extern ostream  cout;            // stdout
  126. extern ostream  cerr;            // stderr
  127.  
  128. extern whitespace WS;            // for convenience
  129.  
  130. //#ifdef __OPTIMIZE__
  131.  
  132.  
  133. inline void* ostream::operator void*()
  134.   check_state(); return (state & (_bad|_fail))? 0 : this ; 
  135. }
  136.  
  137. inline ostream& ostream::operator<<(char   c)
  138.   put(c);  return *this;
  139. }
  140.  
  141. inline void*    istream::operator void*()
  142.   check_state(); return (state & (_bad|_fail))? 0 : this ; 
  143. }
  144.  
  145. inline void istream::_flush()
  146. {
  147.   if (tied_to) tied_to->flush();
  148. }
  149.  
  150.  
  151. //#endif
  152.  
  153. #endif
  154.