SyDEVS  v0.6.7
Multiscale Simulation and Systems Modeling Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
time_cache.h
Go to the documentation of this file.
1 #pragma once
2 #ifndef SYDEVS_TIME_CACHE_H_
3 #define SYDEVS_TIME_CACHE_H_
4 
6 
7 namespace sydevs {
8 
9 
28 {
29 public:
30  time_cache();
31  explicit time_cache(duration dt0);
32  explicit time_cache(const time_point& t0);
33 
34  time_cache(const time_cache&) = default;
35  time_cache& operator=(const time_cache&) = default;
36  time_cache(time_cache&&) = default;
37  time_cache& operator=(time_cache&&) = default;
38  ~time_cache() = default;
39 
40  bool empty() const;
41  int64 size() const;
42 
43  const time_point& current_time() const;
44 
45  const time_point& advance_time(duration dt);
46  const time_point& advance_time(const time_point& t);
47 
48  duration duration_since(int64 event_id) const;
49 
50  void retain_event(int64 event_id, scale precision);
51  bool release_event(int64 event_id);
52 
53  const time_queue::event_id_set& event_ids() const;
54 
55 private:
56  time_queue tq_;
57  time_queue::event_id_set event_ids_;
58 };
59 
60 
61 inline bool time_cache::empty() const
62 {
63  return event_ids_.empty();
64 }
65 
66 
67 inline int64 time_cache::size() const
68 {
69  return event_ids_.size();
70 }
71 
72 
73 inline const time_point& time_cache::current_time() const
74 {
75  return tq_.current_time();
76 }
77 
78 
80 {
81  return event_ids_;
82 }
83 
84 
85 } // namespace
86 
87 #endif
bool release_event(int64 event_id)
Erases the record of the event with id event_id, returning true if successful.
Definition: time_cache.cpp:68
std::set< int64 > event_id_set
The container used to store ids of events occurring at the same time.
Definition: time_queue.h:37
const time_point & current_time() const
Returns the current time.
Definition: time_queue.h:112
bool empty() const
Returns true if the time cache is empty.
Definition: time_cache.h:61
A data structure which provides durations elapsed since past events.
Definition: time_cache.h:27
duration duration_since(int64 event_id) const
Returns the duration since the specified event, or an infinite duration.
Definition: time_cache.cpp:50
const time_queue::event_id_set & event_ids() const
Return the set of ids of all retained events.
Definition: time_cache.h:79
time_cache & operator=(const time_cache &)=default
Copy assignment.
A data type which represents the general concept of scale as a dimensionless power of 1000...
Definition: scale.h:70
~time_cache()=default
Destructor.
A data structure which represents a point in time as an arbitrary-precision multiple of its shortest ...
Definition: time_point.h:84
const time_point & current_time() const
Returns the current time.
Definition: time_cache.h:73
void retain_event(int64 event_id, scale precision)
Retains a record of the event with id event_id at the specified precision.
Definition: time_cache.cpp:61
A data structure which supports the scheduling of future events.
Definition: time_queue.h:34
time_cache()
Constructs an empty time cache with a current time of zero.
Definition: time_cache.cpp:6
int64 size() const
Returns the number of events in the time cache.
Definition: time_cache.h:67
const time_point & advance_time(duration dt)
Advances the current time by dt.
Definition: time_cache.cpp:27