% eventq_class.mw
%   Simple event queue for use in MATLAB event-driven simulations.
%   Uses the MATLAB OO system for encapsulating the event queue.
%
% Copyright (c) 2007  David Bindel
% See the file COPYING for copying permissions

$ #include <queue>
$
$ typedef std::pair<double, int>                      Event;
$ typedef std::priority_queue< Event, 
$                              std::vector<Event>, 
$                              std::greater<Event> >  EventQueue;


@ @eventq/eventq.m -------------------------------------

function [qobj] = eventq();

qobj = [];
# EventQueue* q = new EventQueue();
qobj.q = q;
qobj = class(qobj, 'eventq');


@ @eventq/destroy.m -------------------------------------

function destroy(qobj);

q = qobj.q;
# delete(EventQueue* q);


@ @eventq/empty.m -------------------------------------

function [e] = empty(qobj)

q = qobj.q;
# int e = q->EventQueue.empty();


@ @eventq/pop.m -------------------------------------

function [id, t] = pop(qobj)

$ void pop_event(EventQueue* q, int& id, double& t) {
$     t  = q->top().first;
$     id = q->top().second;
$     q->pop();
$ }
$
q = qobj.q;
# pop_event(EventQueue* q, output int& id, output double& t);


@ @eventq/push.m -------------------------------------

function push(qobj, id, t)

$ void push_events(EventQueue* q, int* id, double* t, int m)
$ {
$     for (int i = 0; i < m; ++i)
$         q->push(Event(t[i], id[i]));
$ }
$
q = qobj.q;
m = length(id);
# push_events(EventQueue* q, int[m] id, double[m] t, int m);
