// $Id$
//
-// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Copyright (C) 2006
+// 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
// it under the terms of the GNU General Public License as published by
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+/** \file
+ \brief Policy Framework internal header
+ */
+
#ifndef IH_SocketPolicy_
#define IH_SocketPolicy_ 1
#include <boost/mpl/and.hpp>
#include <boost/utility.hpp> // for enable_if
-#include "GenericSockAddr.hh"
+#include "../Utils/mpl.hh"
+#include "../Utils/pool_alloc_mixin.hh"
///////////////////////////////ih.p////////////////////////////////////////
-namespace satcom {
-namespace lib {
+/// \cond disabled
+// Hide this code from doxygen
-# define SATLIB_SOCKET_POLICIES_N BOOST_PP_SEQ_SIZE( SATLIB_SOCKET_POLICIES )
-
- // This REALLY is bad ... but we just need an Address member in
- // AddressingPolicyBase as long as ClientSocketHandle /
- // ServerSocketHandle don't make use of enable_if for each and
- // every member they define ...
+namespace senf {
- struct AddressingPolicyBase
- {
- virtual ~ AddressingPolicyBase() {}
-
- typedef GenericSockAddr Address;
- };
+# define SENF_SOCKET_POLICIES_N BOOST_PP_SEQ_SIZE( SENF_SOCKET_POLICIES )
-# define SP_DeclareBase(x1,x2,SomePolicy) \
- struct BOOST_PP_CAT(SomePolicy,Base) \
- { virtual ~ BOOST_PP_CAT(SomePolicy,Base) () {} }; \
+# define SP_DeclareAlias(x1,x2,SomePolicy) \
typedef BOOST_PP_CAT(SomePolicy,Base) BOOST_PP_CAT(Unspecified,SomePolicy);
- BOOST_PP_SEQ_FOR_EACH( SP_DeclareBase, , BOOST_PP_SEQ_POP_FRONT( SATLIB_SOCKET_POLICIES ) )
+ BOOST_PP_SEQ_FOR_EACH( SP_DeclareAlias, , SENF_SOCKET_POLICIES )
+
+# undef SP_DeclareAlias
-# undef SP_DeclareBase
-
struct SocketPolicyBase
{
- virtual ~SocketPolicyBase() {}
+ virtual ~SocketPolicyBase();
-# define SP_DeclareTypedef(x1,x2,SomePolicy) \
- typedef BOOST_PP_CAT(SomePolicy,Base) SomePolicy; \
- BOOST_PP_CAT(SomePolicy,Base) BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); \
- virtual BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const \
- { return BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); }
+# define SP_Declare(x1,x2,SomePolicy) \
+ virtual BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () \
+ const = 0;
- BOOST_PP_SEQ_FOR_EACH( SP_DeclareTypedef, , SATLIB_SOCKET_POLICIES )
+ BOOST_PP_SEQ_FOR_EACH( SP_Declare, , SENF_SOCKET_POLICIES )
-# undef SP_DeclareTypedef
+# undef SP_Declare
};
-# define SP_TemplateArgs(x1,x2,n,SomePolicy) \
- BOOST_PP_COMMA_IF( n ) \
+# define SP_TemplateArgs(x1,x2,n,SomePolicy) \
+ BOOST_PP_COMMA_IF( n ) \
class BOOST_PP_CAT(SomePolicy,_) = BOOST_PP_CAT(SomePolicy,Base)
+# define SP_TemplateParms(x1,x2,n,SomePolicy) \
+ BOOST_PP_COMMA_IF( n ) BOOST_PP_CAT(SomePolicy,_)
- template < BOOST_PP_SEQ_FOR_EACH_I( SP_TemplateArgs, , SATLIB_SOCKET_POLICIES ) >
+ template < BOOST_PP_SEQ_FOR_EACH_I( SP_TemplateArgs, , SENF_SOCKET_POLICIES ) >
struct SocketPolicy
- : public SocketPolicyBase
+ : public SocketPolicyBase,
+ public senf::pool_alloc_mixin<
+ SocketPolicy< BOOST_PP_SEQ_FOR_EACH_I( SP_TemplateParms, , SENF_SOCKET_POLICIES ) > >
{
-# define SP_DeclarePolicyMember(x1,x2,SomePolicy) \
- typedef BOOST_PP_CAT(SomePolicy,_) SomePolicy; \
- SomePolicy BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); \
- BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const \
+# define SP_DeclarePolicyMember(x1,x2,SomePolicy) \
+ typedef BOOST_PP_CAT(SomePolicy,_) SomePolicy; \
+ SomePolicy BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); \
+ BOOST_PP_CAT(SomePolicy,Base) const & BOOST_PP_CAT(the,SomePolicy) () const \
{ return BOOST_PP_CAT(BOOST_PP_CAT(the,SomePolicy),_); }
- BOOST_PP_SEQ_FOR_EACH( SP_DeclarePolicyMember, , SATLIB_SOCKET_POLICIES )
+ BOOST_PP_SEQ_FOR_EACH( SP_DeclarePolicyMember, , SENF_SOCKET_POLICIES )
# undef SP_DeclarePolicyMember
static void checkBaseOf(SocketPolicyBase const & other);
};
# undef SP_TemplateArgs
+# undef SP_TemplateParms
namespace impl {
- struct nil {};
-
- template <int N>
- struct SocketPolicy_rv
- { int v[N+1]; };
-
- template <class Base, class Policy, int N>
+ template <class Base, class Policy, int _>
struct MakeSocketPolicy_merge
{};
-# define SP_DeclareMakeSocketPolicy_merge_member(r,n,m,SomePolicy) \
- BOOST_PP_COMMA_IF( m ) \
+# define SP_DeclareMakeSocketPolicy_merge_member(r,n,m,SomePolicy) \
+ BOOST_PP_COMMA_IF( m ) \
BOOST_PP_IIF( BOOST_PP_EQUAL(n,m), Policy, typename Base::SomePolicy )
-# define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_DEC( SATLIB_SOCKET_POLICIES_N ) )
-# define BOOST_PP_LOCAL_MACRO(n) \
- SocketPolicy_rv<n> MakeSocketPolicy_merge_(BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SATLIB_SOCKET_POLICIES ),Base)*); \
- \
- template <class Base, class Policy> \
- struct MakeSocketPolicy_merge<Base,Policy,sizeof(SocketPolicy_rv<n>)> \
- { \
- typedef SocketPolicy< \
- BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareMakeSocketPolicy_merge_member, n, SATLIB_SOCKET_POLICIES ) \
- > type; \
+# define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_DEC( SENF_SOCKET_POLICIES_N ) )
+# define BOOST_PP_LOCAL_MACRO(n) \
+ senf::mpl::rv<n> MakeSocketPolicy_merge_( \
+ BOOST_PP_CAT( BOOST_PP_SEQ_ELEM( n, SENF_SOCKET_POLICIES ),Base)*); \
+ \
+ template <class Base, class Policy> \
+ struct MakeSocketPolicy_merge<Base,Policy,n> \
+ { \
+ typedef SocketPolicy< \
+ BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareMakeSocketPolicy_merge_member, \
+ n, \
+ SENF_SOCKET_POLICIES ) \
+ > type; \
};
# include BOOST_PP_LOCAL_ITERATE()
struct apply
: MakeSocketPolicy_merge<Base,
Policy,
- sizeof(MakeSocketPolicy_merge_(static_cast<Policy*>(0)))>
+ SENF_MPL_RV(MakeSocketPolicy_merge_(static_cast<Policy*>(0)))>
{};
template <class Base>
- struct apply<Base,nil>
+ struct apply<Base,mpl::nil>
{
typedef Base type;
};
typedef typename boost::mpl::fold< Vector, Base, MakeSocketPolicy_fold >::type policy;
};
-# define SP_DeclareArguments(x1,x2,n,SomePolicy) \
- BOOST_PP_COMMA_IF( n ) \
- typename Base::SomePolicy *
+# define SP_DeclareArguments(x1,x2,n,SomePolicy) \
+ BOOST_PP_COMMA_IF( n ) \
+ typename Base::SomePolicy *
template <class Base>
- SocketPolicy_rv<1> SocketPolicy_checkcompat_(
- BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareArguments, , SATLIB_SOCKET_POLICIES ) );
+ senf::mpl::rv<1> SocketPolicy_checkcompat_(
+ BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareArguments, , SENF_SOCKET_POLICIES ) );
# undef SP_DeclareArguments
template <class Base>
- SocketPolicy_rv<2> SocketPolicy_checkcompat_(
- BOOST_PP_ENUM_PARAMS( SATLIB_SOCKET_POLICIES_N, void * BOOST_PP_INTERCEPT ) );
+ senf::mpl::rv<2> SocketPolicy_checkcompat_( ... );
template <int Size>
struct SocketPolicy_checkcompat
{};
template<>
- struct SocketPolicy_checkcompat<sizeof(SocketPolicy_rv<1>)>
+ struct SocketPolicy_checkcompat<1>
: public boost::true_type
{};
-# define SP_DeclareArguments(x1,x2,n,SomePolicy) \
- BOOST_PP_COMMA_IF( n ) \
+# define SP_DeclareArguments(x1,x2,n,SomePolicy) \
+ BOOST_PP_COMMA_IF( n ) \
static_cast<typename Derived::SomePolicy *>(0)
template <class Base, class Derived>
struct SocketPolicy_compatibility
- : public SocketPolicy_checkcompat< sizeof(
+ : public SocketPolicy_checkcompat< SENF_MPL_RV(
SocketPolicy_checkcompat_<Base>(
- BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareArguments, , SATLIB_SOCKET_POLICIES ) )) >
+ BOOST_PP_SEQ_FOR_EACH_I( SP_DeclareArguments, , SENF_SOCKET_POLICIES ) )) >
{};
} // namespace impl
- template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( SATLIB_SOCKET_POLICIES_N, class T, satcom::lib::impl::nil ) >
+ template < BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT( SENF_SOCKET_POLICIES_N,
+ class T,
+ mpl::nil ) >
class MakeSocketPolicy
: public boost::mpl::if_< boost::is_convertible< T0*, SocketPolicyBase* >,
- impl::MakeSocketPolicy_impl< T0, boost::mpl::vector< BOOST_PP_ENUM_SHIFTED_PARAMS( SATLIB_SOCKET_POLICIES_N, T ) > >,
- impl::MakeSocketPolicy_impl< SocketPolicy<>,
- boost::mpl::vector< BOOST_PP_ENUM_PARAMS( SATLIB_SOCKET_POLICIES_N, T ) > > >::type
+ impl::MakeSocketPolicy_impl<
+ T0,
+ boost::mpl::vector<
+ BOOST_PP_ENUM_SHIFTED_PARAMS(
+ SENF_SOCKET_POLICIES_N, T ) > >,
+ impl::MakeSocketPolicy_impl<
+ SocketPolicy<>,
+ boost::mpl::vector<
+ BOOST_PP_ENUM_PARAMS(
+ SENF_SOCKET_POLICIES_N, T ) > > >::type
{};
template <class BasePolicy, class DerivedPolicy>
struct SocketPolicyIsBaseOf
- : public boost::mpl::if_< boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >,
- boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >,
- impl::SocketPolicy_compatibility<BasePolicy,DerivedPolicy>,
- boost::false_type >::type
+ : public boost::mpl::if_<
+ boost::mpl::and_< boost::is_convertible< BasePolicy*, SocketPolicyBase* >,
+ boost::is_convertible< DerivedPolicy*, SocketPolicyBase* > >,
+ impl::SocketPolicy_compatibility<BasePolicy,DerivedPolicy>,
+ boost::false_type
+ >::type
{};
-# define SP_DefineConditions(x1,x2,SomePolicy) \
- template <class Policy, class Trait> \
- struct BOOST_PP_CAT(SomePolicy,Is) \
- : public boost::is_convertible< typename Policy::SomePolicy*, Trait* > \
- {}; \
- \
- template <class Policy, class Trait> \
- struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is) \
- : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait> > \
- {}; \
- \
- template <class Policy, class Trait> \
- struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot) \
- : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait>::value > \
+# define SP_DefineConditions(x1,x2,SomePolicy) \
+ template <class Policy, class Trait> \
+ struct BOOST_PP_CAT(SomePolicy,Is) \
+ : public boost::is_convertible< typename Policy::SomePolicy*, Trait* > \
+ {}; \
+ \
+ template <class Policy, class Trait> \
+ struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),Is) \
+ : public boost::enable_if< BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait> > \
+ {}; \
+ \
+ template <class Policy, class Trait> \
+ struct BOOST_PP_CAT(BOOST_PP_CAT(If,SomePolicy),IsNot) \
+ : public boost::enable_if_c< ! BOOST_PP_CAT(SomePolicy,Is)<Policy,Trait>::value > \
{};
- BOOST_PP_SEQ_FOR_EACH( SP_DefineConditions, , SATLIB_SOCKET_POLICIES )
+ BOOST_PP_SEQ_FOR_EACH( SP_DefineConditions, , SENF_SOCKET_POLICIES )
# undef SP_DefineConditions
-}}
+}
+
+/// \endcond
///////////////////////////////ih.e////////////////////////////////////////
#endif
\f
// Local Variables:
// mode: c++
-// c-file-style: "satcom"
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
// End: