Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

msg_stream.h

Go to the documentation of this file.
00001 
00063 #ifndef __MSG_STREAM__
00064 #define __MSG_STREAM__
00065 
00066 
00067 #include <iostream>
00068 #include <string>
00069 
00070 namespace Message{
00071 
00072 
00073   
00074 class Warning_stream;
00075 
00077 inline Warning_stream& done(Warning_stream& w);
00078 
00079 
00081 class Warning_stream{
00082     
00083 public:
00085   inline Warning_stream(const char* head,
00086                         const bool fatal=false,
00087                         std::ostream* const output=&std::cerr);
00088 
00090   template<typename T>
00091   inline Warning_stream& operator<<(const T& to_print);
00092 
00094   inline Warning_stream&
00095   operator<<(Warning_stream& (*f)(Warning_stream&));
00096 
00097   inline Warning_stream&
00098   operator<<(std::ostream& (*f)(std::ostream&));
00099 
00101   inline virtual ~Warning_stream();
00102 
00103   friend Warning_stream& done(Warning_stream& w);
00104 
00105   
00106 private:
00108   bool is_fatal;
00109 
00111   bool output_header;
00112 
00114   std::string header;
00115 
00117   std::ostream* const out;
00118 };
00119 
00120 
00121 
00122 /*
00123   
00124   ########################
00125   # Predefined variables #
00126   ########################
00127 
00128 */
00129 
00130 namespace {
00131   Warning_stream warning("warning : ",false,&std::cerr);
00132   Warning_stream error("fatal error : ",true,&std::cerr);
00133 }
00134 
00135 
00136   
00137   
00138 /*
00139 
00140   ##########
00141   # Macros #
00142   ##########
00143 
00144  */
00145 
00146 
00147 #define VALUE_OF(var) #var<<" = "<<var
00148 #define WHERE "fichier : "<<__FILE__<<"    ligne : "<<__LINE__
00149 
00150 
00151 
00152 
00153 
00154 /*
00155   
00156   #############################################
00157   #############################################
00158   #############################################
00159   ######                                 ######
00160   ######   I M P L E M E N T A T I O N   ######
00161   ######                                 ######
00162   #############################################
00163   #############################################
00164   #############################################
00165 
00166 
00167  */
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 Warning_stream::Warning_stream(const char* head,
00176                                const bool fatal,
00177                                std::ostream* const output)
00178   :is_fatal(fatal),
00179    output_header(true),
00180    header(head),
00181    out(output) {}
00182 
00183 Warning_stream&
00184 Warning_stream::operator<<(Warning_stream& (*f)(Warning_stream&)){
00185   return f(*this);
00186 }
00187 
00188 
00189 Warning_stream&
00190 Warning_stream::operator<<(std::ostream& (*f)(std::ostream&)){
00191   
00192   f(*out);
00193   return *this;
00194 }
00195 
00196 
00197 template<typename T>
00198 Warning_stream&
00199 Warning_stream::operator<<(const T& to_print){
00200   if (output_header){
00201     (*out)<<"\n"<<header;
00202     output_header = false;
00203   }
00204   
00205   (*out)<<to_print;
00206 
00207   return *this;
00208 }
00209 
00210 
00217 Warning_stream& done(Warning_stream& w){
00218   *(w.out)<<"\n";
00219   w.out->flush();
00220   
00221   if (w.is_fatal){
00222     exit(1);
00223   }
00224 
00225   w.output_header = true;
00226 
00227   return w;
00228 }
00229 
00230 
00231 Warning_stream::~Warning_stream(){}
00232 
00233 } // END OF namespace Message
00234 
00235 
00236 #endif

Generated on Tue Mar 2 18:12:44 2004 for Graph-cut code by doxygen1.2.18