SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sydevs::time_cache Class Reference

A data structure which provides durations elapsed since past events. More...

#include <time_cache.h>

Public Member Functions

 time_cache ()
 Constructs an empty time cache with a current time of zero. More...
 
 time_cache (duration dt0)
 Constructs an empty time cache with a current time of dt0 More...
 
 time_cache (const time_point &t0)
 Constructs an empty time cache with a current time of t0 More...
 
 time_cache (const time_cache &)=default
 Copy constructor. More...
 
time_cacheoperator= (const time_cache &)=default
 Copy assignment. More...
 
 time_cache (time_cache &&)=default
 Move constructor. More...
 
time_cacheoperator= (time_cache &&)=default
 Move assignment. More...
 
 ~time_cache ()=default
 Destructor. More...
 
bool empty () const
 Returns true if the time cache is empty. More...
 
int64 size () const
 Returns the number of events in the time cache. More...
 
const time_pointcurrent_time () const
 Returns the current time. More...
 
const time_pointadvance_time (duration dt)
 Advances the current time by dt. More...
 
const time_pointadvance_time (const time_point &t)
 Advances the current time to t. More...
 
duration duration_since (int64 event_id) const
 Returns the duration since the specified event, or an infinite duration. More...
 
void retain_event (int64 event_id, scale precision)
 Retains a record of the event with id event_id at the specified precision. More...
 
bool release_event (int64 event_id)
 Erases the record of the event with id event_id, returning true if successful. More...
 
const time_queue::event_id_setevent_ids () const
 Return the set of ids of all retained events. More...
 

Detailed Description

A data structure which provides durations elapsed since past events.

A time_cache object represents past events in order to obtain elapsed event times as required by DEVS. Like a time queue, the time cache has a current time that can be advanced. Events should be added using the retain_event member function at the time when the event occurs and at the scale at which the event was scheduled. The duration_since member function is used to obtain that elapsed time for the retained event, which increases from zero as time is advanced after the associated retain_event call.

The time_cache data structure, which tracks past events, is implemented using a time queue, which tracks future events. This works by way of a trick where each event time is offset forward in time by 999,999,999,999,999 times the specified precision. Subtracting the planned duration from this number gives the elapsed duration.

Constructor & Destructor Documentation

sydevs::time_cache::time_cache ( )

Constructs an empty time cache with a current time of zero.

sydevs::time_cache::time_cache ( duration  dt0)
explicit

Constructs an empty time cache with a current time of dt0

sydevs::time_cache::time_cache ( const time_point t0)
explicit

Constructs an empty time cache with a current time of t0

sydevs::time_cache::time_cache ( const time_cache )
default

Copy constructor.

sydevs::time_cache::time_cache ( time_cache &&  )
default

Move constructor.

sydevs::time_cache::~time_cache ( )
default

Destructor.

Member Function Documentation

const time_point & sydevs::time_cache::advance_time ( duration  dt)

Advances the current time by dt.

const time_point & sydevs::time_cache::advance_time ( const time_point t)

Advances the current time to t.

const time_point & sydevs::time_cache::current_time ( ) const
inline

Returns the current time.

duration sydevs::time_cache::duration_since ( int64  event_id) const

Returns the duration since the specified event, or an infinite duration.

bool sydevs::time_cache::empty ( ) const
inline

Returns true if the time cache is empty.

const time_queue::event_id_set & sydevs::time_cache::event_ids ( ) const
inline

Return the set of ids of all retained events.

time_cache& sydevs::time_cache::operator= ( const time_cache )
default

Copy assignment.

time_cache& sydevs::time_cache::operator= ( time_cache &&  )
default

Move assignment.

bool sydevs::time_cache::release_event ( int64  event_id)

Erases the record of the event with id event_id, returning true if successful.

void sydevs::time_cache::retain_event ( int64  event_id,
scale  precision 
)

Retains a record of the event with id event_id at the specified precision.

int64 sydevs::time_cache::size ( ) const
inline

Returns the number of events in the time cache.


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