Fawkes API Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * factory.h - Logger factory 00004 * 00005 * Created: Mon Jun 04 10:54:35 2007 00006 * Copyright 2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __UTILS_LOGGING_FACTORY_H_ 00025 #define __UTILS_LOGGING_FACTORY_H_ 00026 00027 #include <core/exception.h> 00028 #include <core/exceptions/software.h> 00029 00030 #include <cstddef> 00031 00032 namespace fawkes { 00033 00034 00035 class UnknownLoggerTypeException : public Exception 00036 { 00037 public: 00038 UnknownLoggerTypeException(const char *msg = NULL); 00039 }; 00040 00041 class Logger; 00042 class MultiLogger; 00043 00044 class LoggerFactory 00045 { 00046 public: 00047 static Logger * instance(const char *type, const char *as); 00048 static MultiLogger *multilogger_instance(const char *as); 00049 00050 /** Get typed instance of logger. 00051 * Creates a new instance and converts it to the requested type. If the type 00052 * does not match the requested logger an exception is thrown. 00053 * @param type logger type 00054 * @param as logger argument string 00055 * @return typed logger instance 00056 * @exception TypeMismatchException thrown, if requested logger does not match 00057 * requested type. 00058 */ 00059 template <class L> 00060 static L* instance(const char *type, const char *as); 00061 }; 00062 00063 00064 template <class L> 00065 L * 00066 LoggerFactory::instance(const char *type, const char *as) 00067 { 00068 Logger *l = LoggerFactory::instance(type, as); 00069 L *tl = dynamic_cast<L *>(l); 00070 if ( tl == NULL ) { 00071 throw TypeMismatchException(); 00072 } 00073 return tl; 00074 } 00075 00076 } // end namespace fawkes 00077 00078 #endif