libcommonc++  0.7
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 >:
Collaboration diagram for RunnableDelegate< T >:

Public Member Functions

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

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()

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

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

Parameters
objectThe object.
funcA member function (method) in the object which will be called by run().

Member Function Documentation

◆ run()

void run ( )
inlinevirtual

Entry point.

Implements Runnable.


The documentation for this class was generated from the following file: