Sierra Toolkit  Version of the Day
Callback.hpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2002 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 // Callback class basics from Herb Sutter, http://www.gotw.ca, GOTW #83.
10 
11 #ifndef STK_UTIL_UTIL_Callback_hpp
12 #define STK_UTIL_UTIL_Callback_hpp
13 
21 namespace sierra {
22 
23 template<class T>
24 class Callback;
25 
30 template<>
31 class Callback<void>
32 {
33 public:
39  virtual void operator()() const = 0;
40 
45  virtual ~Callback()
46  {}
47 };
48 
50 
55 template<typename T>
56 class Callback : public Callback<void>
57 {
58 public:
59  typedef void (T::*F)();
60 
69  Callback(T &t, F f)
70  : m_t(&t),
71  m_f(f)
72  {}
73 
78  virtual ~Callback()
79  {}
80 
86  virtual void operator()() const {
87  (m_t->*m_f)();
88  }
89 
90 private:
91  T * m_t;
92  F m_f;
93 };
94 
105 template<typename T>
106 CallbackBase *
108  T & t,
109  void (T::*f)())
110 {
111  return new Callback<T>(t, f);
112 }
113 
114 } // namespace sierra
115 
116 #endif // STK_UTIL_UTIL_Callback_hpp
Definition: Env.cpp:53
virtual void operator()() const
Member function operator() calls the member function on the object.
Definition: Callback.hpp:86
virtual ~Callback()
Definition: Callback.hpp:78
Callback(T &t, F f)
Definition: Callback.hpp:69
Callback< void > CallbackBase
Shorthand for Callback<void>
Definition: Callback.hpp:49
CallbackBase * create_callback(T &t, void(T::*f)())
Member function create_callback creates a new callback object which calls the member function f on th...
Definition: Callback.hpp:107
Class Callback ...
Definition: Callback.hpp:24
Class Callback ...
Definition: Callback.hpp:31
void(T::* F)()
Member function signature.
Definition: Callback.hpp:59