63 lines
1.5 KiB
C
63 lines
1.5 KiB
C
|
#ifndef FILE_TAPE_H
|
||
|
#define FILE_TAPE_H
|
||
|
|
||
|
#include "tape.h"
|
||
|
#include <cstdint>
|
||
|
#include <fstream>
|
||
|
#include <string>
|
||
|
|
||
|
/**
|
||
|
* 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:
|
||
|
/**
|
||
|
* 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.
|
||
|
*/
|
||
|
FileTape(std::string file_name);
|
||
|
|
||
|
/**
|
||
|
* 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;
|
||
|
|
||
|
/**
|
||
|
* Closes the underlying fstream
|
||
|
*/
|
||
|
~FileTape() override;
|
||
|
};
|
||
|
|
||
|
#endif
|