flow  3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Protected Types | Protected Attributes | List of all members
flow::timer Class Referenceabstract

Base class for an object that notifies listeners at some interval. More...

#include <timer.h>

Inheritance diagram for flow::timer:
Inheritance graph
[legend]
Collaboration diagram for flow::timer:
Collaboration graph
[legend]

Public Member Functions

virtual bool stopped () const
 Returns true if the timer is stopped.
 
virtual void stop ()
 Stop the timer.
 
virtual size_t listen (const std::function< void()> &listener)
 Adds a listener to this timer.
 
virtual void ignore (const size_t token)
 Removes a previously added listener.
 
virtual void operator() ()=0
 Execution function to be implemented by concrete timers.
 

Protected Types

typedef std::map< size_t,
const std::function< void()> > 
listeners_t
 Convenience typedef.
 

Protected Attributes

listeners_t d_listeners
 Listeners of this timer.
 
size_t d_next_index
 The token tat maps to a listener.
 
std::mutex d_listeners_m
 Mutex to protect modifications to d_listeners.
 

Detailed Description

Base class for an object that notifies listeners at some interval.

Member Function Documentation

virtual size_t flow::timer::listen ( const std::function< void()> &  listener)
inlinevirtual

Adds a listener to this timer.

Parameters
listenerA functor that will be called at interval.
Returns
The token to pass to ignore.
virtual void flow::timer::ignore ( const size_t  token)
inlinevirtual

Removes a previously added listener.

Parameters
tokenA value previously returned by listen.
virtual void flow::timer::operator() ( )
pure virtual

Execution function to be implemented by concrete timers.

This function must return as soon as possible after the timer is stopped.

Implemented in flow::monotonous_timer.


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