00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TJSTREAM_H
00019 #define TJSTREAM_H
00020
00021
00022 #include <tjutils/tjstd.h>
00023
00024
00025
00026
00027 typedef STD_ostream& (*streammanipulator)(STD_ostream&);
00028
00029
00035 #ifdef STREAM_REPLACEMENT
00036
00037 class tjstd_ostream {
00038
00039 public:
00040 tjstd_ostream() {}
00041 virtual ~tjstd_ostream() {}
00042
00043 inline tjstd_ostream& operator<<(char v) {append2buff(STD_string(1,v)); return *this;}
00044 inline tjstd_ostream& operator<<(unsigned char v) {append2buff(STD_string(1,v)); return *this;}
00045 inline tjstd_ostream& operator<<(signed char v) {append2buff(STD_string(1,v)); return *this;}
00046 inline tjstd_ostream& operator<<(const char* v) {append2buff(v); return *this;}
00047 inline tjstd_ostream& operator<<(int v) {buff_int(v); return *this;}
00048 inline tjstd_ostream& operator<<(unsigned int v) {buff_int(v); return *this;}
00049 inline tjstd_ostream& operator<<(long v) {buff_int(v); return *this;}
00050 inline tjstd_ostream& operator<<(unsigned long v) {buff_int(v); return *this;}
00051 #ifdef HAVE_LONG_LONG
00052 inline tjstd_ostream& operator<<(long long v) {buff_int(v); return *this;}
00053 #endif
00054 inline tjstd_ostream& operator<<(short v) {buff_int(v); return *this;}
00055 inline tjstd_ostream& operator<<(unsigned short v){buff_int(v); return *this;}
00056 inline tjstd_ostream& operator<<(bool v) {if(v) append2buff("true"); else append2buff("false"); return *this;}
00057 inline tjstd_ostream& operator<<(double v) {buff_float(v); return *this;}
00058 inline tjstd_ostream& operator<<(float v) {buff_float(v); return *this;}
00059 inline tjstd_ostream& operator<<(streammanipulator v) {v(*this); return *this;}
00060
00061
00062 private:
00063
00064
00065 tjstd_ostream(const tjstd_ostream&) {}
00066 tjstd_ostream& operator = (const tjstd_ostream&) {return *this;}
00067
00068 virtual void append2buff(const STD_string& str) {}
00069
00070 void buff_float(float f);
00071 void buff_int(int i);
00072
00073 };
00074
00076
00077 class tjstd_ostringstream : public tjstd_ostream {
00078
00079 public:
00080 tjstd_ostringstream() {}
00081 ~tjstd_ostringstream() {}
00082
00083 const STD_string& str() const {return buff;}
00084
00085 private:
00086
00087
00088 tjstd_ostringstream(const tjstd_ostringstream&) {}
00089 tjstd_ostringstream& operator = (const tjstd_ostringstream&) {return *this;}
00090
00091
00092 void append2buff(const STD_string& str) {buff+=str;}
00093
00094 STD_string buff;
00095 };
00096
00098
00099 class tjstd_ofstream : public tjstd_ostream {
00100
00101 public:
00102
00103 tjstd_ofstream(const char* filename="");
00104 ~tjstd_ofstream() {close();}
00105
00106 void close();
00107
00108 bool bad() {return !file_ptr;}
00109
00110 private:
00111
00112
00113 tjstd_ofstream(const tjstd_ofstream&) {}
00114 tjstd_ofstream& operator = (const tjstd_ofstream&) {return *this;}
00115
00116
00117 void append2buff(const STD_string& str);
00118
00119 void* file_ptr;
00120
00121 };
00122
00127
00128
00129 class tjstd_istream {
00130
00131 public:
00132 tjstd_istream() {}
00133
00134 inline tjstd_istream& operator>>(char) {return *this;}
00135 inline tjstd_istream& operator>>(unsigned char) {return *this;}
00136 inline tjstd_istream& operator>>(signed char) {return *this;}
00137 inline tjstd_istream& operator>>(const char *) {return *this;}
00138 inline tjstd_istream& operator>>(int) {return *this;}
00139 inline tjstd_istream& operator>>(unsigned int) {return *this;}
00140 inline tjstd_istream& operator>>(long) {return *this;}
00141 inline tjstd_istream& operator>>(unsigned long) {return *this;}
00142 #ifdef HAVE_LONG_LONG
00143 inline tjstd_istream& operator>>(long long) {return *this;}
00144 #endif
00145 inline tjstd_istream& operator>>(short) {return *this;}
00146 inline tjstd_istream& operator>>(unsigned short){return *this;}
00147 inline tjstd_istream& operator>>(bool) {return *this;}
00148 inline tjstd_istream& operator>>(double) {return *this;}
00149 inline tjstd_istream& operator>>(float) {return *this;}
00150
00151 inline tjstd_istream& get(char&) {return *this;}
00152 inline tjstd_istream& putback(char) {return *this;}
00153
00154 operator void* () const {return 0;}
00155
00156 };
00157
00158 inline tjstd_istream& tjstd_getline(tjstd_istream& is, STD_string&) {return is;}
00159
00160
00161
00163
00164 class tjstd_ifstream : public tjstd_istream {
00165
00166 public:
00167 tjstd_ifstream(const char* ="") {}
00168 void close() {}
00169 bool bad() {return false;}
00170 };
00171
00173
00174
00175 static tjstd_ostream tjstd_cout;
00176 static tjstd_ostream tjstd_cerr;
00177 static tjstd_istream tjstd_cin;
00178
00179 inline STD_ostream& tjstd_endl(STD_ostream& os) {return os << "\n";}
00180 inline STD_ostream& tjstd_flush(STD_ostream& os) {return os;}
00181 inline const char* tjstd_setprecision(unsigned int) {return "";}
00182
00183 #endif
00184
00187 #endif
00188