1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/*=========================================================================
Program: Visualization Toolkit
Module: FunctionPoilters.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef __FunctionPointers_h_
#define __FunctionPointers_h_
// Arbitrary functors
class BaseFunctor
{
public:
virtual ~BaseFunctor() { }
virtual void ExecVoid() = 0;
};
template <typename TReturn>
class Functor0Args : public BaseFunctor
{
public:
virtual ~Functor0Args() { }
virtual void ExecVoid()
{
(*this)();
}
virtual TReturn operator() () = 0;
};
template<typename TObject, typename TReturn>
class MemberFunction0Args : public Functor0Args<TReturn>
{
public:
typedef TReturn (TObject::*TFunctor)(void);
MemberFunction0Args(TObject *instance, TFunctor functionPtr)
: Instance(instance), FunctionPtr(functionPtr)
{ }
virtual ~MemberFunction0Args() { }
virtual TReturn operator() ()
{ return (this->Instance->*this->FunctionPtr)(); }
private:
TObject *Instance;
TFunctor FunctionPtr;
};
template<typename TObject, typename TReturn, typename TArg1>
class MemberFunction1Arg : public Functor0Args<TReturn>
{
public:
typedef TReturn (TObject::*TFunctor)(TArg1);
MemberFunction1Arg(TObject *instance, TFunctor functionPtr, TArg1 arg1)
: Instance(instance), FunctionPtr(functionPtr), Arg1(arg1)
{ }
virtual ~MemberFunction1Arg() { }
virtual TReturn operator() ()
{ return (this->Instance->*this->FunctionPtr)(this->Arg1); }
private:
TObject *Instance;
TFunctor FunctionPtr;
TArg1 Arg1;
};
template<typename TObject, typename TReturn, typename TArg1, typename TArg2>
class MemberFunction2Args : public Functor0Args<TReturn>
{
public:
typedef TReturn (TObject::*TFunctor)(TArg1, TArg2);
MemberFunction2Args(TObject *instance, TFunctor functionPtr,
TArg1 arg1, TArg2 arg2)
: Instance(instance), FunctionPtr(functionPtr), Arg1(arg1), Arg2(arg2)
{ }
virtual ~MemberFunction2Args() { }
virtual TReturn operator() ()
{ return (this->Instance->*this->FunctionPtr)(this->Arg1, this->Arg2); }
private:
TObject *Instance;
TFunctor FunctionPtr;
TArg1 Arg1;
TArg2 Arg2;
};
template<typename TObject, typename TReturn, typename TArg1, typename TArg2,
typename TArg3>
class MemberFunction3Args : public Functor0Args<TReturn>
{
public:
typedef TReturn (TObject::*TFunctor)(TArg1, TArg2, TArg3);
MemberFunction3Args(TObject *instance, TFunctor functionPtr,
TArg1 arg1, TArg2 arg2, TArg3 arg3)
: Instance(instance), FunctionPtr(functionPtr), Arg1(arg1), Arg2(arg2),
Arg3(arg3)
{ }
virtual ~MemberFunction3Args() { }
virtual TReturn operator() ()
{
return (this->Instance->*this->FunctionPtr)
(this->Arg1, this->Arg2, this->Arg3);
}
private:
TObject *Instance;
TFunctor FunctionPtr;
TArg1 Arg1;
TArg2 Arg2;
TArg3 Arg3;
};
#endif
// VTK-HeaderTest-Exclude: FunctionPointers.h
|