libcommonc++  0.7
Runnable.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Runnable_hxx
24 #define __ccxx_Runnable_hxx
25 
26 #include <commonc++/Common.h++>
27 
28 namespace ccxx {
29 
36 {
37  public:
38 
40  virtual ~Runnable() { }
41 
43  virtual void run() = 0;
44 };
45 
78 template<class T> class RunnableDelegate : public Runnable
79 {
80  public:
81 
90  RunnableDelegate(T* object, void (T::* func)())
91  : _object(object),
92  _func(func)
93  {
94  }
95 
97  void run()
98  {
99  (_object->*_func)();
100  }
101 
102  private:
103 
104  T* _object;
105  void (T::*_func)();
106 };
107 
115 template<class T, typename A> class RunnableClosure : public Runnable
116 {
117  public:
118 
128  RunnableClosure(T* object, void (T::* func)(A), A argument)
129  : _object(object),
130  _func(func),
131  _argument(argument)
132  { }
133 
135  void run()
136  { (_object->*_func)(_argument); }
137 
138  private:
139 
140  T* _object;
141  void (T::*_func)(A);
142  A _argument;
143 };
144 
145 } // namespace ccxx
146 
147 #endif // __ccxx_Runnable_hxx
virtual ~Runnable()
Destructor.
Definition: Runnable.h++:40
void run()
Entry point.
Definition: Runnable.h++:97
An adapter object similar to RunnableDelegate that additionally takes an arbitrary argument which wil...
Definition: Runnable.h++:115
void run()
Entry point.
Definition: Runnable.h++:135
RunnableClosure(T *object, void(T::*func)(A), A argument)
Construct a new RunnableClosure which will call a method on another object with the given argument...
Definition: Runnable.h++:128
An adapter object that implements the Runnable interface and delegates to an arbitrary method (one th...
Definition: Runnable.h++:78
RunnableDelegate(T *object, void(T::*func)())
Construct a new RunnableDelegate which will call a method on another object.
Definition: Runnable.h++:90
#define COMMONCPP_API
Definition: Common.h++:126
A runnable object.
Definition: Runnable.h++:35
Definition: AllocationMap.c++:25