00001 #ifndef STD_STREAM_HAS_BEEN_INCLUDED
00002 #define STD_STREAM_HAS_BEEN_INCLUDED
00003
00004 #include "std/support.H"
00005 #include "mem_push.H"
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 class STDdstream {
00023 public:
00024 STDdstream();
00025
00026
00027
00028
00029 STDdstream(iostream* s);
00030 STDdstream( istream* i);
00031 STDdstream( ostream* o);
00032
00033 virtual ~STDdstream () {}
00034
00035 void write(const char * const data, int count);
00036 void read ( UGAptr data, int count, int pop = 1);
00037 void flush();
00038
00039 iostream* iostr() const { return _iostream; }
00040 istream* istr() const { return _iostream ? (istream*)_iostream : _istream; }
00041 ostream* ostr() const { return _iostream ? (ostream*)_iostream : _ostream; }
00042
00043 int ascii() const { return istr() || ostr(); }
00044
00045 char peekahead();
00046 void read_open_delim();
00047 void read_close_delim();
00048
00049 void write_open_delim() { write_delim('{');if(ascii()) _indent++;}
00050 void write_close_delim() { write_delim('}');if(ascii()) _indent--;}
00051 void write_newline() { if (ascii()) {ws("\n");
00052 for (int i=0;i<_indent;i++) ws("\t"); }}
00053 void write_delim(char);
00054 char read_delim();
00055
00056 int check() { char brace = peekahead(); return brace == '}' ? 0 : 1; }
00057 int eof() const { return istr() ? istr()->eof(): !_in_queue.count(); }
00058
00059 void ws(char *);
00060 STDbool operator ! () const { return _fail; }
00061 STDbool fail () const { return _fail; }
00062 STDbool block () const { return _block; }
00063 STDbool block(STDbool flag) { STDbool old=_block; _block = flag; return old; }
00064
00065
00066 str_ptr get_string_with_spaces();
00067
00068 protected:
00069
00070 virtual size_t send (const UGAptr data, int count) { _in_queue.put(data,count); return count; }
00071 virtual size_t recv (UGAptr data, int count) { return _out_queue.get (data, count); }
00072
00073 STDmem_queue _in_queue;
00074 STDmem_queue _out_queue;
00075 iostream* _iostream;
00076 istream* _istream;
00077 ostream* _ostream;
00078 int _indent;
00079
00080 private:
00081 STDbool _fail;
00082 STDbool _block;
00083
00084
00085 friend STDdstream & operator >> (STDdstream &, char &);
00086 friend STDdstream & operator >> (STDdstream &, char *&);
00087 friend STDdstream & operator >> (STDdstream &, str_ptr&);
00088 friend STDdstream & operator >> (STDdstream &, short &);
00089 friend STDdstream & operator >> (STDdstream &, int &);
00090 friend STDdstream & operator >> (STDdstream &, long &);
00091 friend STDdstream & operator >> (STDdstream &, unsigned char &);
00092 friend STDdstream & operator >> (STDdstream &, unsigned short &);
00093 friend STDdstream & operator >> (STDdstream &, unsigned int &);
00094 friend STDdstream & operator >> (STDdstream &, unsigned long &);
00095 friend STDdstream & operator >> (STDdstream &, float &);
00096 friend STDdstream & operator >> (STDdstream &, double &);
00097
00098 friend STDdstream & operator << (STDdstream &, char);
00099 friend STDdstream & operator << (STDdstream &, const char * const);
00100 friend STDdstream & operator << (STDdstream &, str_ptr);
00101 friend STDdstream & operator << (STDdstream &, short);
00102 friend STDdstream & operator << (STDdstream &, int);
00103 friend STDdstream & operator << (STDdstream &, long);
00104 friend STDdstream & operator << (STDdstream &, unsigned char);
00105 friend STDdstream & operator << (STDdstream &, unsigned short);
00106 friend STDdstream & operator << (STDdstream &, unsigned int);
00107 friend STDdstream & operator << (STDdstream &, unsigned long);
00108 friend STDdstream & operator << (STDdstream &, float);
00109 friend STDdstream & operator << (STDdstream &, double);
00110 };
00111
00112
00113
00114 inline STDdstream & flush (STDdstream &ds) { ds.flush(); return (ds); }
00115
00116 STDdstream & operator >> (STDdstream &, char &);
00117 STDdstream & operator >> (STDdstream &, char *&);
00118 STDdstream & operator >> (STDdstream &, str_ptr&);
00119 STDdstream & operator >> (STDdstream &, short &);
00120 STDdstream & operator >> (STDdstream &, int &);
00121 STDdstream & operator >> (STDdstream &, long &);
00122 STDdstream & operator >> (STDdstream &, unsigned char &);
00123 STDdstream & operator >> (STDdstream &, unsigned short &);
00124 STDdstream & operator >> (STDdstream &, unsigned int &);
00125 STDdstream & operator >> (STDdstream &, unsigned long &);
00126 STDdstream & operator >> (STDdstream &, float &);
00127 STDdstream & operator >> (STDdstream &, double &);
00128
00129 STDdstream & operator << (STDdstream &, char);
00130 STDdstream & operator << (STDdstream &, const char * const);
00131 STDdstream & operator << (STDdstream &, str_ptr);
00132 STDdstream & operator << (STDdstream &, short);
00133 STDdstream & operator << (STDdstream &, int);
00134 STDdstream & operator << (STDdstream &, long);
00135 STDdstream & operator << (STDdstream &, unsigned char);
00136 STDdstream & operator << (STDdstream &, unsigned short);
00137 STDdstream & operator << (STDdstream &, unsigned int);
00138 STDdstream & operator << (STDdstream &, unsigned long);
00139 STDdstream & operator << (STDdstream &, float);
00140 STDdstream & operator << (STDdstream &, double);
00141
00142
00143
00144
00145 #endif