Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

log.h

Go to the documentation of this file.
00001 #ifndef LOG_H
00002 #define LOG_H
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <set>
00007 #include <iterator>
00008 
00009 using namespace std;
00010 
00028 enum log_type { L_MODEL = 1, L_REPORT, L_STATUS, L_RES, L_DBG, L_ERR, L_EXT };
00029 
00034 struct logger
00035 {
00041       friend ostream &operator<<(ostream &os, const logger &l);
00042      
00047       logger(ostream &os);
00048 
00055       logger &operator()(log_type type);
00056 
00063       template<class T>
00064       logger &operator<<(const T &arg);
00065 
00072       logger &operator<<(ostream &(*pf)(ostream&));
00073       
00078       void add_log_type(log_type type);
00079 
00087       template<class Con>
00088       void log_all(const Con &con, const string &delim);
00089 
00095       static log_type get_log_type(const string &name);
00096 
00102       static string get_log_name(const log_type &type);
00103 
00104    private:
00105 
00109       ostream &os;
00110 
00114       set<log_type> log_types;
00115 
00119       bool logger_valid;
00120 };
00121 
00122 extern logger lout;
00123 extern logger lerr;
00124 
00125 /* These methods are defined in the headerfile because they are
00126    templated and cannot be in any file other than that in which they
00127    were declared. */
00128  
00129 template<class T>
00130 logger &logger::operator<<(const T &arg)
00131 {
00132    if(logger_valid)
00133       os << arg;
00134    return *this;
00135 }
00136 
00137 template<class Con>
00138 void logger::log_all(const Con &con, const string &delim)
00139 {
00140    if(logger_valid)
00141       copy(con.begin(), con.end(), ostream_iterator<typename Con::value_type>(os, delim.c_str()));
00142 }
00143 
00144 
00145 #endif // LOG_H

Generated on Wed Feb 16 20:53:35 2005 for Fixpoint Engine by  doxygen 1.3.9.1