blob: 571871be9890b3063bb2b8642655a1b72d80aa3e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
//
// RunnableAdapter.h
//
// Library: Foundation
// Package: Threading
// Module: Thread
//
// Definition of the RunnableAdapter template class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Foundation_RunnableAdapter_INCLUDED
#define Foundation_RunnableAdapter_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/Runnable.h"
namespace Poco {
template <class C>
class RunnableAdapter: public Runnable
/// This adapter simplifies using ordinary methods as
/// targets for threads.
/// Usage:
/// RunnableAdapter<MyClass> ra(myObject, &MyObject::doSomething));
/// Thread thr;
/// thr.Start(ra);
///
/// For using a freestanding or static member function as a thread
/// target, please see the ThreadTarget class.
{
public:
typedef void (C::*Callback)();
RunnableAdapter(C& object, Callback method): _pObject(&object), _method(method)
{
}
RunnableAdapter(const RunnableAdapter& ra): _pObject(ra._pObject), _method(ra._method)
{
}
~RunnableAdapter()
{
}
RunnableAdapter& operator = (const RunnableAdapter& ra)
{
_pObject = ra._pObject;
_method = ra._method;
return *this;
}
void run()
{
(_pObject->*_method)();
}
private:
RunnableAdapter();
C* _pObject;
Callback _method;
};
} // namespace Poco
#endif // Foundation_RunnableAdapter_INCLUDED
|