From 5f9f6d2e92038b6a0acca766330f2be03d83280c Mon Sep 17 00:00:00 2001 From: erius Date: Tue, 22 Oct 2024 03:24:13 +0300 Subject: [PATCH] Added tape namespace to all tape-related declarations Added tapeutil header and source file for sorting methods Added FileTapeSettings struct to store delay settings for a file tape --- include/filetape.h | 24 ++++++++++++++++++------ include/tape.h | 4 ++++ include/tapeutil.h | 12 ++++++++++++ src/filetape.cpp | 13 +++++++------ src/main.cpp | 2 -- src/tapeutil.cpp | 3 +++ 6 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 include/tapeutil.h create mode 100644 src/tapeutil.cpp diff --git a/include/filetape.h b/include/filetape.h index 5b2f916..c0c28e9 100644 --- a/include/filetape.h +++ b/include/filetape.h @@ -6,6 +6,19 @@ #include #include +namespace tape { + +/** + * Strcuture for storing all possible settings for a file tape, + * such as read dealy, write delay etc. + */ +struct FileTapeSettings { + unsigned int readDelayMs; + unsigned int writeDelayMs; + unsigned int seekForwardDelayMs; + unsigned int seekBackwardsDelayMs; +}; + /** * Mock tape implementation that uses text files as data source. * @@ -17,21 +30,23 @@ class FileTape : public Tape { private: std::fstream file_; + FileTapeSettings settings_; public: - ~FileTape() override; FileTape &operator=(const FileTape &) = delete; FileTape(const FileTape &) = delete; FileTape(FileTape &&) = delete; FileTape &operator=(FileTape &&) = delete; + ~FileTape() override; /** * Initialize a new instance of FileTape that will open a file with the * specified name. File must be read and write accessible. * * @param file_name Name of a file to be opened. + * @param settings File tape settings */ - explicit FileTape(const std::string &fileName); + explicit FileTape(const std::string &fileName, FileTapeSettings settings); /** * Advances the underlying fstream to a new line. @@ -62,9 +77,6 @@ public: void write(int32_t data) override; }; -struct FileTapeSettings { - unsigned int readDelayMs, writeDelayMs; - unsigned int seekForwardDelayMs, seekBackwardsDelayMs; -}; +} // namespace tape #endif diff --git a/include/tape.h b/include/tape.h index ba68c5c..9e9dd10 100644 --- a/include/tape.h +++ b/include/tape.h @@ -3,6 +3,8 @@ #include +namespace tape { + /** * Abstract class representing a magnetic tape. * @@ -53,4 +55,6 @@ public: virtual void write(int32_t data) = 0; }; +} // namespace tape + #endif diff --git a/include/tapeutil.h b/include/tapeutil.h new file mode 100644 index 0000000..1433961 --- /dev/null +++ b/include/tapeutil.h @@ -0,0 +1,12 @@ +#ifndef TAPE_UTIL_H +#define TAPE_UTIL_H + +#include "tape.h" + +namespace tape { + +void sort(Tape &input, Tape &output); + +} + +#endif diff --git a/src/filetape.cpp b/src/filetape.cpp index 4ffc2fe..5390eda 100644 --- a/src/filetape.cpp +++ b/src/filetape.cpp @@ -3,16 +3,17 @@ #include #include -FileTape::FileTape(const std::string &fileName) { +tape::FileTape::FileTape(const std::string &fileName, FileTapeSettings settings) + : settings_(settings) { this->file_ = std::fstream(fileName); } -bool FileTape::seekForward() { return true; } +bool tape::FileTape::seekForward() { return true; } -bool FileTape::seekBackwards() { return true; } +bool tape::FileTape::seekBackwards() { return true; } -int32_t FileTape::read() { return 0; } +int32_t tape::FileTape::read() { return 0; } -void FileTape::write(int32_t data) {} +void tape::FileTape::write(int32_t data) {} -FileTape::~FileTape() { this->file_.close(); } +tape::FileTape::~FileTape() { this->file_.close(); } diff --git a/src/main.cpp b/src/main.cpp index ac10e2f..9f7372b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,7 @@ -#include "filetape.h" #include #include int main(int /*argc*/, char * /*argv*/[]) { - FileTape tape("waw"); std::cout << "Hello, World!" << std::endl; return 0; } diff --git a/src/tapeutil.cpp b/src/tapeutil.cpp new file mode 100644 index 0000000..382abe8 --- /dev/null +++ b/src/tapeutil.cpp @@ -0,0 +1,3 @@ +#include "tapeutil.h" + +void tape::sort(Tape &input, Tape &output) {}