[ion/simulator] Extrude the QueueJournal class

This commit is contained in:
Romain Goyet
2021-02-25 15:24:57 -05:00
committed by Léa Saviot
parent e8956f4293
commit a6b13185ab
2 changed files with 38 additions and 23 deletions

View File

@@ -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;
}

View 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