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

log.hpp

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 
00026 enum log_type { L_MODEL = 1, L_REPORT, L_STATUS, L_RES, L_DBG, L_ERR, L_EXT };
00027 
00032 class logger
00033 {
00034 public:
00035 
00041    friend std::ostream &operator<<(std::ostream &os, const logger &l);
00042      
00047    logger(std::ostream &os);
00048 
00055    logger &operator()(log_type type);
00056 
00063    template<class T>
00064    logger &operator<<(const T &arg);
00065 
00072    logger &operator<<(std::ostream &(*pf)(std::ostream&));
00073       
00078    void add_log_type(log_type type);
00079 
00087    template<class Con>
00088    void log_all(const Con &con, const std::string &delim);
00089 
00095    static log_type get_log_type(const std::string &name);
00096 
00102    static std::string get_log_name(const log_type &type);
00103 
00104 private:
00105 
00109    std::ostream &os;
00110 
00114    std::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 std::string &delim)
00139 {
00140    if(logger_valid)
00141       std::copy(con.begin(), con.end(), std::ostream_iterator<typename Con::value_type>(os, delim.c_str()));
00142 }
00143 
00144 
00145 #endif // LOG_H

Generated on Mon Mar 21 00:07:37 2005 for Fixpoint Engine by  doxygen 1.3.9.1