RunnableDelegate< T > Class Template Reference

An adapter object that implements the Runnable interface and delegates to an arbitrary method (one that must have no arguments or return value) in some other object. More...

#include <Runnable.h++>

Inheritance diagram for RunnableDelegate< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 RunnableDelegate (T *object, void(T::*func)())
 Construct a new RunnableDelegate which will call a method on another object.
void run ()
 Entry point.

Detailed Description

template<class T>
class ccxx::RunnableDelegate< T >

An adapter object that implements the Runnable interface and delegates to an arbitrary method (one that must have no arguments or return value) in some other object.

This allows a class to have multiple methods that will execute asynchronously in their own threads. For example, consider the class:

 class MyClass
 {
   public:
   MyClass();
   ~MyClass();
   void thread1();
   void thread2();
 };
 

Given an instance of MyClass, the following construct causes a new thread to begin executing in the thread1() method of that instance.

 MyClass mc;
 RunnableDelegate<MyClass> runnable(&mc, &MyClass::thread1);
 Thread thread(&runnable);
 thread.start();
 
Author:
Mark Lindner

Constructor & Destructor Documentation

RunnableDelegate ( T *  object,
void(T::*)()  func 
) [inline]

Construct a new RunnableDelegate which will call a method on another object.

Parameters:
object The object.
func A member function (method) in the object which will be called by run().

Member Function Documentation

void run (  )  [inline, virtual]

Entry point.

Implements Runnable.


The documentation for this class was generated from the following file:
Generated on Sat Nov 26 16:49:09 2011 for libcommonc++ by  doxygen 1.6.3