switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Logger / Definitions.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief Definitions internal header */
30
31 #ifndef IH_SENF_Utils_Logger_Definitions_
32 #define IH_SENF_Utils_Logger_Definitions_ 1
33
34 // Custom includes
35
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 // Implementation details concerning SENF_LOG_CLASS_AREA
39 //
40 // The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of
41 // course, we cannot make the containing class into an area. Therefore we need to trick around a bit:
42 //
43 // We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that
44 // it's name() member will return the name of the containing class (which is simple: just cut of the
45 // last couple of characters of the name since the name will always end in '::SENFLogArea').
46 //
47 // This however does not allow the use of the containing class as an area. There are several places
48 // which need to be adjusted to allow using the containing class as an area: The logging statements
49 // (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via
50 // route statements.
51 //
52 // Lets begin with the compile time configuration. The compile time configuration is done using
53 // specialization of the senf::log::detail::Config template. This doesn't care, what the area
54 // template argument really is. Therefore, compile-time configuration just uses the containing class
55 // as is. So we need to make sure, that the logging statements use the containing class when
56 // checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the
57 // targets.
58 //
59 // So let's look at the logging statements. The central logic for parsing the logging parameters is
60 // in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes
61 // with a SENFLogArea member and then set's things up correctly: It uses the containing class for
62 // compile time checking (this is, what 'area_base' typedef is for) while using the nested
63 // SENFLogArea for routing (this is, what the 'area' typedef is for).
64 //
65 // So the last thing which needs to be adjusted is the routing which is part of the Target
66 // class. Here for each template taking an area as an argument we really provide TWO templates, one
67 // taking the area directly, the other checking for a nested SENFLogArea member. We can
68 // differentiate these overloads using boost::enable_if and friends.
69 //
70 // This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the
71 // implementation is somewhat different.
72
73 #define SENF_LOG_DEFINE_AREA_I(area, decls)                                                       \
74     struct area                                                                                   \
75         : public senf::log::detail::AreaBase, public senf::singleton<area>                        \
76     {                                                                                             \
77         static std::string name() { return instance().v_name(); }                                 \
78         using senf::singleton<area>::instance;                                                    \
79         decls                                                                                     \
80     private:                                                                                      \
81         area() { init(); }                                                                        \
82         friend class senf::singleton<area>;                                                       \
83     }
84
85 namespace senf {
86 namespace log {
87 namespace detail {
88
89     /// Internal: Alias base class
90     struct AliasBase {};
91
92 }}}
93
94 //-/////////////////////////////////////////////////////////////////////////////////////////////////
95 #endif
96
97 \f
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // comment-column: 40
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // End: