4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Parameters internal header */
31 #ifndef IH_SENF_Utils_Logger_Parameters_
32 #define IH_SENF_Utils_Logger_Parameters_ 1
36 #include <boost/preprocessor/seq/for_each_i.hpp>
37 #include <boost/preprocessor/facilities/apply.hpp>
38 #include <boost/preprocessor/punctuation/comma_if.hpp>
39 #include <boost/mpl/vector.hpp>
40 #include <boost/mpl/fold.hpp>
41 #include <boost/mpl/if.hpp>
42 #include <boost/utility.hpp>
43 #include <boost/type_traits/is_convertible.hpp>
44 #include <senf/Utils/mpl.hh>
48 //-/////////////////////////////////////////////////////////////////////////////////////////////////
64 /// Internal: Parameter extractor
65 template <class Base, class Param, unsigned N>
66 struct Parameters_ {};
70 senf::mpl::rv<1> Parameters_select_(StreamBase *);
71 template <class Base, class Param>
72 struct Parameters_<Base,Param,1> : public Base
73 { typedef Param stream; };
75 senf::mpl::rv<2> Parameters_select_(AreaBase *);
76 template <class Base, class Param>
77 struct Parameters_<Base,Param,2> : public Base
78 { typedef Param area; typedef Param area_base; };
80 senf::mpl::rv<3> Parameters_select_(LevelBase *);
81 template <class Base, class Param>
82 struct Parameters_<Base,Param,3> : public Base
83 { typedef Param level; };
85 senf::mpl::rv<4> Parameters_select_(void *);
87 struct Parameters_<Base,void,4> : public Base
90 senf::mpl::rv<5> Parameters_select_(AliasBase *);
91 template <class Base, class Param>
92 struct Parameters_<Base,Param,5>
93 : public Param::template apply<Base>::type
96 // This trick makes any class with a SENFLogArea typedef member usable as area. A typedef of
97 // this name is created by SENF_LOG_CLASS_AREA()
99 senf::mpl::rv<6> Parameters_select_(
101 typename boost::disable_if< boost::is_convertible<T*,StreamBase*> >::type * = 0,
102 typename boost::disable_if< boost::is_convertible<T*,AreaBase*> >::type * = 0,
103 typename boost::disable_if< boost::is_convertible<T*,LevelBase*> >::type * = 0,
104 typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
105 template <class Base, class Param>
106 struct Parameters_<Base,Param,6> : public Base
107 { typedef typename Param::SENFLogArea area; typedef Param area_base; };
111 /// Internal: Log message parameter collection
112 template <class Base>
113 struct Parameters : public Base
115 typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
116 typename Base::stream::defaultLevel,
117 typename Base::level >::type level;
119 static bool const compileEnabled = senf::log::Enabled<
120 typename Base::stream,
121 typename Base::area_base,
124 static bool enabled() {
125 return compileEnabled
126 && ( senf::log::detail::TargetRegistry::instance().fallbackRouting() ||
127 Base::area::instance().limit(Base::stream::instance()) <= level::value );
131 /// Internal: Empty base class
134 /// Internal: Merge log message parameter list
135 struct Parameters_Merge
137 /// Internal: Embedded mpl template meta-function
138 template <class Base, class Param>
143 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
149 typedef senf::log::Debug SENFLogDefaultStream;
150 typedef senf::log::DefaultArea SENFLogDefaultArea;
151 typedef senf::log::NONE SENFLogDefaultLevel;
153 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
155 #define SENF_LOG_MERGE_PARAMETERS_I(base, args) \
157 boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >, \
159 senf::log::detail::Parameters_Merge >::type
161 #define SENF_LOG_MERGE_PARAMETERS(args) \
162 senf::log::detail::Parameters< SENF_LOG_MERGE_PARAMETERS_I( \
163 senf::log::detail::empty, \
164 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
166 #define SENF_LOG_MERGE_PARAMETERS_TPL(args) \
167 senf::log::detail::Parameters< typename SENF_LOG_MERGE_PARAMETERS_I( \
168 senf::log::detail::empty, \
169 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
171 //-/////////////////////////////////////////////////////////////////////////////////////////////////
178 // comment-column: 40
179 // c-file-style: "senf"
180 // indent-tabs-mode: nil
181 // ispell-local-dictionary: "american"
182 // compile-command: "scons -u test"