yadro-task/include/filetape.h

71 lines
1.7 KiB
C
Raw Normal View History

2024-10-19 02:36:22 +00:00
#ifndef FILE_TAPE_H
#define FILE_TAPE_H
#include "tape.h"
#include <cstdint>
#include <fstream>
#include <string>
/**
2024-10-21 08:03:12 +00:00
* 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.
*/
2024-10-19 02:36:22 +00:00
class FileTape : public Tape {
private:
2024-10-21 08:03:12 +00:00
std::fstream file_;
2024-10-19 02:36:22 +00:00
public:
2024-10-21 08:03:12 +00:00
~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;
2024-10-19 02:36:22 +00:00
};
#endif