30#ifndef vtkDispatcher_Private_h
31#define vtkDispatcher_Private_h
46template <
class BaseLhs,
class SomeLhs,
typename RT,
class CastLhs,
class Fun>
72template <
class BaseLhs,
class SomeLhs,
typename RT,
class CastLhs,
class Fun>
95template <
typename R,
typename P1>
111 U* pClone =
static_cast<U*
>(pObj->DoClone());
112 assert(
typeid(*pClone) ==
typeid(*pObj));
127template <
class ParentFunctor,
typename Fun>
130 typedef typename ParentFunctor::Impl Base;
148 : ParentFunctor::Impl(b)
152 FunctorHandler& operator=(
const FunctorHandler& b) =
delete;
158template <
typename R,
typename Parm1>
171 : spImpl_(
Impl::Clone(rhs.spImpl_.get()))
175 template <
typename Fun>
184 spImpl_.swap(copy.spImpl_);
191 std::unique_ptr<Impl> spImpl_;
202template <
class BaseLhs,
class BaseRhs,
class SomeLhs,
class SomeRhs,
typename RT,
class CastLhs,
203 class CastRhs,
class Fun>
204class FunctorRefDispatcherHelper
209 typedef RT ResultType;
210 FunctorRefDispatcherHelper(
const FunctorRefDispatcherHelper& rhs)
214 FunctorRefDispatcherHelper(Fun& fun)
219 ResultType operator()(BaseLhs& lhs, BaseRhs& rhs)
221 return fun_(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
225 FunctorRefDispatcherHelper& operator=(
const FunctorRefDispatcherHelper& b) =
delete;
228template <
class BaseLhs,
class BaseRhs,
class SomeLhs,
class SomeRhs,
typename RT,
class CastLhs,
229 class CastRhs,
class Fun>
230class FunctorDoubleDispatcherHelper
235 typedef RT ResultType;
236 FunctorDoubleDispatcherHelper(
const FunctorDoubleDispatcherHelper& rhs)
240 FunctorDoubleDispatcherHelper(Fun fun)
245 ResultType operator()(BaseLhs& lhs, BaseRhs& rhs)
247 return fun_(CastLhs::Cast(lhs), CastRhs::Cast(rhs));
254template <
typename R,
typename P1,
typename P2>
258 typedef R ResultType;
262 virtual ~FunctorImpl() =
default;
263 virtual R operator()(P1&, P2&) = 0;
264 virtual FunctorImpl* DoClone()
const = 0;
267 static U* Clone(U* pObj)
271 U* pClone =
static_cast<U*
>(pObj->DoClone());
272 assert(
typeid(*pClone) ==
typeid(*pObj));
277 FunctorImpl() =
default;
278 FunctorImpl(
const FunctorImpl&) =
default;
281 FunctorImpl& operator=(
const FunctorImpl&) =
delete;
287template <
class ParentFunctor,
typename Fun>
288class FunctorHandler :
public ParentFunctor::Impl
290 typedef typename ParentFunctor::Impl Base;
293 typedef typename Base::ResultType ResultType;
294 typedef typename Base::Parm1 Parm1;
295 typedef typename Base::Parm2 Parm2;
297 FunctorHandler(
const Fun& fun)
301 ~FunctorHandler()
override =
default;
303 ResultType operator()(Parm1& p1, Parm2& p2)
override {
return f_(p1, p2); }
305 FunctorHandler* DoClone()
const override {
return new FunctorHandler(*
this); }
309 FunctorHandler(
const FunctorHandler& b)
310 : ParentFunctor::Impl(b)
314 FunctorHandler& operator=(
const FunctorHandler& b) =
delete;
320template <
typename R,
typename Parm1,
typename Parm2>
324 typedef FunctorImpl<R, Parm1, Parm2> Impl;
325 typedef R ResultType;
332 Functor(
const Functor& rhs)
333 : spImpl_(Impl::Clone(rhs.spImpl_.get()))
337 template <
typename Fun>
338 Functor(
const Fun& fun)
339 : spImpl_(
new FunctorHandler<Functor, Fun>(fun))
343 Functor& operator=(
const Functor& rhs)
346 spImpl_.swap(copy.spImpl_);
350 ResultType operator()(Parm1& p1, Parm2& p2) {
return (*spImpl_)(p1, p2); }
353 std::unique_ptr<Impl> spImpl_;
360template <
class To,
class From>
363 static To& Cast(From& obj) {
return dynamic_cast<To&
>(obj); }
365 static To* Cast(From* obj) {
return dynamic_cast<To*
>(obj); }
368template <
class To,
class From>
371 static To& Cast(From& obj) {
return *(To::SafeDownCast(&obj)); }
373 static To* Cast(From* obj) {
return To::SafeDownCast(obj); }
381 TypeInfo(
const std::type_info&);
384 const std::type_info& Get()
const;
386 bool before(
const TypeInfo& rhs)
const;
387 const char* name()
const;
390 const std::type_info* pInfo_;
395inline TypeInfo::TypeInfo()
400 pInfo_ = &
typeid(Nil);
404inline TypeInfo::TypeInfo(
const std::type_info& ti)
410inline bool TypeInfo::before(
const TypeInfo& rhs)
const
414 return pInfo_->before(*rhs.pInfo_) != 0;
417inline const std::type_info& TypeInfo::Get()
const
423inline const char* TypeInfo::name()
const
426 return pInfo_->name();
431inline bool operator==(
const TypeInfo& lhs,
const TypeInfo& rhs)
434 return (lhs.Get() == rhs.Get()) != 0;
437inline bool operator<(
const TypeInfo& lhs,
const TypeInfo& rhs)
439 return lhs.before(rhs);
442inline bool operator!=(
const TypeInfo& lhs,
const TypeInfo& rhs)
444 return !(lhs == rhs);
447inline bool operator>(
const TypeInfo& lhs,
const TypeInfo& rhs)
452inline bool operator<=(
const TypeInfo& lhs,
const TypeInfo& rhs)
457inline bool operator>=(
const TypeInfo& lhs,
const TypeInfo& rhs)
FunctorDispatcherHelper(Fun fun)
ResultType operator()(BaseLhs &lhs)
FunctorDispatcherHelper(const FunctorDispatcherHelper &rhs)
ResultType operator()(Parm1 &p1) override
~FunctorHandler() override=default
FunctorHandler * DoClone() const override
Base::ResultType ResultType
FunctorImpl(const FunctorImpl &)=default
virtual FunctorImpl * DoClone() const =0
virtual ~FunctorImpl()=default
virtual R operator()(P1 &)=0
static U * Clone(U *pObj)
FunctorRefDispatcherHelper(Fun &f)
FunctorRefDispatcherHelper(const FunctorRefDispatcherHelper &rhs)
ResultType operator()(BaseLhs &lhs)
Functor(const Functor &rhs)
Functor & operator=(const Functor &rhs)
FunctorImpl< R, Parm1 > Impl
ResultType operator()(Parm1 &p1)
VTKCOMMONCORE_EXPORT bool operator!=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator>(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator>=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
VTKCOMMONCORE_EXPORT bool operator<=(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)