2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief Parameters internal header */
17 #ifndef IH_SENF_Utils_Logger_Parameters_
18 #define IH_SENF_Utils_Logger_Parameters_ 1
21 #include <boost/preprocessor/seq/for_each_i.hpp>
22 #include <boost/preprocessor/facilities/apply.hpp>
23 #include <boost/preprocessor/punctuation/comma_if.hpp>
24 #include <boost/mpl/vector.hpp>
25 #include <boost/mpl/fold.hpp>
26 #include <boost/mpl/if.hpp>
27 #include <boost/utility/enable_if.hpp>
28 #include <boost/type_traits/is_convertible.hpp>
29 #include <senf/Utils/mpl.hh>
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49 /// Internal: Parameter extractor
50 template <class Base, class Param, unsigned N>
51 struct Parameters_ {};
55 senf::mpl::rv<1> Parameters_select_(StreamBase *);
56 template <class Base, class Param>
57 struct Parameters_<Base,Param,1> : public Base
58 { typedef Param stream; };
60 senf::mpl::rv<2> Parameters_select_(AreaBase *);
61 template <class Base, class Param>
62 struct Parameters_<Base,Param,2> : public Base
63 { typedef Param area; typedef Param area_base; };
65 senf::mpl::rv<3> Parameters_select_(LevelBase *);
66 template <class Base, class Param>
67 struct Parameters_<Base,Param,3> : public Base
68 { typedef Param level; };
70 senf::mpl::rv<4> Parameters_select_(void *);
72 struct Parameters_<Base,void,4> : public Base
75 senf::mpl::rv<5> Parameters_select_(AliasBase *);
76 template <class Base, class Param>
77 struct Parameters_<Base,Param,5>
78 : public Param::template apply<Base>::type
81 // This trick makes any class with a SENFLogArea typedef member usable as area. A typedef of
82 // this name is created by SENF_LOG_CLASS_AREA()
84 senf::mpl::rv<6> Parameters_select_(
86 typename boost::disable_if< boost::is_convertible<T*,StreamBase*> >::type * = 0,
87 typename boost::disable_if< boost::is_convertible<T*,AreaBase*> >::type * = 0,
88 typename boost::disable_if< boost::is_convertible<T*,LevelBase*> >::type * = 0,
89 typename boost::disable_if< boost::is_convertible<T*,AliasBase*> >::type * = 0);
90 template <class Base, class Param>
91 struct Parameters_<Base,Param,6> : public Base
92 { typedef typename Param::SENFLogArea area; typedef Param area_base; };
96 /// Internal: Log message parameter collection
98 struct Parameters : public Base
100 typedef typename boost::mpl::if_c< Base::level::value == NONE::value,
101 typename Base::stream::defaultLevel,
102 typename Base::level >::type level;
104 static bool const compileEnabled = senf::log::Enabled<
105 typename Base::stream,
106 typename Base::area_base,
109 static bool enabled() {
110 return compileEnabled
111 && ( senf::log::detail::TargetRegistry::instance().fallbackRouting() ||
112 Base::area::instance().limit(Base::stream::instance()) <= level::value );
116 /// Internal: Empty base class
119 /// Internal: Merge log message parameter list
120 struct Parameters_Merge
122 /// Internal: Embedded mpl template meta-function
123 template <class Base, class Param>
128 SENF_MPL_RV(Parameters_select_(static_cast<Param*>(0)))> type;
134 typedef senf::log::Debug SENFLogDefaultStream;
135 typedef senf::log::DefaultArea SENFLogDefaultArea;
136 typedef senf::log::NONE SENFLogDefaultLevel;
138 #define SENF_LOG_MERGE_ARG(r, data, i, elem) BOOST_PP_COMMA_IF(i) elem
140 #define SENF_LOG_MERGE_PARAMETERS_I(base, args) \
142 boost::mpl::vector< BOOST_PP_SEQ_FOR_EACH_I(SENF_LOG_MERGE_ARG, _, args) >, \
144 senf::log::detail::Parameters_Merge >::type
146 #define SENF_LOG_MERGE_PARAMETERS(args) \
147 senf::log::detail::Parameters< SENF_LOG_MERGE_PARAMETERS_I( \
148 senf::log::detail::empty, \
149 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
151 #define SENF_LOG_MERGE_PARAMETERS_TPL(args) \
152 senf::log::detail::Parameters< typename SENF_LOG_MERGE_PARAMETERS_I( \
153 senf::log::detail::empty, \
154 (SENFLogDefaultStream)(SENFLogDefaultArea)(SENFLogDefaultLevel)args) >
156 //-/////////////////////////////////////////////////////////////////////////////////////////////////
163 // comment-column: 40
164 // c-file-style: "senf"
165 // indent-tabs-mode: nil
166 // ispell-local-dictionary: "american"
167 // compile-command: "scons -u test"