erius
33fee958a5
Added 2 new constructors for FileTape which copy the size of existing tape into a new one Implemented external sort of a Tape using heap sort Rewritten FileTape constructors implementation to better take advantage of existing constructor calls Added const to some parameters to indicate their immutability Added unit tests for external_sort
65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
#ifndef TAPE_H
|
|
#define TAPE_H
|
|
|
|
#include <cstdint>
|
|
|
|
namespace tape {
|
|
|
|
/**
|
|
* Abstract class representing a magnetic tape.
|
|
*
|
|
* Tape is a storage medium consisting of N cells, where each cell contains a
|
|
* 32-bit unsigned integer. Data can be read or written into one cell at a time.
|
|
* Tape can be moved one cell forward or backwards in order to change the
|
|
* targeted cell. Tape performs every operation sequentially. The amount of data
|
|
* stored on a single tape could exceed the amount of available RAM. Moving tape
|
|
* forward or backwards is a very time-consuming operation.
|
|
*/
|
|
class Tape {
|
|
public:
|
|
/**
|
|
* Compiler provided constructors and destructor definitions.
|
|
* Make move constructor and destructor default, copy construcotr delete,
|
|
* and allow destrucor to be overriden.
|
|
*/
|
|
Tape() = default;
|
|
Tape(const Tape &) = delete;
|
|
Tape(Tape &&) = default;
|
|
Tape &operator=(const Tape &) = delete;
|
|
Tape &operator=(Tape &&) = default;
|
|
virtual ~Tape() = default;
|
|
|
|
/**
|
|
* Advances the tape one cell forward.
|
|
*
|
|
* @return false if the next cell doesn't exist (reached end of tape),
|
|
* otherwise true.
|
|
*/
|
|
virtual bool seek_forward() = 0;
|
|
|
|
/**
|
|
* Rewinds the tape one cell backwards.
|
|
*
|
|
* @return false if the previous cell doesn't exist (reached beginning of
|
|
* tape), otherwise true.
|
|
*/
|
|
virtual bool seek_backwards() = 0;
|
|
|
|
/**
|
|
* Reads data from the current cell.
|
|
*
|
|
* @return number, that is stored on the current cell.
|
|
*/
|
|
virtual uint32_t read() = 0;
|
|
|
|
/**
|
|
* Writes data to the current cell.
|
|
*
|
|
* @param data Number, that should be written to the current cell.
|
|
*/
|
|
virtual void write(uint32_t data) = 0;
|
|
};
|
|
|
|
} // namespace tape
|
|
|
|
#endif // !TAPE_H
|