|
|
nono 0.1.6
//
// nono
// Copyright (C) 2021 nono project
// Licensed under nono-license.txt
//
#pragma once
#include <queue>
//
// イベントキュー
//
// 比較関数
template <class T>
class event_comp_t {
public:
inline bool operator()(const T& a, const T& b) const
{
return a->vtime > b->vtime;
}
};
using event_comp = event_comp_t<Event *>;
// イベントキュー
class EventQueue
: public std::priority_queue<Event *, std::vector<Event *>, event_comp>
{
using inherited =
std::priority_queue<Event *, std::vector<Event *>, event_comp>;
public:
EventQueue()
: inherited((event_comp()))
{
}
~EventQueue()
{
}
// キューから ev と(このオブジェクトのポインタが)一致する要素を外し
// true を返す。なければ何もせず false を返す。
// (独自メソッドなので大文字で始めている)
bool Erase(Event *ev)
{
for (auto it = c.begin(); it != c.end(); ++it) {
Event *e = *it;
if (e == ev) {
// 見つけた要素を末尾に移動
std::pop_heap(it, c.end(), comp);
// 末尾を削除
c.pop_back();
// 再構築
std::make_heap(c.begin(), c.end(), comp);
return true;
}
}
return false;
}
};
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.