vtkMemberFunctionCommand.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkMemberFunctionCommand.h
5 
6  Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
7  All rights reserved.
8 
9  ParaView is a free software; you can redistribute it and/or modify it
10  under the terms of the ParaView license version 1.2.
11 
12  See License_v1.2.txt for the full ParaView license.
13  A copy of this license can be obtained by contacting
14  Kitware Inc.
15  28 Corporate Drive
16  Clifton Park, NY 12065
17  USA
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 =========================================================================*/
71 #include "vtkCommand.h"
72 
73 template <class ClassT>
75 {
77 
78 public:
80 
81  const char* GetClassNameInternal() const override { return "vtkMemberFunctionCommand"; }
82 
83  static ThisT* SafeDownCast(vtkObjectBase* o) { return dynamic_cast<ThisT*>(o); }
84 
85  static ThisT* New() { return new ThisT(); }
86 
87  void PrintSelf(ostream& os, vtkIndent indent) override { vtkCommand::PrintSelf(os, indent); }
88 
90 
94  void SetCallback(ClassT& object, void (ClassT::*method)())
95  {
96  this->Object = &object;
97  this->Method = method;
98  }
100 
101  void SetCallback(ClassT& object, void (ClassT::*method2)(vtkObject*, unsigned long, void*))
102  {
103  this->Object = &object;
104  this->Method2 = method2;
105  }
106 
107  void Execute(vtkObject* caller, unsigned long event, void* calldata) override
108  {
109  if (this->Object && this->Method)
110  {
111  (this->Object->*this->Method)();
112  }
113  if (this->Object && this->Method2)
114  {
115  (this->Object->*this->Method2)(caller, event, calldata);
116  }
117  }
118  void Reset()
119  {
120  this->Object = 0;
121  this->Method2 = 0;
122  this->Method = 0;
123  }
124 
125 private:
127  {
128  this->Object = 0;
129  this->Method = 0;
130  this->Method2 = 0;
131  }
132 
133  ~vtkMemberFunctionCommand() override {}
134 
135  ClassT* Object;
136  void (ClassT::*Method)();
137  void (ClassT::*Method2)(vtkObject* caller, unsigned long event, void* calldata);
138 
140  void operator=(const vtkMemberFunctionCommand&) = delete;
141 };
142 
158 template <class ClassT>
160  ClassT& object, void (ClassT::*method)())
161 {
163  result->SetCallback(object, method);
164  return result;
165 }
166 
167 template <class ClassT>
169  ClassT& object, void (ClassT::*method)(vtkObject*, unsigned long, void*))
170 {
172  result->SetCallback(object, method);
173  return result;
174 }
175 //-----------------------------------------------------------------------------
176 // VTK-HeaderTest-Exclude: vtkMemberFunctionCommand.h
void SetCallback(ClassT &object, void(ClassT::*method)())
Set which class instance and member function will be called when a VTK event is received.
static ThisT * SafeDownCast(vtkObjectBase *o)
const char * GetClassNameInternal() const override
void SetCallback(ClassT &object, void(ClassT::*method2)(vtkObject *, unsigned long, void *))
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkMemberFunctionCommand< ClassT > * vtkMakeMemberFunctionCommand(ClassT &object, void(ClassT::*method)())
Convenience function for creating vtkMemberFunctionCommand instances that automatically deduces its a...
void Execute(vtkObject *caller, unsigned long event, void *calldata) override
Call a class member method in response to a VTK event.