36 lines
839 B
C++
36 lines
839 B
C++
#pragma once
|
|
|
|
#include <fstream>
|
|
#include <sp/io/IOInterface.h>
|
|
|
|
namespace sp {
|
|
|
|
struct FileTag {};
|
|
|
|
template <>
|
|
class IOInterface<FileTag> {
|
|
private:
|
|
std::ofstream m_FileOutput;
|
|
std::ifstream m_FileInput;
|
|
|
|
public:
|
|
IOInterface(const std::string& filePath) : m_FileOutput(filePath), m_FileInput(filePath) {}
|
|
IOInterface(IOInterface&& other) : m_FileOutput(std::move(other.m_FileOutput)), m_FileInput(std::move(other.m_FileInput)) {}
|
|
|
|
DataBuffer Read(std::size_t a_Amount) {
|
|
DataBuffer buffer;
|
|
buffer.Resize(a_Amount);
|
|
m_FileInput.read(reinterpret_cast<char*>(buffer.data()), a_Amount);
|
|
return buffer;
|
|
}
|
|
|
|
void Write(const sp::DataBuffer& a_Data) {
|
|
m_FileOutput.write(reinterpret_cast<const char*>(a_Data.data()), a_Data.GetSize());
|
|
m_FileOutput.flush();
|
|
}
|
|
};
|
|
|
|
using FileIO = IOInterface<FileTag>;
|
|
|
|
} // namespace sp
|