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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#ifndef CKJTHREAD_H
#define CKJTHREAD_H
#include <sigc++/class_slot.h>
#include <glibmm/thread.h>
/** a wrapper class for Glib::Thread to use a Glib::Thread like a java or commonc++2
* object. simply derive your own class, overwrite run() and implement the behaviour
* of your own thread object.
* as this class cannot be derived from Glib::Thread (because a Glib::Thread object
* can only be instantiated with the static Thread::create() method),
* operators are offered to access the actual Glib::Thread object.
* @author triendl.kj
*/
class CkjThread
{
Glib::Thread* m_pThread;
bool m_bJoinable;
public:
CkjThread(bool bJoinable = false);
private:
/** a wrapper method for the actual run to realize when the thread has stopped
*/
void _run();
protected:
/** overwrite this method in your derived class
*/
virtual void run() = 0;
public:
/** starts the thread.
* @param bool start the thread joinable or not, overwrites what you have
* specified in the constructor
*/
void start(bool bJoinable);
/** starts the thread. uses the information whether it is joinable or not provided
* in the constructor.
*/
void start()
{
start(m_bJoinable);
}
bool isRunning() const
{
return (m_pThread != NULL);
}
Glib::Thread* operator ->()
{
return m_pThread;
}
const Glib::Thread* operator ->() const
{
return m_pThread;
}
Glib::Thread& operator *()
{
return *m_pThread;
}
const Glib::Thread& operator *() const
{
return *m_pThread;
}
operator Glib::Thread*() const
{
return m_pThread;
}
operator const Glib::Thread*() const
{
return m_pThread;
}
operator Glib::Thread&() const
{
return *m_pThread;
}
operator const Glib::Thread&() const
{
return *m_pThread;
}
};
#endif
|