logger.hpp

Go to the documentation of this file.
00001 // -*- mode: c++; indent-tabs-mode: nil; -*-
00002 //
00003 //The Biomolecule Toolkit (BTK) is a C++ library for use in the
00004 //modeling, analysis, and design of biological macromolecules.
00005 //Copyright (C) 2006, Tim Robertson <kid50@users.sourceforge.net>
00006 //
00007 //This program is free software; you can redistribute it and/or modify
00008 //it under the terms of the GNU Lesser General Public License as published
00009 //by the Free Software Foundation; either version 2.1 of the License, or (at
00010 //your option) any later version.
00011 //
00012 //This program 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 License
00018 //along with this program; if not, write to the Free Software Foundation,
00019 //Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00023 
00024 #ifndef BTK_IO_LOGGER_HPP
00025 #define BTK_IO_LOGGER_HPP
00026 
00027 #include <string>
00028 #include <stack>
00029 
00030 #include <boost/shared_ptr.hpp>
00031 
00032 #include <btk/core/io/logger_level.hpp>
00033 
00034 namespace BTK {
00035 namespace IO {
00036 namespace LOGGING {
00037 
00040 struct LoggerInterface
00041 {
00042   virtual ~LoggerInterface() {}
00043 
00047   virtual void log(std::string const & msg,
00048                    LoggerLevel msg_level = EVERYTHING) const = 0;
00049 
00053   virtual void error(std::string const & msg) const = 0;
00054 };
00055 
00056 class SimpleLogger : public LoggerInterface
00057 {
00058 public:
00059   virtual void log(std::string const & msg,
00060                    LoggerLevel msg_level = EVERYTHING) const;
00061 
00062   virtual void error(std::string const & msg) const;
00063 };
00064 
00077 class Logger
00078 {
00079  public:
00080   typedef boost::shared_ptr<LoggerInterface> logger_ptr;
00081 
00082   virtual ~Logger() {}
00083 
00085   static LoggerInterface const & instance();
00086 
00089   static void push_logger(logger_ptr p) { _loggers.push(p); }
00090 
00094   static void pop_logger() 
00095   {
00096     if (!_loggers.empty()) _loggers.pop();
00097   }
00098 
00099  protected:
00100   Logger() {}
00101    
00102  private:
00103   // disallow copy construction and assignment
00104   Logger(Logger const &);
00105   Logger & operator=(Logger const &);
00106 
00107   static std::stack<logger_ptr> _loggers;
00108 };
00109 
00110 } // LOGGING
00111 } // IO
00112 } // BTK
00113 
00114 #endif // BTK_LOGGER_H

Generated on Sun Jul 15 20:46:25 2007 for BTK Core by  doxygen 1.5.1