SyDEVS
v0.6.7
Multiscale Simulation and Systems Modeling Library
|
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_cache & | operator= (const time_cache &)=default |
Copy assignment. More... | |
time_cache (time_cache &&)=default | |
Move constructor. More... | |
time_cache & | operator= (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_point & | current_time () const |
Returns the current time. More... | |
const time_point & | advance_time (duration dt) |
Advances the current time by dt . More... | |
const time_point & | advance_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_set & | event_ids () const |
Return the set of ids of all retained events. More... | |
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.
sydevs::time_cache::time_cache | ( | ) |
Constructs an empty time cache with a current time of zero.
|
explicit |
Constructs an empty time cache with a current time of dt0
|
explicit |
Constructs an empty time cache with a current time of t0
|
default |
Copy constructor.
|
default |
Move constructor.
|
default |
Destructor.
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
.
|
inline |
Returns the current time.
Returns the duration since the specified event, or an infinite duration.
|
inline |
Returns true
if the time cache is empty.
|
inline |
Return the set of ids of all retained events.
|
default |
Copy assignment.
|
default |
Move assignment.
Erases the record of the event with id event_id
, returning true
if successful.
Retains a record of the event with id event_id
at the specified precision
.
|
inline |
Returns the number of events in the time cache.