Simpatico  v1.10
MethodFunctor.h
1 #ifndef UTIL_METHOD_FUNCTOR_H
2 #define UTIL_METHOD_FUNCTOR_H
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "IFunctor.h"
12 
13 namespace Util
14 {
15 
25  template <class Object, typename T=void>
26  class MethodFunctor : public IFunctor<T>
27  {
28  public:
29 
30  typedef void (Object::*Method1Ptr)(const T&);
31 
38  MethodFunctor(Object& object, Method1Ptr methodPtr)
39  : objectPtr_(&object),
40  methodPtr_(methodPtr)
41  {}
42 
46  virtual ~MethodFunctor(){}
47 
53  virtual void operator () (const T& t)
54  { (objectPtr_->*methodPtr_)(t); }
55 
56  private:
57 
58  Object* objectPtr_;
59  Method1Ptr methodPtr_;
60 
61  };
62 
66  template <class Object>
67  class MethodFunctor<Object, void> : public IFunctor<void>
68  {
69  public:
70 
71  typedef void (Object::*Method0Ptr)();
72 
79  MethodFunctor(Object& object, Method0Ptr methodPtr)
80  : objectPtr_(&object),
81  methodPtr_(methodPtr)
82  {}
83 
87  virtual ~MethodFunctor(){}
88 
89  virtual void operator () ()
90  { (objectPtr_->*methodPtr_)(); }
91 
92  private:
93 
94  Object* objectPtr_;
95  Method0Ptr methodPtr_;
96 
97  };
98 
99 }
100 #endif
virtual void operator()(const T &t)
Operator ().
Definition: MethodFunctor.h:53
virtual ~MethodFunctor()
Destructor.
Definition: MethodFunctor.h:46
Functor that wraps a one-argument class member function.
Definition: MethodFunctor.h:26
Utility classes for scientific computation.
Definition: accumulators.mod:1
MethodFunctor(Object &object, Method1Ptr methodPtr)
Constructor.
Definition: MethodFunctor.h:38
MethodFunctor(Object &object, Method0Ptr methodPtr)
Constructor.
Definition: MethodFunctor.h:79
virtual ~MethodFunctor()
Destructor.
Definition: MethodFunctor.h:87
Interface for functor that wraps a void function with one argument (abstract).
Definition: IFunctor.h:24