VR-Link API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
delegate.h
Go to the documentation of this file.
1 /*********************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************************/
5 
6 #pragma once
7 
12 
13 class DtMessage;
14 
16 template <typename Ret, typename Param0>
17 class Callback
18 {
19  public:
20  virtual Ret invoke(Param0 param0) = 0;
21 };
22 
23 
26 template <typename Ret, typename Param0>
27 class StaticFunctionCallback : public Callback<Ret, Param0>
28 {
29 private:
30  Ret (*func_)(Param0);
31 
32 public:
33  StaticFunctionCallback(Ret (*func)(Param0))
34  : func_(func)
35  {}
36 
37  virtual Ret invoke(Param0 param0)
38  {
39  return (*func_)(param0);
40  }
41 };
42 
43 
46 template <typename Ret, typename Param0, typename T, typename Method>
47 class MethodCallback : public Callback<Ret, Param0>
48 {
49 private:
50  void *object_;
51  Method method_;
52 
53 public:
54  MethodCallback(void *object, Method method)
55  : object_(object)
56  , method_(method)
57  {}
58 
59  virtual Ret invoke(Param0 param0)
60  {
61  T *obj = static_cast<T *>(object_);
62  return (obj->*method_)(param0);
63  }
64 };
65 
68 template <typename Ret, typename Param0>
70 {
71 private:
73 
74 public:
76  DtDelegate(Ret (*func)(Param0))
77  :callback_(new StaticFunctionCallback<Ret, Param0>(func))
78  {}
79 
81  template <typename T, typename Method>
82  DtDelegate(T *object, Method method)
83  :callback_(new MethodCallback<Ret, Param0, T, Method>(object, method))
84  {}
85 
87  ~DtDelegate(void) { delete callback_; }
88 
90  Ret operator()(Param0 param0)
91  {
92  return callback_->invoke(param0);
93  }
94 };
95 
Ret(* func_)(Param0)
Definition: delegate.h:30
virtual Ret invoke(Param0 param0)
Definition: delegate.h:59
Static member function (or global function) callback is used to bind global or static class functions...
Definition: delegate.h:27
This is the DtMessage class.
Definition: message.h:20
void * object_
Definition: delegate.h:50
Method method_
Definition: delegate.h:51
Callback template the base abstract callback class that is used internally to the delegate...
Definition: delegate.h:17
virtual Ret invoke(Param0 param0)
Definition: delegate.h:37
DtDelegate< void, DtMessage * > DtMessageDelegate
create a typedef for message delegates that take a DtMessage* as a parameter and return a void type t...
Definition: delegate.h:98
StaticFunctionCallback(Ret(*func)(Param0))
Definition: delegate.h:33
Callback< Ret, Param0 > * callback_
Definition: delegate.h:72
Member function callback is used to bind class member functions The return type, single parameter...
Definition: delegate.h:47
~DtDelegate(void)
destructor
Definition: delegate.h:87
DtDelegate(Ret(*func)(Param0))
constructor using a static function
Definition: delegate.h:76
MethodCallback(void *object, Method method)
Definition: delegate.h:54
DtDelegate(T *object, Method method)
constructor using a class member functions
Definition: delegate.h:82
Delegate template for binding static or member functions for callback at later time The return type a...
Definition: delegate.h:69
Ret operator()(Param0 param0)
execute operator
Definition: delegate.h:90
virtual Ret invoke(Param0 param0)=0

Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)