Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Parameters.ih

Go to the documentation of this file.
00001 // $Id: Parameters.ih 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2007
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef IH_SENF_Utils_Logger_Parameters_
00027 #define IH_SENF_Utils_Logger_Parameters_ 1
00028 
00029 // Custom includes
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     // This trick makes any class with a SENFLogArea typedef member usable as area. A typedef of
00092     // this name is created by SENF_LOG_CLASS_AREA()
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 // Local Variables:
00171 // mode: c++
00172 // fill-column: 100
00173 // comment-column: 40
00174 // c-file-style: "senf"
00175 // indent-tabs-mode: nil
00176 // ispell-local-dictionary: "american"
00177 // compile-command: "scons -u test"
00178 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research