4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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>
42 ///////////////////////////////ih.p////////////////////////////////////////
58 /// Internal: Parameter extractor
59 template <class Base, class Param, unsigned N>
60 struct Parameters_ {};
64 senf::mpl::rv<1> Parameters_select_(StreamBase *);
65 template <class Base, class Param>
66 struct Parameters_<Base,Param,1> : public Base
67 { typedef Param stream; };
69 senf::mpl::rv<2> Parameters_select_(AreaBase *);
70 template <class Base, class Param>
71 struct Parameters_<Base,Param,2> : public Base
72 { typedef Param area; typedef Param area_base; };
74 senf::mpl::rv<3> Parameters_select_(LevelBase *);
75 template <class Base, class Param>
76 struct Parameters_<Base,Param,3> : public Base
77 { typedef Param level; };
79 senf::mpl::rv<4> Parameters_select_(void *);
81 struct Parameters_<Base,void,4> : public Base
84 senf::mpl::rv<5> Parameters_select_(AliasBase *);
85 template <class Base, class Param>
86 struct Parameters_<Base,Param,5>
87 : public Param::template apply<Base>::type
90 // This trick makes any class with a SENFLogArea typedef member usable as area. A typedef of
91 // this name is created by SENF_LOG_CLASS_AREA()
93 senf::mpl::rv<6> Parameters_select_(
95 typename boost::disable_if< boost::is_convertible<T*,StreamBase*> >::type * = 0,
96 typename boost::disable_if< boost::is_convertible<T*,AreaBase*> >::type * = 0,
97 typename boost::disable_if< boost::is_convertible<T*,LevelBase*> >::type * = 0,
98 typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
99 template <class Base, class Param>
100 struct Parameters_<Base,Param,6> : public Base
101 { typedef typename Param::SENFLogArea area; typedef Param area_base; };
105 /// Internal: Log message parameter collection
106 template <class Base>
107 struct Parameters : public Base
109 typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
110 typename Base::stream::defaultLevel,
111 typename Base::level >::type level;
113 static bool const compileEnabled = senf::log::Enabled<
114 typename Base::stream,
115 typename Base::area_base,
118 static bool enabled() {
119 return compileEnabled
120 && Base::area::instance().limit(Base::stream::instance()) <= level::value;
124 /// Internal: Empty base class
127 /// Internal: Merge log message parameter list
128 struct Parameters_Merge
130 /// Internal: Embedded mpl template meta-function
131 template <class Base, class Param>
136 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
142 typedef senf::log::Debug SENFLogDefaultStream;
143 typedef senf::log::DefaultArea SENFLogDefaultArea;
144 typedef senf::log::NONE SENFLogDefaultLevel;
146 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
148 #define SENF_LOG_MERGE_PARAMETERS_I(base, args) \
150 boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >, \
152 senf::log::detail::Parameters_Merge >::type
154 #define SENF_LOG_MERGE_PARAMETERS(args) \
155 senf::log::detail::Parameters< SENF_LOG_MERGE_PARAMETERS_I( \
156 senf::log::detail::empty, \
157 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
159 #define SENF_LOG_MERGE_PARAMETERS_TPL(args) \
160 senf::log::detail::Parameters< typename SENF_LOG_MERGE_PARAMETERS_I( \
161 senf::log::detail::empty, \
162 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
164 ///////////////////////////////ih.e////////////////////////////////////////
171 // comment-column: 40
172 // c-file-style: "senf"
173 // indent-tabs-mode: nil
174 // ispell-local-dictionary: "american"
175 // compile-command: "scons -u test"