User Manual, Developers Guide and API Documentation

wns::events::DelayedMemberFunction< T > Class Template Reference

Similar to wns::events::MemberFunction, but to be used in std::for_each (or similar). More...

#include <events/MemberFunction.hpp>

Collaboration diagram for wns::events::DelayedMemberFunction< T >:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 DelayedMemberFunction (typename TFunctor< T >::functionPointer _fptr, wns::simulator::Time _delay)
 Takes a member function pointer and the delay.
virtual void operator() (T &obj)
 This is for value objects.
virtual void operator() (T *obj)
 This is for pointers.
virtual ~DelayedMemberFunction ()
 Destructor.

Private Attributes

wns::simulator::Time delay
TFunctor< T >::functionPointer fptr


Detailed Description

template<typename T>
class wns::events::DelayedMemberFunction< T >

Usage:
std::vector<TestObject*> tos;
tos.push_back(new TestObject);
tos.push_back(new TestObject);
tos.push_back(new TestObject);

// counter should be zero for all objects
ASSERT_EQUAL(0, tos[0]->foo);
ASSERT_EQUAL(0, tos[1]->foo);
ASSERT_EQUAL(0, tos[2]->foo);

// queue Events for all objects, calling increaseFoo after 1 second
std::for_each(
    tos.begin(),
    tos.end(),
    DelayedMemberFunction<TestObject>(&TestObject::increaseFoo, 1.0));

// only one of the objects should have the counter
// increased. Since events may be executed in unperdictble order
// we're testing the sum rather than one specifc element!
wns::simulator::getEventScheduler()->processOneEvent();
ASSERT_EQUAL(1, tos[0]->foo + tos[1]->foo + tos[2]->foo);

// two of the objects should have the counter
// increased. None of them should be called twice!
wns::simulator::getEventScheduler()->processOneEvent();
ASSERT_EQUAL(2, tos[0]->foo + tos[1]->foo + tos[2]->foo);
ASSERT(tos[0]->foo < 2 && tos[1]->foo < 2 && tos[2]->foo < 2);

// two of the objects should have the counter
// increased. None of them should be called twice!
wns::simulator::getEventScheduler()->processOneEvent();
ASSERT_EQUAL(3, tos[0]->foo + tos[1]->foo + tos[2]->foo);
ASSERT(tos[0]->foo < 2 && tos[1]->foo < 2 && tos[2]->foo < 2);

Definition at line 74 of file MemberFunction.hpp.


Constructor & Destructor Documentation

template<typename T>
wns::events::DelayedMemberFunction< T >::DelayedMemberFunction ( typename TFunctor< T >::functionPointer  _fptr,
wns::simulator::Time  _delay 
) [inline]

Definition at line 80 of file MemberFunction.hpp.

template<typename T>
virtual wns::events::DelayedMemberFunction< T >::~DelayedMemberFunction (  )  [inline, virtual]

Definition at line 92 of file MemberFunction.hpp.


Member Function Documentation

template<typename T>
virtual void wns::events::DelayedMemberFunction< T >::operator() ( T &  obj  )  [inline, virtual]

Definition at line 109 of file MemberFunction.hpp.

template<typename T>
virtual void wns::events::DelayedMemberFunction< T >::operator() ( T *  obj  )  [inline, virtual]

Definition at line 100 of file MemberFunction.hpp.


Member Data Documentation

template<typename T>
wns::simulator::Time wns::events::DelayedMemberFunction< T >::delay [private]

Definition at line 115 of file MemberFunction.hpp.

template<typename T>
TFunctor<T>::functionPointer wns::events::DelayedMemberFunction< T >::fptr [private]

Definition at line 114 of file MemberFunction.hpp.


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

Generated on Sat May 26 03:32:53 2012 for openWNS by  doxygen 1.5.5