44 lines
675 B
C++
44 lines
675 B
C++
#ifndef THREAD_HH
|
|
#define THREAD_HH
|
|
|
|
#include <boost/thread.hpp>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
template<typename T>
|
|
class Thread {
|
|
private:
|
|
boost::thread* thread;
|
|
bool isRunning;
|
|
public:
|
|
// Ctor
|
|
Thread() : thread(NULL), isRunning(false) {
|
|
}
|
|
virtual ~Thread() {
|
|
kill();
|
|
}
|
|
|
|
void start() {
|
|
T* derived = dynamic_cast<T*>(this);
|
|
thread = new boost::thread(boost::bind(&Thread::doIt, this, boost::ref(*derived)));
|
|
}
|
|
void doIt(T& derived) {
|
|
}
|
|
bool isFinished() {
|
|
return isRunning;
|
|
}
|
|
void join() {
|
|
if(thread) {
|
|
thread->join();
|
|
}
|
|
}
|
|
void kill() {
|
|
if(thread) {
|
|
thread->interrupt();
|
|
delete thread;
|
|
thread = NULL;
|
|
}
|
|
}
|
|
};
|
|
#endif |