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>
40 ///////////////////////////////ih.p////////////////////////////////////////
56 /// Internal: Parameter extractor
57 template <class Base, class Param, unsigned N>
58 struct Parameters_ {};
62 senf::mpl::rv<1> Parameters_select_(StreamBase *);
63 template <class Base, class Param>
64 struct Parameters_<Base,Param,1> : public Base
65 { typedef Param stream; };
67 senf::mpl::rv<2> Parameters_select_(AreaBase *);
68 template <class Base, class Param>
69 struct Parameters_<Base,Param,2> : public Base
70 { typedef Param area; typedef Param area_base; };
72 senf::mpl::rv<3> Parameters_select_(LevelBase *);
73 template <class Base, class Param>
74 struct Parameters_<Base,Param,3> : public Base
75 { typedef Param level; };
77 senf::mpl::rv<4> Parameters_select_(void *);
79 struct Parameters_<Base,void,4> : public Base
82 senf::mpl::rv<5> Parameters_select_(AliasBase *);
83 template <class Base, class Param>
84 struct Parameters_<Base,Param,5>
85 : public Param::template apply<Base>::type
88 // This trick makes any class with a SENFLogArea typedef member usable as area. A typedef of
89 // this name is created by SENF_LOG_CLASS_AREA()
91 senf::mpl::rv<6> Parameters_select_(
93 typename boost::disable_if< boost::is_convertible<T*,StreamBase*> >::type * = 0,
94 typename boost::disable_if< boost::is_convertible<T*,AreaBase*> >::type * = 0,
95 typename boost::disable_if< boost::is_convertible<T*,LevelBase*> >::type * = 0,
96 typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
97 template <class Base, class Param>
98 struct Parameters_<Base,Param,6> : public Base
99 { typedef typename Param::SENFLogArea area; typedef Param area_base; };
103 /// Internal: Log message parameter collection
104 template <class Base>
105 struct Parameters : public Base
107 typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
108 typename Base::stream::defaultLevel,
109 typename Base::level >::type level;
111 static bool const compileEnabled = senf::log::Enabled<
112 typename Base::stream,
113 typename Base::area_base,
116 static bool enabled() {
117 return compileEnabled
118 && Base::area::instance().limit(Base::stream::instance()) <= level::value;
122 /// Internal: Empty base class
125 /// Internal: Merge log message parameter list
126 struct Parameters_Merge
128 /// Internal: Embedded mpl template meta-function
129 template <class Base, class Param>
134 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
140 typedef senf::log::Debug SENFLogDefaultStream;
141 typedef senf::log::DefaultArea SENFLogDefaultArea;
142 typedef senf::log::NONE SENFLogDefaultLevel;
144 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
146 #define SENF_LOG_MERGE_PARAMETERS_I(base, args) \
148 boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >, \
150 senf::log::detail::Parameters_Merge >::type
152 #define SENF_LOG_MERGE_PARAMETERS(args) \
153 senf::log::detail::Parameters< SENF_LOG_MERGE_PARAMETERS_I( \
154 senf::log::detail::empty, \
155 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
157 #define SENF_LOG_MERGE_PARAMETERS_TPL(args) \
158 senf::log::detail::Parameters< typename SENF_LOG_MERGE_PARAMETERS_I( \
159 senf::log::detail::empty, \
160 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
162 ///////////////////////////////ih.e////////////////////////////////////////
169 // comment-column: 40
170 // c-file-style: "senf"
171 // indent-tabs-mode: nil
172 // ispell-local-dictionary: "american"
173 // compile-command: "scons -u test"