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