eng::Timer Class Reference

Singleton to register and invoke timer callbacks. More...

#include <eng_timer.hh>

List of all members.

Public Types

enum  eDisablement { CAN_DISABLE, CANNOT_DISABLE }

Public Member Functions

CLASS_METHOD TimerGetInstance (void)
void Register (SharedPtr< Functor > functor, const Milliseconds millisecFreq, eDisablement canDisable=CAN_DISABLE)
void Unregister (SharedPtr< Functor > functor)
void Enable (bool enable)
void Tick (const Milliseconds millisecElapsed)

Private Types

typedef map< SafePtr
< Functor >,
Callback
Callbacks
typedef deque
< Callbacks::iterator > 
Zombies

Private Member Functions

 Timer (void)
 ~Timer ()
Callbacks::iterator Find (SharedPtr< Functor > functor)

Private Attributes

CLASS_CONST uint MIN_MILLISEC = 1
CLASS_CONST uint MAX_MILLISEC = THOUSAND * 60 * 60
CLASS_VAR TimermsInstance
bool mEnabled
Callbacks mCallbacks
 mapped by raw ptr to Functor
Zombies mZombies
 callbacks that were unregistered and will be destroyed at safe time

Classes

class  Callback
 Encapsulates a callback functor and defines how frequently to call it. More...
class  Functor
 User-defined timer functor. More...


Detailed Description

Singleton to register and invoke timer callbacks.

Timer must be Singleton since globals register timers.

To integrate Timer: Whichever function that is called periodically must call Timer::Tick() to drive the Timer object. Otherwise Timer won't be active.

Trying to re-register the same functor is considered a bug.

A callback is allowed to unregister itself. Unregister() modifies the Callback container. Therefore, the iteration to invoke Callbacks is driven by copy of the container to avoid disruption if Unregister() is called in the middle.

Since many timer callbacks could be repeatedly registered/unregistered, a faster STL set is used.

Disabling Timer isn't absolute. A callback that is constructed with Timer::CANNOT_DISABLE must still be called even if Timer is disabled. For example, polling keyboard should remain enabled always.


Member Typedef Documentation

typedef map<SafePtr<Functor>,Callback> eng::Timer::Callbacks [private]

typedef deque<Callbacks::iterator> eng::Timer::Zombies [private]


Member Enumeration Documentation

enum eng::Timer::eDisablement

Enumerator:
CAN_DISABLE 
CANNOT_DISABLE 


Constructor & Destructor Documentation

eng::Timer::Timer ( void   )  [private]

ctor/dtor.

eng::Timer::~Timer (  )  [private]


Member Function Documentation

Timer & eng::Timer::GetInstance ( void   ) 

Singleton method.

void eng::Timer::Register ( SharedPtr< Functor functor,
const Milliseconds  millisecFreq,
eDisablement  canDisable = CAN_DISABLE 
)

void eng::Timer::Unregister ( SharedPtr< Functor functor  ) 

void eng::Timer::Enable ( bool  enable  ) 

Timer can be disabled to pause/freeze program.

void eng::Timer::Tick ( const Milliseconds  millisecElapsed  ) 

Callbacks::iterator eng::Timer::Find ( SharedPtr< Functor functor  )  [private]


Member Data Documentation

CLASS_CONST uint eng::Timer::MIN_MILLISEC = 1 [private]

CLASS_CONST uint eng::Timer::MAX_MILLISEC = THOUSAND * 60 * 60 [private]

Timer * eng::Timer::msInstance [private]

bool eng::Timer::mEnabled [private]

Callbacks eng::Timer::mCallbacks [private]

mapped by raw ptr to Functor

Zombies eng::Timer::mZombies [private]

callbacks that were unregistered and will be destroyed at safe time


The documentation for this class was generated from the following files: Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:25 2007