00001 // $Id: Definitions.ih 1771 2011-03-08 14:43:47Z tho $ 00002 // 00003 // Copyright (C) 2007 00004 // Fraunhofer (FOKUS) 00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY 00006 // Stefan Bund <g0dil@berlios.de> 00007 // 00008 // This program is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 2 of the License, or 00011 // (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the 00020 // Free Software Foundation, Inc., 00021 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00026 #ifndef IH_SENF_Utils_Logger_Definitions_ 00027 #define IH_SENF_Utils_Logger_Definitions_ 1 00028 00029 // Custom includes 00030 00031 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00032 00033 // Implementation details concerning SENF_LOG_CLASS_AREA 00034 // 00035 // The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of 00036 // course, we cannot make the containing class into an area. Therefore we need to trick around a bit: 00037 // 00038 // We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that 00039 // it's name() member will return the name of the containing class (which is simple: just cut of the 00040 // last couple of characters of the name since the name will always end in '::SENFLogArea'). 00041 // 00042 // This however does not allow the use of the containing class as an area. There are several places 00043 // which need to be adjusted to allow using the containing class as an area: The logging statements 00044 // (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via 00045 // route statements. 00046 // 00047 // Lets begin with the compile time configuration. The compile time configuration is done using 00048 // specialization of the senf::log::detail::Config template. This doesn't care, what the area 00049 // template argument really is. Therefore, compile-time configuration just uses the containing class 00050 // as is. So we need to make sure, that the logging statements use the containing class when 00051 // checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the 00052 // targets. 00053 // 00054 // So let's look at the logging statements. The central logic for parsing the logging parameters is 00055 // in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes 00056 // with a SENFLogArea member and then set's things up correctly: It uses the containing class for 00057 // compile time checking (this is, what 'area_base' typedef is for) while using the nested 00058 // SENFLogArea for routing (this is, what the 'area' typedef is for). 00059 // 00060 // So the last thing which needs to be adjusted is the routing which is part of the Target 00061 // class. Here for each template taking an area as an argument we really provide TWO templates, one 00062 // taking the area directly, the other checking for a nested SENFLogArea member. We can 00063 // differentiate these overloads using boost::enable_if and friends. 00064 // 00065 // This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the 00066 // implementation is somewhat different. 00067 00068 #define SENF_LOG_DEFINE_AREA_I(area, decls) \ 00069 struct area \ 00070 : public senf::log::detail::AreaBase, public senf::singleton<area> \ 00071 { \ 00072 static std::string name() { return instance().v_name(); } \ 00073 using senf::singleton<area>::instance; \ 00074 decls \ 00075 private: \ 00076 area() { init(); } \ 00077 friend class senf::singleton<area>; \ 00078 } 00079 00080 namespace senf { 00081 namespace log { 00082 namespace detail { 00083 00085 struct AliasBase {}; 00086 00087 }}} 00088 00089 //-///////////////////////////////////////////////////////////////////////////////////////////////// 00090 #endif 00091 00092 00093 // Local Variables: 00094 // mode: c++ 00095 // fill-column: 100 00096 // comment-column: 40 00097 // c-file-style: "senf" 00098 // indent-tabs-mode: nil 00099 // ispell-local-dictionary: "american" 00100 // compile-command: "scons -u test" 00101 // End: