Packets: Fix VariantParser invalid parser access bug
[senf.git] / Utils / Logger / Target.ih
index 668bacc..c96eb32 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer NETwork research (NET)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 /** \file
     \brief Target internal header */
 
-#ifndef IH_Target_
-#define IH_Target_ 1
+#ifndef IH_SENF_Utils_Logger_Target_
+#define IH_SENF_Utils_Logger_Target_ 1
 
 // Custom includes
 #include <memory>
-#include <boost/scoped_ptr.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/static_assert.hpp>
 
 ///////////////////////////////ih.p////////////////////////////////////////
 
@@ -46,8 +47,6 @@ namespace detail {
         void write(StreamBase const & stream, AreaBase const & area, unsigned level, 
                    std::string msg);
 
-        void timeSource(std::auto_ptr<TimeSource> source);
-
         void routed();
         bool fallbackRouting();
 
@@ -59,7 +58,6 @@ namespace detail {
 
         typedef std::set<Target *> Targets;
         Targets targets_;
-        boost::scoped_ptr<TimeSource> timeSource_;
 
         bool fallbackRouting_;
         
@@ -71,6 +69,91 @@ namespace detail {
     template <class Stream, class Area, class Level>
     void write(std::string msg);
 
+#ifndef DOXYGEN
+
+    // This code takes the routing target template arguments in any order and sorts them 
+    // by type (Stream, Area and Level).
+
+    senf::mpl::rv<0u> RouteParameterCheck_(...);
+    senf::mpl::rv<1u> RouteParameterCheck_(StreamBase *);
+    senf::mpl::rv<2u> RouteParameterCheck_(AreaBase *);
+    template <class T> senf::mpl::rv<3u> RouteParameterCheck_(T*, typename T::SENFLogArea * = 0);
+    senf::mpl::rv<4u> RouteParameterCheck_(LevelBase *);
+
+    // For g++ 4.0 (at least) we need to provide the fully scoped name for this default value.
+    // no idea why. It works without the scope in 4.1
+    template < class T, class A2, class A1,
+               unsigned type = SENF_MPL_RV( senf::log::detail::RouteParameterCheck_(static_cast<T*>(0)) ) >
+    struct RouteParameters
+    {};
+
+    template <class A2, class A1>
+    struct RouteParameters<mpl::nil,A2,A1,0u>
+        : public RouteParameters<A2,A1,mpl::nil>
+    {};
+
+    struct NilLevel {
+        static unsigned const value = NONE::value;
+    };
+
+    template <>
+    struct RouteParameters<mpl::nil,mpl::nil,mpl::nil,0u>
+    {
+        typedef mpl::nil Stream;
+        typedef mpl::nil Area;
+        typedef NilLevel Level;
+    };
+
+    template <class T, class A2, class A1>
+    struct RouteParameters<T,A2,A1,1u>
+        : public RouteParameters<A2,A1,mpl::nil>
+    {
+        typedef RouteParameters<A2,A1,mpl::nil> base;
+        BOOST_STATIC_ASSERT(( boost::is_same<typename base::Stream, mpl::nil>::value ));
+        typedef T Stream;
+    };
+
+    template <class T, class A2, class A1>
+    struct RouteParameters<T,A2,A1,2u>
+        : public RouteParameters<A2,A1,mpl::nil>
+    {
+        typedef RouteParameters<A2,A1,mpl::nil> base;
+        BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
+        typedef T Area;
+    };
+
+    template <class T, class A2, class A1>
+    struct RouteParameters<T,A2,A1,3u>
+        : public RouteParameters<A2,A1,mpl::nil>
+    {
+        typedef RouteParameters<A2,A1,mpl::nil> base;
+        BOOST_STATIC_ASSERT(( boost::is_same<typename base::Area, mpl::nil>::value ));
+        typedef typename T::SENFLogArea Area;
+    };
+
+    template <class T, class A2, class A1>
+    struct RouteParameters<T,A2,A1,4u>
+        : public RouteParameters<A2,A1,mpl::nil>
+    {
+        typedef RouteParameters<A2,A1,mpl::nil> base;
+        BOOST_STATIC_ASSERT(( boost::is_same<typename base::Level, NilLevel>::value ));
+        typedef T Level;
+    };
+
+    template <class T, class RV>
+    struct InstanceP
+    {
+        static RV * value() { return & T::instance(); }
+    };
+
+    template <class RV>
+    struct InstanceP<mpl::nil, RV>
+    {
+        static RV * value() { return 0; }
+    };
+
+#endif
+
 }}}
 
 ///////////////////////////////ih.e////////////////////////////////////////