//	Thread.h - Simple thread base class.
//  ----------------------------------------------------------------------------

#ifndef THREAD_H_
#define THREAD_H_

struct SDL_Thread;

///	Simple thread base class.
/*!
	To use it, you should create a subclass that implements the run() method.
 */
class Thread
{
  public:
	///	Constructor.
	Thread();
	///	Destructor.
	/*!
		This will wait for the thread to terminate.  Do not delete a Thread
		object from it's own thread.  It is assumed that your subclass will
		implement some kind of way to tell the running thread that it must
		terminate, and exit the run() method, otherwise you may find your
		program hangs forever.
	 */
	virtual ~Thread();

	///	Call this to start the thread.
	/*!
		\param threadPointer Pointer to the subclass calling it (since it needs
		to be passed to SDL_CreateThread, and we can't just use this in Thread
		(because that would be a base class pointer, not a subclass...).
	 */
	void startThread(Thread *threadPointer);

	///	Where any processing for the thread occurs.
	/*!
		\return Set this to true if the thread completed successfully, false
		otherwise.

		To use this class, you want to create a subclass, and put all your
		processing stuff in this method.
	 */
	virtual bool run() = 0;

	///	Static method passed to SDL_CreateThread, to ensure run() is always called.
	/*!
		In the Thread constructor, we pass in a pointer to the instance of
		Thread for this method, so it can call Thread::run().
	 */
	static int threadMethod(void *data);
  private:
	///	Pointer to the actual thread struct.
	SDL_Thread *thread;
};

#endif
