2 #ifndef SYDEVS_TIME_QUEUE_H_
3 #define SYDEVS_TIME_QUEUE_H_
75 using event_account = std::pair<duration, scale>;
76 using queue_iterator = std::deque<duration>::iterator;
84 queue_iterator lower_bound(
duration pdt);
86 scale default_precision_;
88 std::deque<duration> queue_;
89 std::map<duration, event_id_set> event_id_sets_;
90 std::map<int64, event_account> event_accounts_;
96 return event_accounts_.empty();
102 return int64(event_accounts_.size());
108 return int64(event_id_sets_.size());
duration duration_at(int64 time_index) const
Returns the duration at time_index.
Definition: time_queue.cpp:104
std::set< int64 > event_id_set
The container used to store ids of events occurring at the same time.
Definition: time_queue.h:37
bool cancel_event(int64 event_id)
Cancels the event with id event_id, returning true if successful.
Definition: time_queue.cpp:178
time_queue()
Constructs an empty time queue with a current time of zero.
Definition: time_queue.cpp:7
bool empty() const
Returns true if the time queue is empty.
Definition: time_queue.h:94
const time_point & current_time() const
Returns the current time.
Definition: time_queue.h:112
const event_id_set & imminent_event_ids() const
Returns the imminent events.
Definition: time_queue.cpp:112
int64 size() const
Returns the number of events in the time queue.
Definition: time_queue.h:100
duration duration_until(int64 event_id) const
Returns the duration until the event with id event_id, or infinity if no such event exists...
Definition: time_queue.cpp:92
time_queue & operator=(const time_queue &)=default
Copy assignment.
A data type which represents the general concept of scale as a dimensionless power of 1000...
Definition: scale.h:70
A data structure which represents a point in time as an arbitrary-precision multiple of its shortest ...
Definition: time_point.h:84
A data structure which supports the scheduling of future events.
Definition: time_queue.h:34
int64 time_count() const
Returns the number of distinct event times in the time queue.
Definition: time_queue.h:106
const time_point & advance_time()
Advances the current time to that of the imminent events.
Definition: time_queue.cpp:40
duration imminent_duration() const
Returns the duration until the imminent event(s).
Definition: time_queue.cpp:82
bool can_advance_by(duration dt)
Returns true if time can be advanced by the specified duration.
Definition: time_queue.cpp:65
void pop_imminent_event(int64 event_id)
Pops the specified imminent event with id event_id.
Definition: time_queue.cpp:127
~time_queue()=default
Destructor.
int64_t int64
Definition: number_types.h:14
void plan_event(int64 event_id, duration dt)
Schedules an event with id event_id after a planned duration of dt.
Definition: time_queue.cpp:157
const event_id_set & event_ids_at(int64 time_index) const
Returns the events at time_index.
Definition: time_queue.cpp:119
void pop_imminent_events()
Pops the imminent events.
Definition: time_queue.cpp:145