31 lines
768 B
C++
31 lines
768 B
C++
#include "../headers/fileDevice.h"
|
|
#include <stdexcept>
|
|
|
|
fileDevice::fileDevice(const std::string& filename) {
|
|
file.open(filename, std::ios::in | std::ios::out | std::ios::binary);
|
|
if (!file.is_open()) {
|
|
std::ofstream create(filename, std::ios::binary);
|
|
create.close();
|
|
file.open(filename, std::ios::in | std::ios::out | std::ios::binary);
|
|
}
|
|
|
|
if (!file.is_open()) {
|
|
throw std::runtime_error("Datoteke ni mogoče odpreti: " + filename);
|
|
}
|
|
}
|
|
|
|
|
|
uint8_t fileDevice::read() {
|
|
int c = file.get();
|
|
if (c == EOF) {
|
|
return 0;
|
|
}
|
|
return static_cast<uint8_t>(c);
|
|
}
|
|
|
|
void fileDevice::write(uint8_t val) {
|
|
file.put(static_cast<char>(val));
|
|
file.flush();
|
|
}
|
|
|
|
bool fileDevice::test() {return true;}
|