From f4905c59a24bbe9956d2225e01862f7af3d830a8 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Thu, 10 Sep 2020 16:23:33 -0400 Subject: [PATCH] [ion] Events::Journal has isEmpty --- ion/include/ion/events.h | 1 + ion/src/shared/events_keyboard.cpp | 5 ++--- ion/src/simulator/shared/journal.cpp | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index 6c1c64d76..c5a5fae5b 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -57,6 +57,7 @@ class Journal { public: virtual void pushEvent(Event e) = 0; virtual Event popEvent() = 0; + virtual bool isEmpty() = 0; }; void replayFrom(Journal * l); diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index c368b785e..fe0825a4b 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -125,11 +125,10 @@ void logTo(Journal * l) { sDestinationJournal = l; } Event getEvent(int * timeout) { if (sSourceJournal != nullptr) { - Event e = sSourceJournal->popEvent(); - if (e == None) { + if (sSourceJournal->isEmpty()) { sSourceJournal = nullptr; } else { - return e; + return sSourceJournal->popEvent(); } } Event e = innerGetEvent(timeout); diff --git a/ion/src/simulator/shared/journal.cpp b/ion/src/simulator/shared/journal.cpp index f6112d48c..8677fb40c 100644 --- a/ion/src/simulator/shared/journal.cpp +++ b/ion/src/simulator/shared/journal.cpp @@ -12,10 +12,16 @@ public: 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 m_eventStorage; };