// $Id$ // // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // // The contents of this file are subject to the Fraunhofer FOKUS Public License // Version 1.0 (the "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // http://senf.berlios.de/license.html // // The Fraunhofer FOKUS Public License Version 1.0 is based on, // but modifies the Mozilla Public License Version 1.1. // See the full license text for the amendments. // // Software distributed under the License is distributed on an "AS IS" basis, // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License // for the specific language governing rights and limitations under the License. // // The Original Code is Fraunhofer FOKUS code. // // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. // (registered association), Hansastraße 27 c, 80686 Munich, Germany. // All Rights Reserved. // // Contributor(s): // Stefan Bund /** \file \brief Definitions internal header */ #ifndef IH_SENF_Utils_Logger_Definitions_ #define IH_SENF_Utils_Logger_Definitions_ 1 // Custom includes //-///////////////////////////////////////////////////////////////////////////////////////////////// // Implementation details concerning SENF_LOG_CLASS_AREA // // The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of // course, we cannot make the containing class into an area. Therefore we need to trick around a bit: // // We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that // it's name() member will return the name of the containing class (which is simple: just cut of the // last couple of characters of the name since the name will always end in '::SENFLogArea'). // // This however does not allow the use of the containing class as an area. There are several places // which need to be adjusted to allow using the containing class as an area: The logging statements // (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via // route statements. // // Lets begin with the compile time configuration. The compile time configuration is done using // specialization of the senf::log::detail::Config template. This doesn't care, what the area // template argument really is. Therefore, compile-time configuration just uses the containing class // as is. So we need to make sure, that the logging statements use the containing class when // checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the // targets. // // So let's look at the logging statements. The central logic for parsing the logging parameters is // in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes // with a SENFLogArea member and then set's things up correctly: It uses the containing class for // compile time checking (this is, what 'area_base' typedef is for) while using the nested // SENFLogArea for routing (this is, what the 'area' typedef is for). // // So the last thing which needs to be adjusted is the routing which is part of the Target // class. Here for each template taking an area as an argument we really provide TWO templates, one // taking the area directly, the other checking for a nested SENFLogArea member. We can // differentiate these overloads using boost::enable_if and friends. // // This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the // implementation is somewhat different. #define SENF_LOG_DEFINE_AREA_I(area, decls) \ struct area \ : public senf::log::detail::AreaBase, public senf::singleton \ { \ static std::string name() { return instance().v_name(); } \ using senf::singleton::instance; \ decls \ private: \ area() { init(); } \ friend class senf::singleton; \ } namespace senf { namespace log { namespace detail { /// Internal: Alias base class struct AliasBase {}; }}} //-///////////////////////////////////////////////////////////////////////////////////////////////// #endif // Local Variables: // mode: c++ // fill-column: 100 // comment-column: 40 // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" // End: