00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef IH_SENF_Utils_Logger_Parameters_
00027 #define IH_SENF_Utils_Logger_Parameters_ 1
00028
00029
00030 #include <iostream>
00031 #include <boost/preprocessor/seq/for_each_i.hpp>
00032 #include <boost/preprocessor/facilities/apply.hpp>
00033 #include <boost/preprocessor/punctuation/comma_if.hpp>
00034 #include <boost/mpl/vector.hpp>
00035 #include <boost/mpl/fold.hpp>
00036 #include <boost/mpl/if.hpp>
00037 #include <boost/utility.hpp>
00038 #include <boost/type_traits/is_convertible.hpp>
00039 #include <senf/Utils/mpl.hh>
00040 #include "Config.hh"
00041 #include "Target.hh"
00042
00043
00044
00045 namespace senf {
00046 namespace log {
00047
00048 class DefaultArea;
00049 class Debug;
00050 class NONE;
00051
00052 namespace detail {
00053
00054 class StreamBase;
00055 class AreaBase;
00056 class LevelBase;
00057 class AliasBase;
00058
00060 template <class Base, class Param, unsigned N>
00061 struct Parameters_ {};
00062
00063 #ifndef DOXYGEN
00064
00065 senf::mpl::rv<1> Parameters_select_(StreamBase *);
00066 template <class Base, class Param>
00067 struct Parameters_<Base,Param,1> : public Base
00068 { typedef Param stream; };
00069
00070 senf::mpl::rv<2> Parameters_select_(AreaBase *);
00071 template <class Base, class Param>
00072 struct Parameters_<Base,Param,2> : public Base
00073 { typedef Param area; typedef Param area_base; };
00074
00075 senf::mpl::rv<3> Parameters_select_(LevelBase *);
00076 template <class Base, class Param>
00077 struct Parameters_<Base,Param,3> : public Base
00078 { typedef Param level; };
00079
00080 senf::mpl::rv<4> Parameters_select_(void *);
00081 template <class Base>
00082 struct Parameters_<Base,void,4> : public Base
00083 {};
00084
00085 senf::mpl::rv<5> Parameters_select_(AliasBase *);
00086 template <class Base, class Param>
00087 struct Parameters_<Base,Param,5>
00088 : public Param::template apply<Base>::type
00089 {};
00090
00091
00092
00093 template <class T>
00094 senf::mpl::rv<6> Parameters_select_(
00095 T *,
00096 typename boost::disable_if< boost::is_convertible<T*,StreamBase*> >::type * = 0,
00097 typename boost::disable_if< boost::is_convertible<T*,AreaBase*> >::type * = 0,
00098 typename boost::disable_if< boost::is_convertible<T*,LevelBase*> >::type * = 0,
00099 typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
00100 template <class Base, class Param>
00101 struct Parameters_<Base,Param,6> : public Base
00102 { typedef typename Param::SENFLogArea area; typedef Param area_base; };
00103
00104 #endif
00105
00107 template <class Base>
00108 struct Parameters : public Base
00109 {
00110 typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
00111 typename Base::stream::defaultLevel,
00112 typename Base::level >::type level;
00113
00114 static bool const compileEnabled = senf::log::Enabled<
00115 typename Base::stream,
00116 typename Base::area_base,
00117 level>::value;
00118
00119 static bool enabled() {
00120 return compileEnabled
00121 && ( senf::log::detail::TargetRegistry::instance().fallbackRouting() ||
00122 Base::area::instance().limit(Base::stream::instance()) <= level::value );
00123 }
00124 };
00125
00127 struct empty {};
00128
00130 struct Parameters_Merge
00131 {
00133 template <class Base, class Param>
00134 struct apply {
00135 typedef Parameters_<
00136 Base,
00137 Param,
00138 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
00139 };
00140 };
00141
00142 }}}
00143
00144 typedef senf::log::Debug SENFLogDefaultStream;
00145 typedef senf::log::DefaultArea SENFLogDefaultArea;
00146 typedef senf::log::NONE SENFLogDefaultLevel;
00147
00148 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
00149
00150 #define SENF_LOG_MERGE_PARAMETERS_I(base, args) \
00151 boost::mpl::fold< \
00152 boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >, \
00153 base, \
00154 senf::log::detail::Parameters_Merge >::type
00155
00156 #define SENF_LOG_MERGE_PARAMETERS(args) \
00157 senf::log::detail::Parameters< SENF_LOG_MERGE_PARAMETERS_I( \
00158 senf::log::detail::empty, \
00159 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
00160
00161 #define SENF_LOG_MERGE_PARAMETERS_TPL(args) \
00162 senf::log::detail::Parameters< typename SENF_LOG_MERGE_PARAMETERS_I( \
00163 senf::log::detail::empty, \
00164 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
00165
00166
00167 #endif
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178