4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Parameters internal header */
26 #ifndef IH_Parameters_
27 #define IH_Parameters_ 1
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>
43 ///////////////////////////////ih.p////////////////////////////////////////
59 /// Internal: Parameter extractor
60 template <class Base, class Param, unsigned N>
61 struct Parameters_ {};
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; };
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; };
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; };
80 senf::mpl::rv<4> Parameters_select_(void *);
82 struct Parameters_<Base,void,4> : public Base
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
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()
94 senf::mpl::rv<6> Parameters_select_(
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; };
106 /// Internal: Log message parameter collection
107 template <class Base>
108 struct Parameters : public Base
110 typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
111 typename Base::stream::defaultLevel,
112 typename Base::level >::type level;
114 static bool const compileEnabled = senf::log::Enabled<
115 typename Base::stream,
116 typename Base::area_base,
119 static bool enabled() {
120 return compileEnabled
121 && ( senf::log::detail::TargetRegistry::instance().fallbackRouting() ||
122 Base::area::instance().limit(Base::stream::instance()) <= level::value );
126 /// Internal: Empty base class
129 /// Internal: Merge log message parameter list
130 struct Parameters_Merge
132 /// Internal: Embedded mpl template meta-function
133 template <class Base, class Param>
138 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
144 typedef senf::log::Debug SENFLogDefaultStream;
145 typedef senf::log::DefaultArea SENFLogDefaultArea;
146 typedef senf::log::NONE SENFLogDefaultLevel;
148 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
150 #define SENF_LOG_MERGE_PARAMETERS_I(base, args) \
152 boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >, \
154 senf::log::detail::Parameters_Merge >::type
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) >
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) >
166 ///////////////////////////////ih.e////////////////////////////////////////
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"