00001 // ---------------------------------------------------------------------------- 00002 // CERTI - HLA RunTime Infrastructure 00003 // Copyright (C) 2003 ONERA 00004 // 00005 // This file is part of CERTI-libCERTI 00006 // 00007 // CERTI-libCERTI is free software ; you can redistribute it and/or 00008 // modify it under the terms of the GNU Lesser General Public License 00009 // as published by the Free Software Foundation ; either version 2 of 00010 // the License, or (at your option) any later version. 00011 // 00012 // CERTI-libCERTI is distributed in the hope that it will be useful, but 00013 // WITHOUT ANY WARRANTY ; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 // Lesser General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public 00018 // License along with this program ; if not, write to the Free Software 00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00020 // USA 00021 // 00022 // $Id: DebugOStream.hh,v 4.2 2008/12/10 16:53:23 erk Exp $ 00023 // ---------------------------------------------------------------------------- 00024 00025 #ifndef _CERTI_DEBUGOSTREAM_HH 00026 #define _CERTI_DEBUGOSTREAM_HH 00027 00028 #include <iostream> 00029 #include "certi.hh" 00030 00033 class CERTI_EXPORT DebugOStream 00034 { 00035 private: 00036 std::ostream& ostr; 00037 00038 public: 00039 static DebugOStream nullOutputStream; 00040 00041 DebugOStream(std::ostream& theostr) : ostr(theostr) {} 00042 00043 int isNullOstream(void) { 00044 return(this != &(nullOutputStream)); 00045 } 00046 00047 // Global insertors on strings and characters are defined as 00048 // members of DebugOStream. 00049 DebugOStream& operator<<(const char* thestr) 00050 { 00051 if (this != &(DebugOStream::nullOutputStream)) 00052 ostr << thestr; 00053 return *this ; 00054 } 00055 00056 DebugOStream& operator<<(const signed char* thestr) 00057 { 00058 if (this != &(DebugOStream::nullOutputStream)) ostr << thestr; 00059 return *this ; 00060 } 00061 00062 DebugOStream& operator<<(const unsigned char* thestr) 00063 { 00064 if (this != &(DebugOStream::nullOutputStream)) ostr << thestr; 00065 return *this ; 00066 } 00067 00068 DebugOStream& operator<<(char ch) 00069 { 00070 if (this != &(DebugOStream::nullOutputStream)) ostr << ch; 00071 return *this ; 00072 } 00073 00074 DebugOStream& operator<<(signed char ch) 00075 { 00076 if (this != &(DebugOStream::nullOutputStream)) ostr << ch; 00077 return *this ; 00078 } 00079 00080 DebugOStream& operator<<(unsigned char ch) 00081 { 00082 if (this != &(DebugOStream::nullOutputStream)) ostr << ch; 00083 return *this ; 00084 } 00085 00086 //Copy And Redefine the ostream public interface 00087 //Arithmetic Inserters 00088 DebugOStream& operator<<(bool n) 00089 { 00090 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00091 return(*this); 00092 } 00093 00094 DebugOStream& operator<<(short n) 00095 { 00096 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00097 return(*this); 00098 } 00099 00100 DebugOStream& operator<<(unsigned short n) 00101 { 00102 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00103 return(*this); 00104 } 00105 00106 DebugOStream& operator<<(int n) 00107 { 00108 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00109 return(*this); 00110 } 00111 00112 DebugOStream& operator<<(unsigned int n) 00113 { 00114 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00115 return(*this); 00116 } 00117 00118 DebugOStream& operator<<(long n) 00119 { 00120 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00121 return(*this); 00122 } 00123 00124 DebugOStream& operator<<(unsigned long n) 00125 { 00126 if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00127 return(*this); 00128 } 00129 00130 DebugOStream& operator<<(float f) 00131 { 00132 if (this != &(DebugOStream::nullOutputStream)) ostr << f; 00133 return(*this); 00134 } 00135 00136 DebugOStream& operator<<(double f) 00137 { 00138 if (this != &(DebugOStream::nullOutputStream)) ostr << f; 00139 return(*this); 00140 } 00141 00142 DebugOStream& operator<<(long double f) 00143 { 00144 if (this != &(DebugOStream::nullOutputStream)) ostr << f; 00145 return(*this); 00146 } 00147 00148 //Specifique gcc, dans la norme le pointeur n'est pas constant. 00149 DebugOStream& operator<<(const void* p) 00150 { 00151 if (this != &(DebugOStream::nullOutputStream)) ostr << p; 00152 return(*this); 00153 } 00154 00155 // #ifdef _GLIBCPP_USE_LONG_LONG 00156 // //Specifique gcc 00157 // DebugOStream& operator<<(long long n) 00158 // { 00159 // if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00160 // return(*this); 00161 // } 00162 00163 // //Specifique gcc 00164 // DebugOStream& operator<<(unsigned long long n) 00165 // { 00166 // if (this != &(DebugOStream::nullOutputStream)) ostr << n; 00167 // return(*this); 00168 // } 00169 // #endif 00170 00171 //Specifique gcc 00172 DebugOStream& operator<<(std::streambuf* sb) 00173 { 00174 if (this != &(DebugOStream::nullOutputStream)) ostr << sb; 00175 return(*this); 00176 } 00177 00178 //Dans la norme C++, il faut passer une r�f�rence et pas un 00179 //pointeur mais ca marche pas avec gcc 00180 00181 //DebugOStream& operator<<(streambuf& sb) 00182 //{ 00183 // if (this != &(DebugOStream::nullOutputStream)) ostr << sb; 00184 // return(*this); 00185 //} 00186 00187 DebugOStream& operator<<(std::ostream& (*pf)(std::ostream&)) 00188 { 00189 if (this != &(DebugOStream::nullOutputStream)) 00190 ostr << pf; 00191 return(*this); 00192 } 00193 00194 DebugOStream& operator<<(std::ios& (*pf)(std::ios&)) 00195 { 00196 if (this != &(DebugOStream::nullOutputStream)) 00197 ostr << pf; 00198 return(*this); 00199 } 00200 00201 DebugOStream& operator<<(std::ios_base& (*pf)(std::ios_base&)) 00202 { 00203 if (this != &(DebugOStream::nullOutputStream)) 00204 ostr << pf; 00205 return(*this); 00206 } 00207 00208 // Unformatted output: 00209 DebugOStream& put(char c) 00210 { 00211 if (this != &(DebugOStream::nullOutputStream)) 00212 ostr.put(c); 00213 return(*this); 00214 } 00215 00216 DebugOStream& write(const char* str, std::streamsize n) 00217 { 00218 if (this != &(DebugOStream::nullOutputStream)) 00219 ostr.write(str, n); 00220 return(*this); 00221 } 00222 00223 // Other methods 00224 DebugOStream& flush(void) 00225 { 00226 if (this != &(DebugOStream::nullOutputStream)) 00227 ostr.flush(); 00228 return(*this); 00229 } 00230 00231 DebugOStream& seekp(std::streampos pos) 00232 { 00233 if (this != &(DebugOStream::nullOutputStream)) 00234 ostr.seekp(pos); 00235 return(*this); 00236 } 00237 00238 DebugOStream& seekp(std::streamoff off, std::ios_base::seekdir dir) 00239 { 00240 if (this != &(DebugOStream::nullOutputStream)) 00241 ostr.seekp(off, dir); 00242 return(*this); 00243 } 00244 00245 std::streampos tellp(void) 00246 { 00247 if (this != &(DebugOStream::nullOutputStream)) 00248 return(ostr.tellp()); 00249 else return(0); 00250 } 00251 00252 //End Copy And Redifine the ostream public interface 00253 00254 //The methods herited from ios_base and ios are not redefined in 00255 //DebugOStream to avoid basic access to these ostreams aimed at 00256 //printing simple debug messages 00257 }; 00258 00259 #endif // _CERTI_DEBUGOSTREAM_HH 00260 00261 // $Id: DebugOStream.hh,v 4.2 2008/12/10 16:53:23 erk Exp $