55 #ifndef __UT_Functor_h__
56 #define __UT_Functor_h__
86 template <
typename R,
typename P1>
104 template <
typename R,
typename P1,
typename P2>
125 template <
typename ParentFunctor,
typename FunctorType>
143 {
return myFunctor(); }
146 FunctorType myFunctor;
151 template <
typename ParentFunctor,
typename FunctorType>
154 typename ParentFunctor::Parm1Type>
160 : myFunctor(functor) {}
166 {
return myFunctor(parm1); }
170 int64 mem = inclusive ?
sizeof(*this) : 0;
175 FunctorType myFunctor;
180 template <
typename ParentFunctor,
typename FunctorType>
183 typename ParentFunctor::Parm1Type,
184 typename ParentFunctor::Parm2Type>
191 : myFunctor(functor) {}
197 {
return myFunctor(parm1, parm2); }
200 FunctorType myFunctor;
206 template <
typename ParentFunctor,
typename PointerToObj,
207 typename PointerToMemFn>
215 const PointerToMemFn pointer_to_mem_fn)
216 : myPointerToObj(pointer_to_obj), myPointerToMemFn(pointer_to_mem_fn)
221 PointerToMemFn>(*this); }
224 {
return ((*myPointerToObj).*myPointerToMemFn)(); }
227 PointerToObj myPointerToObj;
228 PointerToMemFn myPointerToMemFn;
233 template <
typename ParentFunctor,
typename PointerToObj,
234 typename PointerToMemFn>
237 typename ParentFunctor::Parm1Type>
244 const PointerToMemFn pointer_to_mem_fn)
245 : myPointerToObj(pointer_to_obj), myPointerToMemFn(pointer_to_mem_fn)
250 PointerToMemFn>(*this); }
253 {
return ((*myPointerToObj).*myPointerToMemFn)(parm1); }
257 int64 mem = inclusive ?
sizeof(*this) : 0;
262 PointerToObj myPointerToObj;
263 PointerToMemFn myPointerToMemFn;
268 template <
typename ParentFunctor,
typename PointerToObj,
269 typename PointerToMemFn>
272 typename ParentFunctor::Parm1Type,
273 typename ParentFunctor::Parm2Type>
281 const PointerToMemFn pointer_to_mem_fn)
282 : myPointerToObj(pointer_to_obj), myPointerToMemFn(pointer_to_mem_fn)
287 PointerToMemFn>(*this); }
290 {
return ((*myPointerToObj).*myPointerToMemFn)(parm1, parm2); }
293 PointerToObj myPointerToObj;
294 PointerToMemFn myPointerToMemFn;
300 template <
typename R>
311 : myFunctorImpl(functor_implementation)
316 myFunctorImpl.myFunctorImpl = src.myFunctorImpl.myFunctorImpl
317 ? src.myFunctorImpl.myFunctorImpl->clone() :
nullptr;
326 template <
typename FunctorType>
334 template <
typename Po
interToObj,
typename Po
interToMemFn>
337 PointerToMemFn>(pointer, method))
343 delete myFunctorImpl.myFunctorImpl;
344 myFunctorImpl.myFunctorImpl = 0;
350 if (&functor !=
this)
352 delete myFunctorImpl.myFunctorImpl;
353 myFunctorImpl.myFunctorImpl = functor.myFunctorImpl.myFunctorImpl
354 ? functor.myFunctorImpl.myFunctorImpl->clone() : 0;
366 return (*myFunctorImpl.myFunctorImpl)();
369 explicit operator bool() const noexcept {
return isSet(); }
373 {
return myFunctorImpl.myFunctorImpl != 0; }
382 Helper() : myFunctorImpl(0) {}
385 Helper(
const Helper &helper)
386 { myFunctorImpl = helper.myFunctorImpl
387 ? helper.myFunctorImpl->clone() : 0; }
390 : myFunctorImpl(functor_implementation) {}
393 explicit Helper(U *
ptr) : myFunctorImpl(ptr) {}
398 Helper myFunctorImpl;
403 template <
typename R,
typename P1>
415 : myFunctorImpl(functor_implementation)
418 template <
typename FunctorType>
423 template <
typename Po
interToObj,
typename Po
interToMemFn>
426 PointerToMemFn>(pointer, method))
431 myFunctorImpl.myFunctorImpl = src.myFunctorImpl.myFunctorImpl
432 ? src.myFunctorImpl.myFunctorImpl->clone() :
nullptr;
437 delete myFunctorImpl.myFunctorImpl;
438 myFunctorImpl.myFunctorImpl = 0;
443 if (&functor !=
this)
445 delete myFunctorImpl.myFunctorImpl;
446 myFunctorImpl.myFunctorImpl = functor.myFunctorImpl.myFunctorImpl
447 ? functor.myFunctorImpl.myFunctorImpl->clone() : 0;
455 return (*myFunctorImpl.myFunctorImpl)(parm1);
458 explicit operator bool() const noexcept {
return isSet(); }
461 {
return myFunctorImpl.myFunctorImpl != 0; }
465 int64 mem = inclusive ?
sizeof(*this) : 0;
466 if (myFunctorImpl.myFunctorImpl)
467 mem += myFunctorImpl.myFunctorImpl->getMemoryUsage(
true);
475 Helper() : myFunctorImpl(0) {}
478 Helper(
const Helper &helper)
479 { myFunctorImpl = helper.myFunctorImpl
480 ? helper.myFunctorImpl->clone() : 0; }
484 : myFunctorImpl(functor_implementation) {}
487 explicit Helper(U *
ptr) : myFunctorImpl(ptr) {}
492 Helper myFunctorImpl;
497 template <
typename R,
typename P1,
typename P2>
509 : myFunctorImpl(functor_impl)
514 myFunctorImpl.myFunctorImpl = src.myFunctorImpl.myFunctorImpl
515 ? src.myFunctorImpl.myFunctorImpl->clone() :
nullptr;
518 template <
typename FunctorType>
523 template <
typename Po
interToObj,
typename Po
interToMemFn>
526 PointerToMemFn>(pointer, method))
531 delete myFunctorImpl.myFunctorImpl;
532 myFunctorImpl.myFunctorImpl = 0;
537 if (&functor !=
this)
539 delete myFunctorImpl.myFunctorImpl;
540 myFunctorImpl.myFunctorImpl = functor.myFunctorImpl.myFunctorImpl
541 ? functor.myFunctorImpl.myFunctorImpl->clone() :
nullptr;
549 return (*myFunctorImpl.myFunctorImpl)(parm1, parm2);
552 explicit operator bool() const noexcept {
return isSet(); }
555 {
return myFunctorImpl.myFunctorImpl != 0; }
561 Helper() : myFunctorImpl(0) {}
564 Helper(
const Helper &helper)
565 { myFunctorImpl = helper.myFunctorImpl
566 ? helper.myFunctorImpl->clone() : 0; }
570 : myFunctorImpl(functor_impl) {}
573 explicit Helper(U *
ptr) : myFunctorImpl(ptr) {}
578 Helper myFunctorImpl;
585 template <
typename Incoming>
593 : myFunctor(functor), myBoundArgument(bound_argument)
600 {
return myFunctor(myBoundArgument); }
609 template <
typename Functor>
611 UT_BindFirst(
const Functor &functor,
typename Functor::Parm1Type bound_argument)
622 template <
typename Incoming>
624 typename Incoming::Parm2Type>
632 : myFunctor(functor), myBoundArgument(bound_argument)
639 {
return myFunctor(myBoundArgument, parm1); }
643 int64 mem = inclusive ?
sizeof(*this) : 0;
652 template <
typename Functor>
655 typename Functor::Parm1Type bound_argument)
657 typedef typename Functor::ReturnType ReturnType;
658 typedef typename Functor::Parm2Type Parm1Type;
669 #if defined(WIN32) || defined(LINUX) || defined(MBSD)
Incoming::Parm1Type BoundType
UT_FunctorImpl1 & operator=(const UT_FunctorImpl1 &)=delete
UT_FunctorImpl & operator=(const UT_FunctorImpl &)=delete
UT_MemFunHandler1(const PointerToObj &pointer_to_obj, const PointerToMemFn pointer_to_mem_fn)
ParentFunctor::Parm2Type Parm2Type
UT_Functor< typename Functor::ReturnType > UT_BindFirst(const Functor &functor, typename Functor::Parm1Type bound_argument)
virtual ReturnType operator()(Parm1Type parm1) const =0
UT_FunctorHandler(const FunctorType &functor)
virtual ReturnType operator()() const =0
ParentFunctor::ReturnType ReturnType
UT_Functor(const this_type &src)
UT_FunctorImpl< ReturnType > * clone() const override
ParentFunctor::Parm1Type Parm1Type
UT_Functor(FunctorType functor)
UT_FunctorHandler1(const FunctorType &functor)
ParentFunctor::Parm1Type Parm1Type
UT_Functor(UT_FunctorImpl< ReturnType > *functor_implementation)
UT_FunctorHandler2(const FunctorType &functor)
UT_Functor(const PointerToObj &pointer, PointerToMemFn method)
Incoming::Parm1Type BoundType
UT_FunctorImpl2()=default
int64 getMemoryUsage(bool inclusive) const override
Incoming::ReturnType ReturnType
ReturnType operator()(Parm1Type parm1) const override
UT_Functor1(FunctorType functor)
virtual ~UT_FunctorImpl1()
UT_FunctorImpl< ReturnType > * clone() const override
virtual ReturnType operator()(Parm1Type parm1, Parm2Type parm2) const =0
UT_Functor1< typename Functor::ReturnType, typename Functor::Parm2Type > UT_BindFirst1(const Functor &functor, typename Functor::Parm1Type bound_argument)
ParentFunctor::ReturnType ReturnType
UT_FunctorImpl1< ReturnType, Parm1Type > * clone() const override
ReturnType operator()(Parm1Type parm1, Parm2Type parm2) const
UT_Functor1(UT_FunctorImpl1< ReturnType, Parm1Type > *functor_implementation)
ReturnType operator()(Parm1Type parm1) const override
int64 getMemoryUsage(bool inclusive) const override
int64 getMemoryUsage(bool inclusive) const
UT_FunctorImpl2< ReturnType, Parm1Type, Parm2Type > * clone() const override
UT_MemFunHandler(const PointerToObj &pointer_to_obj, const PointerToMemFn pointer_to_mem_fn)
ReturnType operator()() const override
UT_Functor1(const this_type &src)
ReturnType operator()(Parm1Type parm1) const override
UT_FunctorImpl2< ReturnType, Parm1Type, Parm2Type > * clone() const override
UT_Functor2(UT_FunctorImpl2< ReturnType, Parm1Type, Parm2Type > *functor_impl)
ReturnType operator()(Parm1Type parm1, Parm2Type parm2) const override
virtual int64 getMemoryUsage(bool inclusive) const =0
Incoming::ReturnType ReturnType
ReturnType operator()(Parm1Type parm1) const
UT_FunctorImpl1< ReturnType, Parm1Type > * clone() const override
ParentFunctor::Parm1Type Parm1Type
UT_Functor1(const PointerToObj &pointer, PointerToMemFn method)
Incoming::Parm2Type Parm1Type
virtual UT_FunctorImpl2< ReturnType, Parm1Type, Parm2Type > * clone() const =0
ParentFunctor::Parm2Type Parm2Type
UT_BindFirstImpl1(const Incoming &functor, BoundType bound_argument)
ParentFunctor::ReturnType ReturnType
UT_Functor2(FunctorType functor)
virtual UT_FunctorImpl1< ReturnType, Parm1Type > * clone() const =0
ParentFunctor::ReturnType ReturnType
UT_FunctorImpl2 & operator=(const UT_FunctorImpl2 &)=delete
int64 getMemoryUsage(bool inclusive) const override
ReturnType operator()(Parm1Type parm1, Parm2Type parm2) const override
UT_FunctorImpl1()=default
UT_Functor2 & operator=(const UT_Functor2 &functor)
UT_Functor2(const this_type &src)
virtual ~UT_FunctorImpl()
UT_MemFunHandler2(const PointerToObj &pointer_to_obj, const PointerToMemFn pointer_to_mem_fn)
UT_Functor & operator=(const UT_Functor &functor)
ParentFunctor::ReturnType ReturnType
UT_FunctorImpl< ReturnType > * clone() const override
UT_Functor2(const PointerToObj &pointer, PointerToMemFn method)
virtual ~UT_FunctorImpl2()
UT_BindFirstImpl(const Incoming &functor, BoundType bound_argument)
ReturnType operator()() const override
virtual UT_FunctorImpl< ReturnType > * clone() const =0
ParentFunctor::ReturnType ReturnType
ReturnType operator()() const override
ReturnType operator()() const
UT_Functor1 & operator=(const UT_Functor1 &functor)
ParentFunctor::Parm1Type Parm1Type
UT_FunctorImpl1< ReturnType, Parm1Type > * clone() const override