diff --git a/OSBindings/Mac/Clock SignalTests/CommodoreStaticAnalyserTests.mm b/OSBindings/Mac/Clock SignalTests/CommodoreStaticAnalyserTests.mm index 5fc87c3da..f2dc2e2c0 100644 --- a/OSBindings/Mac/Clock SignalTests/CommodoreStaticAnalyserTests.mm +++ b/OSBindings/Mac/Clock SignalTests/CommodoreStaticAnalyserTests.mm @@ -46,7 +46,6 @@ struct HitRate { continue; } - NSLog(@"%@", diskItem); const auto list = Analyser::Static::GetTargets([path stringByAppendingPathComponent:diskItem].UTF8String); if(list.empty()) { continue; diff --git a/Storage/FileHolder.cpp b/Storage/FileHolder.cpp index 5a43b99c5..8dc772a64 100644 --- a/Storage/FileHolder.cpp +++ b/Storage/FileHolder.cpp @@ -133,7 +133,7 @@ void FileHolder::seek(long offset, int whence) { std::fseek(file_, offset, whence); } -long FileHolder::tell() { +long FileHolder::tell() const { return std::ftell(file_); } @@ -141,7 +141,7 @@ void FileHolder::flush() { std::fflush(file_); } -bool FileHolder::eof() { +bool FileHolder::eof() const { return std::feof(file_); } @@ -159,7 +159,7 @@ bool FileHolder::check_signature(const char *signature, std::size_t length) { return true; } -std::string FileHolder::extension() { +std::string FileHolder::extension() const { std::size_t pointer = name_.size() - 1; while(pointer > 0 && name_[pointer] != '.') pointer--; if(name_[pointer] == '.') pointer++; @@ -178,11 +178,11 @@ void FileHolder::ensure_is_at_least_length(long length) { } } -bool FileHolder::get_is_known_read_only() { +bool FileHolder::get_is_known_read_only() const { return is_read_only_; } -struct stat &FileHolder::stats() { +const struct stat &FileHolder::stats() const { return file_stats_; } diff --git a/Storage/FileHolder.hpp b/Storage/FileHolder.hpp index 2749a44e8..402f792dc 100644 --- a/Storage/FileHolder.hpp +++ b/Storage/FileHolder.hpp @@ -144,13 +144,13 @@ public: void seek(long offset, int whence); /*! @returns The current cursor position within this file. */ - long tell(); + long tell() const; /*! Flushes any queued content that has not yet been written to disk. */ void flush(); /*! @returns @c true if the end-of-file indicator is set, @c false otherwise. */ - bool eof(); + bool eof() const; class BitStream { public: @@ -214,7 +214,7 @@ public: Determines and returns the file extension: everything from the final character back to the first dot. The string is converted to lowercase before being returned. */ - std::string extension(); + std::string extension() const; /*! Ensures the file is at least @c length bytes long, appending 0s until it is @@ -225,12 +225,12 @@ public: /*! @returns @c true if an attempt was made to read this file in ReadWrite mode but it could be opened only for reading; @c false otherwise. */ - bool get_is_known_read_only(); + bool get_is_known_read_only() const; /*! @returns the stat struct describing this file. */ - struct stat &stats(); + const struct stat &stats() const; /*! @returns a mutex owned by the file that can be used to serialise file access. diff --git a/Storage/Tape/Formats/CAS.cpp b/Storage/Tape/Formats/CAS.cpp index 2de796495..b07db8216 100644 --- a/Storage/Tape/Formats/CAS.cpp +++ b/Storage/Tape/Formats/CAS.cpp @@ -168,7 +168,7 @@ CAS::CAS(const std::string &file_name) { } } -bool CAS::is_at_end() { +bool CAS::is_at_end() const { return phase_ == Phase::EndOfFile; } diff --git a/Storage/Tape/Formats/CAS.hpp b/Storage/Tape/Formats/CAS.hpp index 61fe55858..5ec222f53 100644 --- a/Storage/Tape/Formats/CAS.hpp +++ b/Storage/Tape/Formats/CAS.hpp @@ -34,11 +34,11 @@ public: }; // implemented to satisfy @c Tape - bool is_at_end(); + bool is_at_end() const override; private: - void virtual_reset(); - Pulse virtual_get_next_pulse(); + void virtual_reset() override; + Pulse virtual_get_next_pulse() override; // Storage for the array of data blobs to transcribe into audio; // each chunk is preceded by a header which may be long, and is optionally diff --git a/Storage/Tape/Formats/CSW.cpp b/Storage/Tape/Formats/CSW.cpp index 40f8ba700..251ad4fab 100644 --- a/Storage/Tape/Formats/CSW.cpp +++ b/Storage/Tape/Formats/CSW.cpp @@ -114,7 +114,7 @@ void CSW::invert_pulse() { pulse_.type = (pulse_.type == Pulse::High) ? Pulse::Low : Pulse::High; } -bool CSW::is_at_end() { +bool CSW::is_at_end() const { return source_data_pointer_ == source_data_.size(); } diff --git a/Storage/Tape/Formats/CSW.hpp b/Storage/Tape/Formats/CSW.hpp index e269a3084..318911c1a 100644 --- a/Storage/Tape/Formats/CSW.hpp +++ b/Storage/Tape/Formats/CSW.hpp @@ -43,11 +43,11 @@ public: }; // implemented to satisfy @c Tape - bool is_at_end(); + bool is_at_end() const override; private: - void virtual_reset(); - Pulse virtual_get_next_pulse(); + void virtual_reset() override; + Pulse virtual_get_next_pulse() override; Pulse pulse_; CompressionType compression_type_; diff --git a/Storage/Tape/Formats/CommodoreTAP.cpp b/Storage/Tape/Formats/CommodoreTAP.cpp index c9049bb6c..6a9044901 100644 --- a/Storage/Tape/Formats/CommodoreTAP.cpp +++ b/Storage/Tape/Formats/CommodoreTAP.cpp @@ -45,7 +45,7 @@ void CommodoreTAP::virtual_reset() { is_at_end_ = false; } -bool CommodoreTAP::is_at_end() { +bool CommodoreTAP::is_at_end() const { return is_at_end_; } diff --git a/Storage/Tape/Formats/CommodoreTAP.hpp b/Storage/Tape/Formats/CommodoreTAP.hpp index 25bfede2b..7a27ef0df 100644 --- a/Storage/Tape/Formats/CommodoreTAP.hpp +++ b/Storage/Tape/Formats/CommodoreTAP.hpp @@ -33,12 +33,12 @@ public: }; // implemented to satisfy @c Tape - bool is_at_end(); + bool is_at_end() const override; private: Storage::FileHolder file_; - void virtual_reset(); - Pulse virtual_get_next_pulse(); + void virtual_reset() override; + Pulse virtual_get_next_pulse() override; bool updated_layout_; uint32_t file_size_; diff --git a/Storage/Tape/Formats/OricTAP.cpp b/Storage/Tape/Formats/OricTAP.cpp index 0a6441483..efd41a057 100644 --- a/Storage/Tape/Formats/OricTAP.cpp +++ b/Storage/Tape/Formats/OricTAP.cpp @@ -158,6 +158,6 @@ Tape::Pulse OricTAP::virtual_get_next_pulse() { return pulse; } -bool OricTAP::is_at_end() { +bool OricTAP::is_at_end() const { return phase_ == End; } diff --git a/Storage/Tape/Formats/OricTAP.hpp b/Storage/Tape/Formats/OricTAP.hpp index 3a996a6e0..ff96d2ae3 100644 --- a/Storage/Tape/Formats/OricTAP.hpp +++ b/Storage/Tape/Formats/OricTAP.hpp @@ -33,12 +33,12 @@ public: }; // implemented to satisfy @c Tape - bool is_at_end(); + bool is_at_end() const override; private: Storage::FileHolder file_; - void virtual_reset(); - Pulse virtual_get_next_pulse(); + void virtual_reset() override; + Pulse virtual_get_next_pulse() override; // byte serialisation and output uint16_t current_value_; diff --git a/Storage/Tape/Formats/TZX.cpp b/Storage/Tape/Formats/TZX.cpp index 2a41bf362..1349e8add 100644 --- a/Storage/Tape/Formats/TZX.cpp +++ b/Storage/Tape/Formats/TZX.cpp @@ -115,7 +115,7 @@ void TZX::get_csw_recording_block() { while(!csw.is_at_end()) { Tape::Pulse next_pulse = csw.get_next_pulse(); current_level_ = (next_pulse.type == Tape::Pulse::High); - emplace_back(std::move(next_pulse)); + push_back(next_pulse); } (void)number_of_compressed_pulses; diff --git a/Storage/Tape/Formats/TapePRG.cpp b/Storage/Tape/Formats/TapePRG.cpp index 48f335acb..c5ddb6fa9 100644 --- a/Storage/Tape/Formats/TapePRG.cpp +++ b/Storage/Tape/Formats/TapePRG.cpp @@ -95,7 +95,7 @@ void PRG::virtual_reset() { copy_mask_ = 0x80; } -bool PRG::is_at_end() { +bool PRG::is_at_end() const { return file_phase_ == FilePhaseAtEnd; } diff --git a/Storage/Tape/Formats/TapePRG.hpp b/Storage/Tape/Formats/TapePRG.hpp index 0d0cd180e..c33143f8f 100644 --- a/Storage/Tape/Formats/TapePRG.hpp +++ b/Storage/Tape/Formats/TapePRG.hpp @@ -34,12 +34,12 @@ public: }; // implemented to satisfy @c Tape - bool is_at_end(); + bool is_at_end() const override; private: FileHolder file_; - Pulse virtual_get_next_pulse(); - void virtual_reset(); + Pulse virtual_get_next_pulse() override; + void virtual_reset() override; uint16_t load_address_; uint16_t length_; diff --git a/Storage/Tape/Formats/ZX80O81P.cpp b/Storage/Tape/Formats/ZX80O81P.cpp index 16145727f..b65e1e66b 100644 --- a/Storage/Tape/Formats/ZX80O81P.cpp +++ b/Storage/Tape/Formats/ZX80O81P.cpp @@ -42,11 +42,11 @@ void ZX80O81P::virtual_reset() { bit_pointer_ = wave_pointer_ = 0; } -bool ZX80O81P::has_finished_data() { +bool ZX80O81P::has_finished_data() const { return (data_pointer_ == data_.size()) && !wave_pointer_ && !bit_pointer_; } -bool ZX80O81P::is_at_end() { +bool ZX80O81P::is_at_end() const { return has_finished_data() && has_ended_final_byte_; } diff --git a/Storage/Tape/Formats/ZX80O81P.hpp b/Storage/Tape/Formats/ZX80O81P.hpp index 17c7d085f..132804d88 100644 --- a/Storage/Tape/Formats/ZX80O81P.hpp +++ b/Storage/Tape/Formats/ZX80O81P.hpp @@ -37,15 +37,15 @@ public: private: // implemented to satisfy @c Tape - bool is_at_end(); + bool is_at_end() const override; // implemented to satisfy TargetPlatform::TypeDistinguisher - TargetPlatform::Type target_platform_type(); + TargetPlatform::Type target_platform_type() override; TargetPlatform::Type platform_type_; - void virtual_reset(); - Pulse virtual_get_next_pulse(); - bool has_finished_data(); + void virtual_reset() override; + Pulse virtual_get_next_pulse() override; + bool has_finished_data() const; uint8_t byte_; int bit_pointer_; diff --git a/Storage/Tape/Formats/ZXSpectrumTAP.cpp b/Storage/Tape/Formats/ZXSpectrumTAP.cpp index 41e742151..e7103042c 100644 --- a/Storage/Tape/Formats/ZXSpectrumTAP.cpp +++ b/Storage/Tape/Formats/ZXSpectrumTAP.cpp @@ -38,7 +38,7 @@ ZXSpectrumTAP::ZXSpectrumTAP(const std::string &file_name) : virtual_reset(); } -bool ZXSpectrumTAP::is_at_end() { +bool ZXSpectrumTAP::is_at_end() const { return file_.tell() == file_.stats().st_size && phase_ == Phase::Gap; } diff --git a/Storage/Tape/Formats/ZXSpectrumTAP.hpp b/Storage/Tape/Formats/ZXSpectrumTAP.hpp index df7fb093a..74ee390d7 100644 --- a/Storage/Tape/Formats/ZXSpectrumTAP.hpp +++ b/Storage/Tape/Formats/ZXSpectrumTAP.hpp @@ -48,7 +48,7 @@ private: void read_next_block(); // Implemented to satisfy @c Tape. - bool is_at_end() override; + bool is_at_end() const override; void virtual_reset() override; Pulse virtual_get_next_pulse() override; }; diff --git a/Storage/Tape/PulseQueuedTape.cpp b/Storage/Tape/PulseQueuedTape.cpp index 42e16d45b..15f4fc5aa 100644 --- a/Storage/Tape/PulseQueuedTape.cpp +++ b/Storage/Tape/PulseQueuedTape.cpp @@ -12,11 +12,11 @@ using namespace Storage::Tape; PulseQueuedTape::PulseQueuedTape() : pulse_pointer_(0), is_at_end_(false) {} -bool PulseQueuedTape::is_at_end() { +bool PulseQueuedTape::is_at_end() const { return is_at_end_; } -void PulseQueuedTape::set_is_at_end(bool is_at_end) { +void PulseQueuedTape::set_is_at_end(const bool is_at_end) { is_at_end_ = is_at_end; } @@ -25,27 +25,23 @@ void PulseQueuedTape::clear() { pulse_pointer_ = 0; } -bool PulseQueuedTape::empty() { +bool PulseQueuedTape::empty() const { return queued_pulses_.empty(); } -void PulseQueuedTape::emplace_back(Tape::Pulse::Type type, Time length) { +void PulseQueuedTape::emplace_back(const Tape::Pulse::Type type, const Time length) { queued_pulses_.emplace_back(type, length); } -void PulseQueuedTape::emplace_back(const Tape::Pulse &&pulse) { - queued_pulses_.emplace_back(pulse); -} - -Tape::Pulse PulseQueuedTape::silence() { - Pulse silence; - silence.type = Pulse::Zero; - silence.length.length = 1; - silence.length.clock_rate = 1; - return silence; +void PulseQueuedTape::push_back(const Tape::Pulse pulse) { + queued_pulses_.push_back(pulse); } Tape::Pulse PulseQueuedTape::virtual_get_next_pulse() { + const auto silence = [] { + return Tape::Pulse(Tape::Pulse::Type::Zero, Storage::Time(1, 1)); + }; + if(is_at_end_) { return silence(); } @@ -59,7 +55,7 @@ Tape::Pulse PulseQueuedTape::virtual_get_next_pulse() { } } - std::size_t read_pointer = pulse_pointer_; + const std::size_t read_pointer = pulse_pointer_; pulse_pointer_++; return queued_pulses_[read_pointer]; } diff --git a/Storage/Tape/PulseQueuedTape.hpp b/Storage/Tape/PulseQueuedTape.hpp index 584814fb5..2fb2b5793 100644 --- a/Storage/Tape/PulseQueuedTape.hpp +++ b/Storage/Tape/PulseQueuedTape.hpp @@ -26,20 +26,19 @@ namespace Storage::Tape { class PulseQueuedTape: public Tape { public: PulseQueuedTape(); - bool is_at_end(); + bool is_at_end() const override; protected: void emplace_back(Tape::Pulse::Type type, Time length); - void emplace_back(const Tape::Pulse &&pulse); + void push_back(Tape::Pulse); void clear(); - bool empty(); + bool empty() const; void set_is_at_end(bool); virtual void get_next_pulses() = 0; private: - Pulse virtual_get_next_pulse(); - Pulse silence(); + Pulse virtual_get_next_pulse() override; std::vector queued_pulses_; std::size_t pulse_pointer_; diff --git a/Storage/Tape/Tape.cpp b/Storage/Tape/Tape.cpp index 9dcfa7165..910f2a1ea 100644 --- a/Storage/Tape/Tape.cpp +++ b/Storage/Tape/Tape.cpp @@ -49,7 +49,7 @@ Tape::Pulse Tape::get_next_pulse() { return pulse_; } -uint64_t Tape::get_offset() { +uint64_t Tape::get_offset() const { return offset_; } diff --git a/Storage/Tape/Tape.hpp b/Storage/Tape/Tape.hpp index d1a792d53..6011fffb9 100644 --- a/Storage/Tape/Tape.hpp +++ b/Storage/Tape/Tape.hpp @@ -54,14 +54,14 @@ public: void reset(); /// @returns @c true if the tape has progressed beyond all recorded content; @c false otherwise. - virtual bool is_at_end() = 0; + virtual bool is_at_end() const = 0; /*! Returns a numerical representation of progression into the tape. Precision is arbitrary but required to be at least to the whole pulse. Greater numbers are later than earlier numbers, but not necessarily continuous. */ - virtual uint64_t get_offset(); + virtual uint64_t get_offset() const; /*! Moves the tape to the first time at which the specified offset would be returned by get_offset.