57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#ifndef GERMANAIRLINESVA_FILE_HELPERS_H
|
|
#define GERMANAIRLINESVA_FILE_HELPERS_H
|
|
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace germanairlinesva
|
|
{
|
|
namespace file
|
|
{
|
|
static inline const std::string readString(std::ifstream &in,
|
|
std::uint8_t length)
|
|
{
|
|
std::vector<char> value(length + 1);
|
|
in.read(value.data(), length);
|
|
return std::string(std::move(value.data()));
|
|
}
|
|
|
|
static inline const std::string readString(std::ifstream &in)
|
|
{
|
|
std::uint8_t length;
|
|
in.read(reinterpret_cast<char *>(&length), 1);
|
|
std::vector<char> value(length + 1);
|
|
in.read(value.data(), length);
|
|
return std::string(std::move(value.data()));
|
|
}
|
|
|
|
template <typename T> static inline const T read(std::ifstream &in)
|
|
{
|
|
T value;
|
|
in.read(reinterpret_cast<char *>(&value), sizeof(value));
|
|
return value;
|
|
}
|
|
|
|
static inline void writeString(std::ofstream &out, std::string value)
|
|
{
|
|
std::uint8_t length = value.length();
|
|
out.write(reinterpret_cast<char *>(&length), sizeof(length));
|
|
out.write(value.data(), length);
|
|
}
|
|
|
|
static inline void
|
|
writeString(std::ofstream &out, std::string value, std::uint8_t length)
|
|
{
|
|
out.write(value.data(), length);
|
|
}
|
|
|
|
template <typename T> static inline void write(std::ofstream &out, T value)
|
|
{
|
|
out.write(reinterpret_cast<char *>(&value), sizeof(value));
|
|
}
|
|
} // namespace file
|
|
} // namespace germanairlinesva
|
|
|
|
#endif |