events.cpp
Go to the documentation of this file.
#include <itpp/protocol/events.h>
namespace itpp
{
Ttype Event_Queue::t = 0;
unsigned long long int Base_Event::global_id = 0;
std::priority_queue < Base_Event*,
std::deque<Base_Event*, std::allocator<Base_Event*> >,
Compare_Base_Event_Times > Event_Queue::event_queue;
bool Event_Queue::keep_running = false;
void Event_Queue::add(Base_Event *e)
{
e->expire_t = t + e->delta_t;
event_queue.push(e);
}
void Event_Queue::_run()
{
while (!event_queue.empty() && keep_running) {
Base_Event* e = event_queue.top(); // Next event to process.
event_queue.pop(); // Remove event.
if (e->active) { // Only process active events.
t = e->expire_t; // Update current time.
e->exec(); // Execute the event.
}
delete e; // This event is history!
}
}
void Event_Queue::start()
{
keep_running = true;
_run();
}
void Event_Queue::stop()
{
keep_running = false;
}
void Event_Queue::clear()
{
stop();
Base_Event* e;
while (!event_queue.empty()) {
e = event_queue.top();
delete e;
event_queue.pop();
}
t = 0;
}
// void Event_Queue::cancel_all(BaseSignal *s){
// }
} // namespace itpp
itpp::Base_Event
Base Event Class.
Definition events.h:69
itpp::Base_Event::active
bool active
ADD DOCUMENTATION HERE.
Definition events.h:100
itpp::Base_Event::delta_t
Ttype delta_t
ADD DOCUMENTATION HERE.
Definition events.h:96
itpp::Base_Event::global_id
static unsigned long long int global_id
ADD DOCUMENTATION HERE.
Definition events.h:104
itpp::Base_Event::exec
virtual void exec(void)=0
ADD DOCUMENTATION HERE.
itpp::Base_Event::expire_t
Ttype expire_t
ADD DOCUMENTATION HERE.
Definition events.h:98
itpp::Event_Queue::start
static void start()
Start executing events.
Definition events.cpp:67
itpp::Event_Queue::add
static void add(Base_Event *e)
Add event to Queue.
Definition events.cpp:45
itpp::Event_Queue::stop
static void stop()
Stop execution of events.
Definition events.cpp:73
itpp::Event_Queue::clear
static void clear()
Remove all events.
Definition events.cpp:78
events.h
Definitions of an event-based simulation class.
itpp
itpp namespace
Definition itmex.h:37
itpp::Ttype
double Ttype
64-bit floating point time
Definition events.h:54

Generated on Mon Jun 10 2024 11:49:24 for IT++ by Doxygen 1.9.8