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_CACHED_LOGGER_HPP 00025 #define BTK_IO_CACHED_LOGGER_HPP 00026 00027 #include <map> 00028 #include <string> 00029 00030 #include <btk/core/io/logger.hpp> 00031 00032 namespace BTK { 00033 namespace IO { 00034 namespace LOGGING { 00035 00041 class CachedLogger : public LoggerInterface 00042 { 00043 public: 00044 CachedLogger(LoggerInterface const & previous_logger) : 00045 _previous_logger(previous_logger) {} 00046 00047 virtual ~CachedLogger() { flush(); } 00048 00052 virtual void log(std::string const & msg, 00053 LoggerLevel level) const; 00054 00055 virtual void error(std::string const & msg) const 00056 { 00057 _previous_logger.error(msg); 00058 } 00059 00063 void flush() const; 00064 00065 private: 00066 LoggerInterface const & _previous_logger; 00067 mutable std::map<std::string,LoggerLevel> _messages; 00068 }; 00069 00070 } // namespace LOGGING 00071 } // namespace IO 00072 } // namespace BTK 00073 00074 #endif
1.5.1