Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Utils / Logger / Parameters.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 Parameters internal header */
25
26 #ifndef IH_SENF_Utils_Logger_Parameters_
27 #define IH_SENF_Utils_Logger_Parameters_ 1
28
29 // Custom includes
30 #include <iostream>
31 #include <boost/preprocessor/seq/for_each_i.hpp>
32 #include <boost/preprocessor/facilities/apply.hpp>
33 #include <boost/preprocessor/punctuation/comma_if.hpp>
34 #include <boost/mpl/vector.hpp>
35 #include <boost/mpl/fold.hpp>
36 #include <boost/mpl/if.hpp>
37 #include <boost/utility.hpp>
38 #include <boost/type_traits/is_convertible.hpp>
39 #include <senf/Utils/mpl.hh>
40 #include "Config.hh"
41 #include "Target.hh"
42
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 namespace senf {
46 namespace log {
47
48     class DefaultArea;
49     class Debug;
50     class NONE;
51
52 namespace detail {
53
54     class StreamBase;
55     class AreaBase;
56     class LevelBase;
57     class AliasBase;
58
59     /// Internal: Parameter extractor
60     template <class Base, class Param, unsigned N>
61     struct Parameters_ {};
62
63 #ifndef DOXYGEN
64
65     senf::mpl::rv<1> Parameters_select_(StreamBase *);
66     template <class Base, class Param>
67     struct Parameters_<Base,Param,1> : public Base
68     { typedef Param stream; };
69
70     senf::mpl::rv<2> Parameters_select_(AreaBase *);
71     template <class Base, class Param>
72     struct Parameters_<Base,Param,2> : public Base
73     { typedef Param area; typedef Param area_base; };
74
75     senf::mpl::rv<3> Parameters_select_(LevelBase *);
76     template <class Base, class Param>
77     struct Parameters_<Base,Param,3> : public Base
78     { typedef Param level; };
79
80     senf::mpl::rv<4> Parameters_select_(void *);
81     template <class Base>
82     struct Parameters_<Base,void,4> : public Base
83     {};
84
85     senf::mpl::rv<5> Parameters_select_(AliasBase *);
86     template <class Base, class Param>
87     struct Parameters_<Base,Param,5>
88         : public Param::template apply<Base>::type
89     {};
90
91     // This trick makes any class with a SENFLogArea typedef member usable as area. A typedef of
92     // this name is created by SENF_LOG_CLASS_AREA()
93     template <class T>
94     senf::mpl::rv<6> Parameters_select_(
95         T *,
96         typename boost::disable_if< boost::is_convertible<T*,StreamBase*> >::type * = 0,
97         typename boost::disable_if< boost::is_convertible<T*,AreaBase*> >::type * = 0,
98         typename boost::disable_if< boost::is_convertible<T*,LevelBase*> >::type * = 0,
99         typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
100     template <class Base, class Param>
101     struct Parameters_<Base,Param,6> : public Base
102     { typedef typename Param::SENFLogArea area; typedef Param area_base; };
103
104 #endif
105
106     /// Internal: Log message parameter collection
107     template <class Base>
108     struct Parameters : public Base
109     {
110         typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
111                                            typename Base::stream::defaultLevel,
112                                            typename Base::level >::type level;
113
114         static bool const compileEnabled = senf::log::Enabled<
115             typename Base::stream,
116             typename Base::area_base,
117             level>::value;
118
119         static bool enabled() {
120             return compileEnabled
121                 && ( senf::log::detail::TargetRegistry::instance().fallbackRouting() ||
122                      Base::area::instance().limit(Base::stream::instance()) <= level::value );
123         }
124     };
125
126     /// Internal: Empty base class
127     struct empty {};
128
129     /// Internal: Merge log message parameter list
130     struct Parameters_Merge
131     {
132         /// Internal: Embedded mpl template meta-function
133         template <class Base, class Param>
134         struct apply {
135             typedef Parameters_<
136                 Base,
137                 Param,
138                 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
139         };
140     };
141
142 }}}
143
144 typedef senf::log::Debug       SENFLogDefaultStream;
145 typedef senf::log::DefaultArea SENFLogDefaultArea;
146 typedef senf::log::NONE        SENFLogDefaultLevel;
147
148 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
149
150 #define SENF_LOG_MERGE_PARAMETERS_I(base, args)                                                   \
151     boost::mpl::fold<                                                                             \
152         boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >,               \
153         base,                                                                                     \
154         senf::log::detail::Parameters_Merge >::type
155
156 #define SENF_LOG_MERGE_PARAMETERS(args)                                                           \
157     senf::log::detail::Parameters< SENF_LOG_MERGE_PARAMETERS_I(                                   \
158         senf::log::detail::empty,                                                                 \
159         (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
160
161 #define SENF_LOG_MERGE_PARAMETERS_TPL(args)                                                       \
162     senf::log::detail::Parameters< typename SENF_LOG_MERGE_PARAMETERS_I(                          \
163         senf::log::detail::empty,                                                                 \
164         (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
165
166 //-/////////////////////////////////////////////////////////////////////////////////////////////////
167 #endif
168
169 \f
170 // Local Variables:
171 // mode: c++
172 // fill-column: 100
173 // comment-column: 40
174 // c-file-style: "senf"
175 // indent-tabs-mode: nil
176 // ispell-local-dictionary: "american"
177 // compile-command: "scons -u test"
178 // End: