2002-08-11 05:49:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The Loki Library
|
|
|
|
// Copyright (c) 2001 by Andrei Alexandrescu
|
|
|
|
// This code accompanies the book:
|
2009-02-02 06:23:28 +00:00
|
|
|
// Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
|
2002-08-11 05:49:45 +00:00
|
|
|
// Patterns Applied". Copyright (c) 2001. Addison-Wesley.
|
2011-09-23 00:46:21 +00:00
|
|
|
//
|
|
|
|
// Code covered by the MIT License
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
// SOFTWARE.
|
2002-08-11 05:49:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2005-09-26 07:33:05 +00:00
|
|
|
#ifndef LOKI_MULTIMETHODS_INC_
|
|
|
|
#define LOKI_MULTIMETHODS_INC_
|
2002-08-11 05:49:45 +00:00
|
|
|
|
2006-10-17 19:50:37 +00:00
|
|
|
// $Id$
|
|
|
|
|
2006-01-16 19:05:09 +00:00
|
|
|
|
2010-04-19 03:09:59 +00:00
|
|
|
#include <loki/Typelist.h>
|
|
|
|
#include <loki/LokiTypeInfo.h>
|
|
|
|
#include <loki/Functor.h>
|
|
|
|
#include <loki/AssocVector.h>
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// IMPORTANT NOTE:
|
|
|
|
// The double dispatchers implemented below differ from the excerpts shown in
|
|
|
|
// the book - they are simpler while respecting the same interface.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Loki
|
|
|
|
{
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template InvocationTraits (helper)
|
|
|
|
// Helps implementing optional symmetry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Private
|
|
|
|
{
|
2009-02-02 06:23:28 +00:00
|
|
|
template <class SomeLhs, class SomeRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
class Executor, typename ResultType>
|
2002-08-11 05:49:45 +00:00
|
|
|
struct InvocationTraits
|
|
|
|
{
|
2009-02-02 06:23:28 +00:00
|
|
|
static ResultType
|
|
|
|
DoDispatch(SomeLhs& lhs, SomeRhs& rhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
Executor& exec, Int2Type<false>)
|
2002-08-11 05:49:45 +00:00
|
|
|
{
|
|
|
|
return exec.Fire(lhs, rhs);
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
static ResultType
|
|
|
|
DoDispatch(SomeLhs& lhs, SomeRhs& rhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
Executor& exec, Int2Type<true>)
|
2002-08-11 05:49:45 +00:00
|
|
|
{
|
|
|
|
return exec.Fire(rhs, lhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template StaticDispatcher
|
|
|
|
// Implements an automatic static double dispatcher based on two typelists
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
|
|
|
class Executor,
|
2009-02-02 06:23:28 +00:00
|
|
|
class BaseLhs,
|
2002-08-11 05:49:45 +00:00
|
|
|
class TypesLhs,
|
|
|
|
bool symmetric = true,
|
|
|
|
class BaseRhs = BaseLhs,
|
|
|
|
class TypesRhs = TypesLhs,
|
|
|
|
typename ResultType = void
|
|
|
|
>
|
|
|
|
class StaticDispatcher
|
|
|
|
{
|
|
|
|
template <class SomeLhs>
|
|
|
|
static ResultType DispatchRhs(SomeLhs& lhs, BaseRhs& rhs,
|
2009-02-02 06:23:28 +00:00
|
|
|
Executor & exec, NullType)
|
2002-08-11 05:49:45 +00:00
|
|
|
{ return exec.OnError(lhs, rhs); }
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2003-02-27 20:09:08 +00:00
|
|
|
template <class Head, class Tail, class SomeLhs>
|
2002-08-11 05:49:45 +00:00
|
|
|
static ResultType DispatchRhs(SomeLhs& lhs, BaseRhs& rhs,
|
2009-02-02 06:23:28 +00:00
|
|
|
Executor & exec, Typelist<Head, Tail>)
|
|
|
|
{
|
2002-08-11 05:49:45 +00:00
|
|
|
if (Head* p2 = dynamic_cast<Head*>(&rhs))
|
|
|
|
{
|
|
|
|
Int2Type<(symmetric &&
|
|
|
|
int(TL::IndexOf<TypesRhs, Head>::value) <
|
|
|
|
int(TL::IndexOf<TypesLhs, SomeLhs>::value))> i2t;
|
|
|
|
|
2009-02-02 06:23:28 +00:00
|
|
|
typedef Private::InvocationTraits<
|
2002-08-11 05:49:45 +00:00
|
|
|
SomeLhs, Head, Executor, ResultType> CallTraits;
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
return CallTraits::DoDispatch(lhs, *p2, exec, i2t);
|
|
|
|
}
|
|
|
|
return DispatchRhs(lhs, rhs, exec, Tail());
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
static ResultType DispatchLhs(BaseLhs& lhs, BaseRhs& rhs,
|
2009-02-02 06:23:28 +00:00
|
|
|
Executor & exec, NullType)
|
2002-08-11 05:49:45 +00:00
|
|
|
{ return exec.OnError(lhs, rhs); }
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2003-02-27 20:09:08 +00:00
|
|
|
template <class Head, class Tail>
|
2002-08-11 05:49:45 +00:00
|
|
|
static ResultType DispatchLhs(BaseLhs& lhs, BaseRhs& rhs,
|
2009-02-02 06:23:28 +00:00
|
|
|
Executor & exec, Typelist<Head, Tail>)
|
|
|
|
{
|
2002-08-11 05:49:45 +00:00
|
|
|
if (Head* p1 = dynamic_cast<Head*>(&lhs))
|
|
|
|
{
|
|
|
|
return DispatchRhs(*p1, rhs, exec, TypesRhs());
|
|
|
|
}
|
|
|
|
return DispatchLhs(lhs, rhs, exec, Tail());
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static ResultType Go(BaseLhs& lhs, BaseRhs& rhs,
|
2009-02-02 06:23:28 +00:00
|
|
|
Executor & exec)
|
2002-08-11 05:49:45 +00:00
|
|
|
{ return DispatchLhs(lhs, rhs, exec, TypesLhs()); }
|
|
|
|
};
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template BasicDispatcher
|
|
|
|
// Implements a logarithmic double dispatcher for functors (or functions)
|
|
|
|
// Doesn't offer automated casts or symmetry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template
|
|
|
|
<
|
|
|
|
class BaseLhs,
|
|
|
|
class BaseRhs = BaseLhs,
|
|
|
|
typename ResultType = void,
|
|
|
|
typename CallbackType = ResultType (*)(BaseLhs&, BaseRhs&)
|
|
|
|
>
|
|
|
|
class BasicDispatcher
|
|
|
|
{
|
|
|
|
typedef std::pair<TypeInfo,TypeInfo> KeyType;
|
|
|
|
typedef CallbackType MappedType;
|
|
|
|
typedef AssocVector<KeyType, MappedType> MapType;
|
|
|
|
MapType callbackMap_;
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
void DoAdd(TypeInfo lhs, TypeInfo rhs, CallbackType fun);
|
|
|
|
bool DoRemove(TypeInfo lhs, TypeInfo rhs);
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
public:
|
|
|
|
template <class SomeLhs, class SomeRhs>
|
|
|
|
void Add(CallbackType fun)
|
|
|
|
{
|
|
|
|
DoAdd(typeid(SomeLhs), typeid(SomeRhs), fun);
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class SomeLhs, class SomeRhs>
|
|
|
|
bool Remove()
|
|
|
|
{
|
|
|
|
return DoRemove(typeid(SomeLhs), typeid(SomeRhs));
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
ResultType Go(BaseLhs& lhs, BaseRhs& rhs);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Non-inline to reduce compile time overhead...
|
2009-02-02 06:23:28 +00:00
|
|
|
template <class BaseLhs, class BaseRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
typename ResultType, typename CallbackType>
|
2002-08-11 05:49:45 +00:00
|
|
|
void BasicDispatcher<BaseLhs,BaseRhs,ResultType,CallbackType>
|
2005-10-30 14:03:23 +00:00
|
|
|
::DoAdd(TypeInfo lhs, TypeInfo rhs, CallbackType fun)
|
2002-08-11 05:49:45 +00:00
|
|
|
{
|
|
|
|
callbackMap_[KeyType(lhs, rhs)] = fun;
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
|
|
|
template <class BaseLhs, class BaseRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
typename ResultType, typename CallbackType>
|
2002-08-11 05:49:45 +00:00
|
|
|
bool BasicDispatcher<BaseLhs,BaseRhs,ResultType,CallbackType>
|
|
|
|
::DoRemove(TypeInfo lhs, TypeInfo rhs)
|
|
|
|
{
|
|
|
|
return callbackMap_.erase(KeyType(lhs, rhs)) == 1;
|
|
|
|
}
|
|
|
|
|
2009-02-02 06:23:28 +00:00
|
|
|
template <class BaseLhs, class BaseRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
typename ResultType, typename CallbackType>
|
2002-08-11 05:49:45 +00:00
|
|
|
ResultType BasicDispatcher<BaseLhs,BaseRhs,ResultType,CallbackType>
|
|
|
|
::Go(BaseLhs& lhs, BaseRhs& rhs)
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
typename MapType::key_type k(typeid(lhs),typeid(rhs));
|
2002-08-11 05:49:45 +00:00
|
|
|
typename MapType::iterator i = callbackMap_.find(k);
|
|
|
|
if (i == callbackMap_.end())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Function not found");
|
|
|
|
}
|
|
|
|
return (i->second)(lhs, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template StaticCaster
|
|
|
|
// Implementation of the CastingPolicy used by FunctorDispatcher
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template <class To, class From>
|
|
|
|
struct StaticCaster
|
|
|
|
{
|
|
|
|
static To& Cast(From& obj)
|
|
|
|
{
|
|
|
|
return static_cast<To&>(obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template DynamicCaster
|
|
|
|
// Implementation of the CastingPolicy used by FunctorDispatcher
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template <class To, class From>
|
|
|
|
struct DynamicCaster
|
|
|
|
{
|
|
|
|
static To& Cast(From& obj)
|
|
|
|
{
|
|
|
|
return dynamic_cast<To&>(obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template Private::FnDispatcherHelper
|
|
|
|
// Implements trampolines and argument swapping used by FnDispatcher
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Private
|
|
|
|
{
|
|
|
|
template <class BaseLhs, class BaseRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
class SomeLhs, class SomeRhs,
|
2002-08-11 05:49:45 +00:00
|
|
|
typename ResultType,
|
|
|
|
class CastLhs, class CastRhs,
|
|
|
|
ResultType (*Callback)(SomeLhs&, SomeRhs&)>
|
|
|
|
struct FnDispatcherHelper
|
|
|
|
{
|
|
|
|
static ResultType Trampoline(BaseLhs& lhs, BaseRhs& rhs)
|
|
|
|
{
|
|
|
|
return Callback(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
|
|
|
|
}
|
|
|
|
static ResultType TrampolineR(BaseRhs& rhs, BaseLhs& lhs)
|
|
|
|
{
|
|
|
|
return Trampoline(lhs, rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template FnDispatcher
|
|
|
|
// Implements an automatic logarithmic double dispatcher for functions
|
|
|
|
// Features automated conversions
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template <class BaseLhs, class BaseRhs = BaseLhs,
|
|
|
|
typename ResultType = void,
|
|
|
|
template <class, class> class CastingPolicy = DynamicCaster,
|
|
|
|
template <class, class, class, class>
|
|
|
|
class DispatcherBackend = BasicDispatcher>
|
|
|
|
class FnDispatcher
|
|
|
|
{
|
2009-02-02 06:23:28 +00:00
|
|
|
DispatcherBackend<BaseLhs, BaseRhs, ResultType,
|
2002-08-11 05:49:45 +00:00
|
|
|
ResultType (*)(BaseLhs&, BaseRhs&)> backEnd_;
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
public:
|
|
|
|
template <class SomeLhs, class SomeRhs>
|
|
|
|
void Add(ResultType (*pFun)(BaseLhs&, BaseRhs&))
|
|
|
|
{
|
2003-02-02 16:35:14 +00:00
|
|
|
return backEnd_.template Add<SomeLhs, SomeRhs>(pFun);
|
2009-02-02 06:23:28 +00:00
|
|
|
}
|
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class SomeLhs, class SomeRhs,
|
|
|
|
ResultType (*callback)(SomeLhs&, SomeRhs&)>
|
|
|
|
void Add()
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
typedef Private::FnDispatcherHelper<
|
2009-02-02 06:23:28 +00:00
|
|
|
BaseLhs, BaseRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
SomeLhs, SomeRhs,
|
|
|
|
ResultType,
|
2009-02-02 06:23:28 +00:00
|
|
|
CastingPolicy<SomeLhs,BaseLhs>,
|
|
|
|
CastingPolicy<SomeRhs,BaseRhs>,
|
2005-10-30 14:03:23 +00:00
|
|
|
callback> Local;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
Add<SomeLhs, SomeRhs>(&Local::Trampoline);
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class SomeLhs, class SomeRhs,
|
|
|
|
ResultType (*callback)(SomeLhs&, SomeRhs&),
|
|
|
|
bool symmetric>
|
2003-02-27 20:09:08 +00:00
|
|
|
void Add(bool = true) // [gcc] dummy bool
|
2002-08-11 05:49:45 +00:00
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
typedef Private::FnDispatcherHelper<
|
2009-02-02 06:23:28 +00:00
|
|
|
BaseLhs, BaseRhs,
|
2005-10-30 14:03:23 +00:00
|
|
|
SomeLhs, SomeRhs,
|
|
|
|
ResultType,
|
2009-02-02 06:23:28 +00:00
|
|
|
CastingPolicy<SomeLhs,BaseLhs>,
|
|
|
|
CastingPolicy<SomeRhs,BaseRhs>,
|
2005-10-30 14:03:23 +00:00
|
|
|
callback> Local;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
Add<SomeLhs, SomeRhs>(&Local::Trampoline);
|
|
|
|
if (symmetric)
|
|
|
|
{
|
|
|
|
Add<SomeRhs, SomeLhs>(&Local::TrampolineR);
|
|
|
|
}
|
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class SomeLhs, class SomeRhs>
|
|
|
|
void Remove()
|
|
|
|
{
|
2003-02-02 16:35:14 +00:00
|
|
|
backEnd_.template Remove<SomeLhs, SomeRhs>();
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultType Go(BaseLhs& lhs, BaseRhs& rhs)
|
|
|
|
{
|
|
|
|
return backEnd_.Go(lhs, rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template FunctorDispatcherAdaptor
|
|
|
|
// permits use of FunctorDispatcher under gcc.2.95.2/3
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
namespace Private
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
template <class BaseLhs, class BaseRhs,
|
|
|
|
class SomeLhs, class SomeRhs,
|
|
|
|
typename ResultType,
|
|
|
|
class CastLhs, class CastRhs,
|
|
|
|
class Fun, bool SwapArgs>
|
2009-02-02 06:23:28 +00:00
|
|
|
class FunctorDispatcherHelper
|
2002-08-11 05:49:45 +00:00
|
|
|
{
|
|
|
|
Fun fun_;
|
|
|
|
ResultType Fire(BaseLhs& lhs, BaseRhs& rhs,Int2Type<false>)
|
|
|
|
{
|
|
|
|
return fun_(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
|
|
|
|
}
|
|
|
|
ResultType Fire(BaseLhs& rhs, BaseRhs& lhs,Int2Type<true>)
|
|
|
|
{
|
|
|
|
return fun_(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
FunctorDispatcherHelper(const Fun& fun) : fun_(fun) {}
|
|
|
|
|
|
|
|
ResultType operator()(BaseLhs& lhs, BaseRhs& rhs)
|
|
|
|
{
|
|
|
|
return Fire(lhs,rhs,Int2Type<SwapArgs>());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// class template FunctorDispatcher
|
|
|
|
// Implements a logarithmic double dispatcher for functors
|
|
|
|
// Features automated casting
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
template <class BaseLhs, class BaseRhs = BaseLhs,
|
|
|
|
typename ResultType = void,
|
2009-02-02 06:23:28 +00:00
|
|
|
template <class, class> class CastingPolicy = DynamicCaster,
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class, class, class, class>
|
|
|
|
class DispatcherBackend = BasicDispatcher>
|
|
|
|
class FunctorDispatcher
|
|
|
|
{
|
2005-09-26 07:33:05 +00:00
|
|
|
typedef LOKI_TYPELIST_2(BaseLhs&, BaseRhs&) ArgsList;
|
|
|
|
typedef Functor<ResultType, ArgsList, LOKI_DEFAULT_THREADING> FunctorType;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
|
|
|
DispatcherBackend<BaseLhs, BaseRhs, ResultType, FunctorType> backEnd_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
template <class SomeLhs, class SomeRhs, class Fun>
|
|
|
|
void Add(const Fun& fun)
|
|
|
|
{
|
|
|
|
typedef Private::FunctorDispatcherHelper<
|
2005-10-30 14:03:23 +00:00
|
|
|
BaseLhs, BaseRhs,
|
|
|
|
SomeLhs, SomeRhs,
|
|
|
|
ResultType,
|
|
|
|
CastingPolicy<SomeLhs, BaseLhs>,
|
|
|
|
CastingPolicy<SomeRhs, BaseRhs>,
|
|
|
|
Fun, false> Adapter;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
2003-02-02 16:35:14 +00:00
|
|
|
backEnd_.template Add<SomeLhs, SomeRhs>(FunctorType(Adapter(fun)));
|
2005-10-30 14:03:23 +00:00
|
|
|
}
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class SomeLhs, class SomeRhs, bool symmetric, class Fun>
|
|
|
|
void Add(const Fun& fun)
|
|
|
|
{
|
2005-10-30 14:03:23 +00:00
|
|
|
Add<SomeLhs,SomeRhs>(fun);
|
|
|
|
|
|
|
|
if (symmetric)
|
|
|
|
{
|
|
|
|
// Note: symmetry only makes sense where BaseLhs==BaseRhs
|
|
|
|
typedef Private::FunctorDispatcherHelper<
|
|
|
|
BaseLhs, BaseLhs,
|
|
|
|
SomeLhs, SomeRhs,
|
|
|
|
ResultType,
|
|
|
|
CastingPolicy<SomeLhs, BaseLhs>,
|
|
|
|
CastingPolicy<SomeRhs, BaseLhs>,
|
|
|
|
Fun, true> AdapterR;
|
2002-08-11 05:49:45 +00:00
|
|
|
|
2003-02-02 16:35:14 +00:00
|
|
|
backEnd_.template Add<SomeRhs, SomeLhs>(FunctorType(AdapterR(fun)));
|
2005-10-30 14:03:23 +00:00
|
|
|
}
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
2009-02-02 06:23:28 +00:00
|
|
|
|
2002-08-11 05:49:45 +00:00
|
|
|
template <class SomeLhs, class SomeRhs>
|
|
|
|
void Remove()
|
|
|
|
{
|
2003-02-02 16:35:14 +00:00
|
|
|
backEnd_.template Remove<SomeLhs, SomeRhs>();
|
2002-08-11 05:49:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultType Go(BaseLhs& lhs, BaseRhs& rhs)
|
|
|
|
{
|
|
|
|
return backEnd_.Go(lhs, rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace Loki
|
|
|
|
|
|
|
|
|
2006-01-16 19:05:09 +00:00
|
|
|
|
2006-10-17 19:31:51 +00:00
|
|
|
#endif // end file guardian
|
|
|
|
|