1e81d2816b7e3f8420e6e433df0f096131ab690e
[senf.git] / senf / Utils / Logger / Definitions.ih
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Definitions internal header */
25
26 #ifndef IH_SENF_Utils_Logger_Definitions_
27 #define IH_SENF_Utils_Logger_Definitions_ 1
28
29 // Custom includes
30
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
32
33 // Implementation details concerning SENF_LOG_CLASS_AREA
34 //
35 // The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of
36 // course, we cannot make the containing class into an area. Therefor we need to trick around a bit:
37 //
38 // We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that
39 // it's name() member will return the name of the containing class (which is simple: just cut of the
40 // last couple of characters of the name since the name will always end in '::SENFLogArea').
41 //
42 // This however does not allow the use of the containing class as an area. There are several places
43 // which need to be adjusted to allow using the containing class as an area: The logging statements
44 // (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via
45 // route statements.
46 //
47 // Lets begin with the compile time configuration. The compile time configuration is done using
48 // specialization of the senf::log::detail::Config template. This doesn't care, what the area
49 // template argument really is. Therefore, compile-time configuration just uses the containing class
50 // as is. So we need to make sure, that the logging statements use the containing class when
51 // checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the
52 // targets.
53 //
54 // So let's look at the logging statements. The central logic for parsing the logging parameters is
55 // in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes
56 // with a SENFLogArea member and then set's things up correctly: It uses the containing class for
57 // compile time checking (this is, what 'area_base' typedef is for) while using the nested
58 // SENFLogArea for routing (this is, what the 'area' typedef is for).
59 //
60 // So the last thing which needs to be adjusted is the routing which is part of the Target
61 // class. Here for each template taking an area as an argument we really provide TWO templates, one
62 // taking the area directly, the other checking for a nested SENFLogArea member. We can
63 // differentiate these overloads using boost::enable_if and friends.
64 //
65 // This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the
66 // implementation is somewhat different.
67
68 #define SENF_LOG_DEFINE_AREA_I(area, decls)                                                       \
69     struct area                                                                                   \
70         : public senf::log::detail::AreaBase, public senf::singleton<area>                        \
71     {                                                                                             \
72         static std::string name() { return instance().v_name(); }                                 \
73         using senf::singleton<area>::instance;                                                    \
74         decls                                                                                     \
75     private:                                                                                      \
76         area() { init(); }                                                                        \
77         friend class senf::singleton<area>;                                                       \
78     }
79
80 namespace senf {
81 namespace log {
82 namespace detail {
83
84     /// Internal: Alias base class
85     struct AliasBase {};
86
87 }}}
88
89 //-/////////////////////////////////////////////////////////////////////////////////////////////////
90 #endif
91
92 \f
93 // Local Variables:
94 // mode: c++
95 // fill-column: 100
96 // comment-column: 40
97 // c-file-style: "senf"
98 // indent-tabs-mode: nil
99 // ispell-local-dictionary: "american"
100 // compile-command: "scons -u test"
101 // End: