00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __SGL_OSTREAM_HPP
00027 #define __SGL_OSTREAM_HPP
00028
00029 #include <sgl.h>
00030
00031 class sglNullStreamBuf;
00032
00033
00034
00038 class SGL_DLL_API sglOStream
00039 {
00040 public:
00042
00043 {
00044 eALWAYS,
00045 eWARNING,
00046 eINFO,
00047 eDEBUG
00048 };
00049
00051 typedef void (*callback)(void);
00052
00053 public:
00057 static void setStream(ostream* stream);
00058
00062 static ostream* getStream();
00063
00069 static void setThreshold(PrintLevelEnum threshold);
00070
00074 static PrintLevelEnum getThreshold();
00075
00080 static void setPreFunc(callback func);
00081
00085 static callback getPreFunc();
00086
00091 static void setPostFunc(callback func);
00092
00096 static callback getPostFunc();
00097
00098 #ifdef WIN32
00099
00103 static string formatWIN32Error(int error_number);
00104 #endif
00105
00106 public:
00108
00109 : m_print_level(level)
00110 {
00111 if (s_pre_func && m_print_level <= s_threshold) (*s_pre_func)();
00112 }
00113
00115 virtual ~sglOStream()
00116 {
00117 if (s_post_func && m_print_level <= s_threshold) (*s_post_func)();
00118 }
00119
00121 ostream& getOStream()
00122 {
00123 if (s_stream && m_print_level <= s_threshold)
00124 return *s_stream;
00125 else
00126 return s_null_ostream;
00127 }
00128
00129 private:
00130
00131 sglOStream(const sglOStream &);
00132 sglOStream& operator=(const sglOStream &);
00133
00134 private:
00135 static PrintLevelEnum s_threshold;
00136 static ostream *s_stream;
00137 static callback s_pre_func;
00138 static callback s_post_func;
00139
00140 static sglNullStreamBuf *s_null_buff;
00141 static ostream s_null_ostream;
00142
00143 PrintLevelEnum m_print_level;
00144 };
00145
00146
00147
00148
00149 class SGL_DLL_API sglNullStream
00150 {
00151 public:
00152 sglNullStream() {};
00153 ~sglNullStream() {};
00154
00155
00156
00157
00158
00159
00160 template <class T>
00161 inline const sglNullStream& operator<<(const T&) const
00162 {
00163 return *this;
00164 }
00165 #ifdef WIN32
00166
00167 inline const sglNullStream& operator<<(
00168 ostream::_Myt& (__cdecl *_F)(ostream::_Myt&)) const
00169 {
00170 return *this;
00171 }
00172 #endif
00173 #if defined(vxw)
00174
00175 inline const sglNullStream& operator<<(char* rhs) const
00176 {
00177 return *this;
00178 }
00179 #endif
00180 #if (defined(__GNUC__) && (__GNUC__==2) && ((__GNUC_MINOR__<=91) || (__GNUC_MINOR__==96)))
00181
00182 inline const sglNullStream& operator<<(ostream& (*_F)(ostream&)) const
00183 {
00184 return *this;
00185 }
00186
00187 inline const sglNullStream& operator<<(ios& (*_F)(ios&)) const
00188 {
00189 return *this;
00190 }
00191 #endif
00192 #if (defined(sgi) && defined(_STANDARD_C_PLUS_PLUS)) || defined(__ghs__)
00193 inline const sglNullStream& operator<<(ostream& (*_F)(ostream&)) const
00194 {
00195 return *this;
00196 }
00197 #endif
00198
00199 private:
00200 sglNullStream(const sglNullStream &);
00201 sglNullStream &operator=(const sglNullStream &);
00202 };
00203
00204
00205
00206 #define sglPrint() (sglOStream(sglOStream::eALWAYS).getOStream())
00207
00208
00209 const sglNullStream sglNullStreamInst;
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 #ifdef NO_SGL_WARNING_PRINTS
00220 inline const sglNullStream &sglPrintWarning() { return sglNullStreamInst; }
00221 #else
00222 # define sglPrintWarning() (sglOStream(sglOStream::eWARNING).getOStream())
00223 #endif
00224
00225 #ifdef NO_SGL_INFO_PRINTS
00226 inline const sglNullStream &sglPrintInfo() { return sglNullStreamInst; }
00227 #else
00228 # define sglPrintInfo() (sglOStream(sglOStream::eINFO).getOStream())
00229 #endif
00230
00231 #ifdef NO_SGL_DEBUG_PRINTS
00232 inline const sglNullStream &sglPrintDebug() { return sglNullStreamInst; }
00233 #else
00234 # define sglPrintDebug() (sglOStream(sglOStream::eDEBUG).getOStream())
00235 #endif
00236
00237
00238 #endif