1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-04 18:29:40 +00:00

Added: a shout-out when the tape has been exhausted.

This commit is contained in:
Thomas Harte 2017-06-08 21:32:27 -04:00
parent c6e48dfd56
commit bc0d70b2f7

View File

@ -43,6 +43,7 @@ template <typename WaveType, typename SymbolType> 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 <typename WaveType, typename SymbolType> 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 <typename WaveType, typename SymbolType> 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<Storage::Tape::Tape> &tape) {
return tape->is_at_end() && wave_queue_.empty() && !has_next_symbol_;
}
private:
bool error_flag_;