2021-12-05 17:54:36 +00:00
|
|
|
#pragma once
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace BinaryIO {
|
|
|
|
template<typename T>
|
|
|
|
std::ostream& BinaryWrite(std::ostream& stream, const T& value) {
|
|
|
|
return stream.write(reinterpret_cast<const char*>(&value), sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2022-07-28 13:39:57 +00:00
|
|
|
std::istream& BinaryRead(std::istream& stream, T& value) {
|
2022-11-01 18:21:26 +00:00
|
|
|
if (!stream.good()) throw std::runtime_error("Failed to read from istream.");
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return stream.read(reinterpret_cast<char*>(&value), sizeof(T));
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteString(const std::string& stringToWrite, std::ofstream& outstream);
|
2022-11-01 18:21:26 +00:00
|
|
|
std::string ReadString(std::istream& instream);
|
|
|
|
std::string ReadString(std::istream& instream, size_t size);
|
|
|
|
std::string ReadWString(std::istream& instream);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
inline bool DoesFileExist(const std::string& name) {
|
|
|
|
std::ifstream f(name.c_str());
|
|
|
|
return f.good();
|
|
|
|
}
|
|
|
|
}
|