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
This commit is contained in:
Egor 2024-10-22 03:24:13 +03:00
parent 967a208e4a
commit 5f9f6d2e92
6 changed files with 44 additions and 14 deletions

View file

@ -6,6 +6,19 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
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. * Mock tape implementation that uses text files as data source.
* *
@ -17,21 +30,23 @@
class FileTape : public Tape { class FileTape : public Tape {
private: private:
std::fstream file_; std::fstream file_;
FileTapeSettings settings_;
public: public:
~FileTape() override;
FileTape &operator=(const FileTape &) = delete; FileTape &operator=(const FileTape &) = delete;
FileTape(const FileTape &) = delete; FileTape(const FileTape &) = delete;
FileTape(FileTape &&) = delete; FileTape(FileTape &&) = delete;
FileTape &operator=(FileTape &&) = delete; FileTape &operator=(FileTape &&) = delete;
~FileTape() override;
/** /**
* Initialize a new instance of FileTape that will open a file with the * Initialize a new instance of FileTape that will open a file with the
* specified name. File must be read and write accessible. * specified name. File must be read and write accessible.
* *
* @param file_name Name of a file to be opened. * @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. * Advances the underlying fstream to a new line.
@ -62,9 +77,6 @@ public:
void write(int32_t data) override; void write(int32_t data) override;
}; };
struct FileTapeSettings { } // namespace tape
unsigned int readDelayMs, writeDelayMs;
unsigned int seekForwardDelayMs, seekBackwardsDelayMs;
};
#endif #endif

View file

@ -3,6 +3,8 @@
#include <cstdint> #include <cstdint>
namespace tape {
/** /**
* Abstract class representing a magnetic tape. * Abstract class representing a magnetic tape.
* *
@ -53,4 +55,6 @@ public:
virtual void write(int32_t data) = 0; virtual void write(int32_t data) = 0;
}; };
} // namespace tape
#endif #endif

12
include/tapeutil.h Normal file
View file

@ -0,0 +1,12 @@
#ifndef TAPE_UTIL_H
#define TAPE_UTIL_H
#include "tape.h"
namespace tape {
void sort(Tape &input, Tape &output);
}
#endif

View file

@ -3,16 +3,17 @@
#include <fstream> #include <fstream>
#include <string> #include <string>
FileTape::FileTape(const std::string &fileName) { tape::FileTape::FileTape(const std::string &fileName, FileTapeSettings settings)
: settings_(settings) {
this->file_ = std::fstream(fileName); 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(); }

View file

@ -1,9 +1,7 @@
#include "filetape.h"
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
int main(int /*argc*/, char * /*argv*/[]) { int main(int /*argc*/, char * /*argv*/[]) {
FileTape tape("waw");
std::cout << "Hello, World!" << std::endl; std::cout << "Hello, World!" << std::endl;
return 0; return 0;
} }

3
src/tapeutil.cpp Normal file
View file

@ -0,0 +1,3 @@
#include "tapeutil.h"
void tape::sort(Tape &input, Tape &output) {}