#ifndef FILE_TAPE_H #define FILE_TAPE_H #include "tape.h" #include #include #include /** * Mock tape implementation that uses text files as data source. * * Simulates tape operations by artificially pausing the execution of some * methods using time intervals, specified in command line arguments or a * configuration file. Each cell is represented as a seperate line in a file, * cell data is stored as plain text. */ class FileTape : public Tape { private: std::fstream file_; public: ~FileTape() override; FileTape &operator=(const FileTape &) = delete; FileTape(const FileTape &) = delete; FileTape(FileTape &&) = delete; FileTape &operator=(FileTape &&) = delete; /** * 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. */ explicit FileTape(const std::string &fileName); /** * Advances the underlying fstream to a new line. * * @return false if EOF is reached, otherwise true. */ bool seekForward() override; /** * Rewinds the underlying fstream to a previous line. * * @return false if called from the first line of a file, otherwise true. */ bool seekBackwards() override; /** * Reads and parses data from the current line. * * @return number from the line, or 0 if data can not be parsed. */ int32_t read() override; /** * Writes data to the current line. * * @param data Number, that should be written to the current line. */ void write(int32_t data) override; }; struct FileTapeSettings { unsigned int readDelayMs, writeDelayMs; unsigned int seekForwardDelayMs, seekBackwardsDelayMs; }; #endif