9 #ifndef TurtleBrains_FileUtilities_hpp
10 #define TurtleBrains_FileUtilities_hpp
12 #include "tb_types.hpp"
13 #include "tb_defines.hpp"
21 namespace FileUtilities
24 void WriteVariableLengthEncoding(
tbCore::uint64 length, std::ostream& outputFile);
27 tbCore::uint64 ReadVariableLengthEncoding(std::istream& inputFile);
29 template<
typename Type> Type ReadVariableLength(std::istream& inputFile)
31 return tbCore::RangedCast<Type, tbCore::uint64>(ReadVariableLengthEncoding(inputFile));
37 template <
typename Type>
void WriteBinary(
const Type&
object, std::ostream& outputFile)
39 outputFile.write(reinterpret_cast<const char*>(&
object),
sizeof(Type));
45 WriteVariableLengthEncoding(stringLength, outputFile);
46 outputFile.write(
object.c_str(), stringLength + 1);
49 template <
typename Type>
void ReadBinary(Type&
object, std::istream& inputFile)
51 inputFile.read(reinterpret_cast<char*>(&
object),
sizeof(Type));
56 const tbCore::uint32 stringLength = ReadVariableLength<tbCore::uint32>(inputFile);
62 object.resize(stringLength);
63 inputFile.read(&
object.at(0), stringLength);
70 inputFile.seekg(1, std::ios_base::cur);
73 template <
typename Type> Type ReadBinary(std::istream& inputFile)
76 ReadBinary(
object, inputFile);
80 template<>
inline tbCore::tbString ReadBinary<tbCore::tbString>(std::istream& inputFile)
83 ReadBinary(
object, inputFile);
Here is some information about the primary namespace.
Definition: tb_application_dialog.hpp:21
uint64_t uint64
Unsigned integer with a size of 64 bits, Supports values from 0 to (2^64 - 1).
Definition: tb_types.hpp:30
void WriteBinary(const tbCore::DynamicStructure &data, std::ostream &output)
uint32_t uint32
Unsigned integer with a size of 32 bits. Supports values from 0 to 4294967295, (2^32 - 1)...
Definition: tb_types.hpp:28
Contains core functionality for each component of the API.
Definition: tb_debug_logger.hpp:88
std::string tbString
Definition: tb_string.hpp:335