% eventq_handle.mw
%   Simple event queue for use in MATLAB event-driven simulations.
%   Uses the MATLAB 2008+ 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;


@ eventqh.m --------------------------------------------

classdef eventqh < handle

  properties
    mwptr
  end

  methods

    function [qobj] = eventqh()
      # EventQueue* q = new EventQueue();
      qobj.mwptr = q;
    end

    function delete(q)
      #delete(EventQueue* q);
    end

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

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

    function push(q, 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]));
      $ }
      m = length(id);
      # push_events(EventQueue* q, int[m] id, double[m] t, int m);
    end

  end
end
