mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion/simulator] Extrude the QueueJournal class
This commit is contained in:
@@ -1,42 +1,22 @@
|
||||
#include "journal.h"
|
||||
#include "journal/queue_journal.h"
|
||||
#include <queue>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Journal {
|
||||
|
||||
using Ion::Events::Event;
|
||||
class Journal : public Ion::Events::Journal {
|
||||
public:
|
||||
void pushEvent(Event e) override {
|
||||
m_eventStorage.push(e);
|
||||
}
|
||||
virtual Event popEvent() override {
|
||||
if (isEmpty()) {
|
||||
return Ion::Events::None;
|
||||
}
|
||||
Event e = m_eventStorage.front();
|
||||
m_eventStorage.pop();
|
||||
return e;
|
||||
}
|
||||
virtual bool isEmpty() override {
|
||||
return m_eventStorage.empty();
|
||||
}
|
||||
private:
|
||||
std::queue<Event> m_eventStorage;
|
||||
};
|
||||
|
||||
void init() {
|
||||
Events::logTo(logJournal());
|
||||
}
|
||||
|
||||
Events::Journal * replayJournal() {
|
||||
static Journal journal;
|
||||
static QueueJournal journal;
|
||||
return &journal;
|
||||
}
|
||||
|
||||
Events::Journal * logJournal() {
|
||||
static Journal journal;
|
||||
static QueueJournal journal;
|
||||
return &journal;
|
||||
}
|
||||
|
||||
|
||||
35
ion/src/simulator/shared/journal/queue_journal.h
Normal file
35
ion/src/simulator/shared/journal/queue_journal.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef ION_SIMULATOR_JOURNAL_QUEUE_JOURNAL_H
|
||||
#define ION_SIMULATOR_JOURNAL_QUEUE_JOURNAL_H
|
||||
|
||||
#include <ion/events.h>
|
||||
#include <queue>
|
||||
|
||||
namespace Ion {
|
||||
namespace Simulator {
|
||||
namespace Journal {
|
||||
|
||||
class QueueJournal : public Ion::Events::Journal {
|
||||
public:
|
||||
void pushEvent(Ion::Events::Event e) override {
|
||||
m_eventStorage.push(e);
|
||||
}
|
||||
virtual Ion::Events::Event popEvent() override {
|
||||
if (isEmpty()) {
|
||||
return Ion::Events::None;
|
||||
}
|
||||
Ion::Events::Event e = m_eventStorage.front();
|
||||
m_eventStorage.pop();
|
||||
return e;
|
||||
}
|
||||
virtual bool isEmpty() override {
|
||||
return m_eventStorage.empty();
|
||||
}
|
||||
private:
|
||||
std::queue<Ion::Events::Event> m_eventStorage;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user