72 #ifndef vtkDoubleDispatcher_h
73 #define vtkDoubleDispatcher_h
81 class BaseRhs = BaseLhs,
82 typename ReturnType = void,
98 template <
class SomeLhs,
class SomeRhs,
class Functor>
99 void Add(Functor fun) { this->AddInternal<SomeLhs,SomeRhs>(fun, 1); }
105 template <
class SomeLhs,
class SomeRhs>
120 ReturnType
Go(BaseLhs* lhs, BaseRhs* rhs);
128 bool DoRemove(TypeInfo lhs, TypeInfo rhs);
131 typedef std::map<KeyType, MappedType >
MapType;
134 template <
class SomeLhs,
class SomeRhs,
class Functor>
135 void AddInternal(
const Functor& fun,
long);
136 template <
class SomeLhs,
class SomeRhs,
class Functor>
137 void AddInternal(Functor* fun,
int);
142 template<
class BaseLhs,
class BaseRhs,
typename ReturnType,
143 template <
class,
class>
class CastingPolicy>
144 template <
class SomeLhs,
class SomeRhs,
class Functor>
152 CastingPolicy<SomeLhs, BaseLhs>,
153 CastingPolicy<SomeRhs, BaseRhs>,
157 DoAddFunctor(
typeid(SomeLhs),
typeid(SomeRhs),mt);
161 template<
class BaseLhs,
class BaseRhs,
typename ReturnType,
162 template <
class,
class>
class CastingPolicy>
163 template <
class SomeLhs,
class SomeRhs,
class Functor>
171 CastingPolicy<SomeLhs, BaseLhs>,
172 CastingPolicy<SomeRhs, BaseRhs>,
176 DoAddFunctor(
typeid(SomeLhs),
typeid(SomeRhs),mt);
180 template<
class BaseLhs,
class BaseRhs,
typename ReturnType,
181 template <
class,
class>
class CastingPolicy>
185 FunctorMap[
KeyType(lhs, rhs)] = fun;
189 template <
class BaseLhs,
class BaseRhs,
typename ReturnType,
190 template <
class,
class>
class CastingPolicy>
194 return FunctorMap.erase(
KeyType(lhs, rhs)) == 1;
198 template <
class BaseLhs,
class BaseRhs,
typename ReturnType,
199 template <
class,
class>
class CastingPolicy>
201 ::Go(BaseLhs* lhs, BaseRhs* rhs)
203 typename MapType::key_type k(
typeid(*lhs),
typeid(*rhs));
204 typename MapType::iterator i = FunctorMap.find(k);
205 if (i == FunctorMap.end())
211 return (i->second)(*lhs,*rhs);
214 #endif // vtkDoubleDispatcher_h
ReturnType Go(BaseLhs *lhs, BaseRhs *rhs)
std::map< KeyType, MappedType > MapType
void DoAddFunctor(TypeInfo lhs, TypeInfo rhs, MappedType fun)
vtkDispatcherCommon::TypeInfo TypeInfo
Dispatch to functor based on two pointer types.
bool DoRemove(TypeInfo lhs, TypeInfo rhs)
std::pair< TypeInfo, TypeInfo > KeyType
vtkDoubleDispatcherPrivate::Functor< ReturnType, BaseLhs, BaseRhs > MappedType