diff --git a/Storage/Tape/Parsers/TapeParser.hpp b/Storage/Tape/Parsers/TapeParser.hpp index 06270b8d7..2ae7b2d13 100644 --- a/Storage/Tape/Parsers/TapeParser.hpp +++ b/Storage/Tape/Parsers/TapeParser.hpp @@ -43,6 +43,7 @@ template class Parser { while(!has_next_symbol_ && !tape->is_at_end()) { process_pulse(tape->get_next_pulse()); } + if(tape->is_at_end()) mark_end(); has_next_symbol_ = false; return next_symbol_; } @@ -65,6 +66,12 @@ template class Parser { */ virtual void process_pulse(Storage::Tape::Tape::Pulse pulse) = 0; + /*! + An optional implementation for subclasses; called to announce that the tape has ended: that + no more process_pulse calls will occur. + */ + virtual void mark_end() {} + protected: /*! @@ -103,6 +110,13 @@ template class Parser { error_flag_ = true; } + /*! + @returns `true` if there is no data left on the tape and the WaveType queue has been exhausted; `false` otherwise. + */ + bool is_at_end(const std::shared_ptr &tape) { + return tape->is_at_end() && wave_queue_.empty() && !has_next_symbol_; + } + private: bool error_flag_;