43 namespace binfile_details
49 _str(new std::ofstream(filename,mode)){};
57 _str(new std::ifstream(filename,mode)){};
65 _str(new std::fstream(filename,mode)){};
71 template<
typename T1,
typename T2>
inline
72 void read_endian(T1& st, T2& data,
bool switch_endian =
false)
74 int bytes =
sizeof(T2);
75 char *c =
reinterpret_cast<char *
>(&data);
79 for (
int i = bytes - 1; i >= 0; i--)
84 template<
typename T1,
typename T2>
inline
87 int bytes =
sizeof(T2);
88 char *c =
reinterpret_cast<char *
>(&data);
92 for (
int i = bytes - 1; i >= 0; i--)
98 bool exist(
const std::string& name)
100 bool file_exists =
false;
101 ifstream file(name.c_str(), ios::in);
102 if (file.is_open()) {
114 switch_endianity(false),
126 bfstream_base(e), binfile_details::Ofstream_Binfile_Facade(name.c_str()) {}
136 Ofstream_Binfile_Facade::open(name.c_str(),
137 truncate? ios::out | ios::binary | ios::trunc : ios::out | ios::binary);
148 it_assert(
sizeof(
char) ==
sizeof(int8_t),
"Unexpected int8_t size.");
149 put(static_cast<char>(a));
155 it_assert(
sizeof(
char) ==
sizeof(uint8_t),
"Unexpected uint8_t size.");
156 put(static_cast<char>(a));
210 write_endian<bofstream, int32_t>(*
this,
static_cast<int32_t
>(a),
switch_endianity);
217 write(a, strlen(a) + 1);
223 write(a.c_str(), a.size() + 1);
232 bfstream_base(e), binfile_details::Ifstream_Binfile_Facade(name.c_str(), ios::in | ios::binary) {}
247 std::streampos pos1, len;
263 it_assert(
sizeof(
char) ==
sizeof(int8_t),
"Unexpected int8_t size.");
272 it_assert(
sizeof(
char) ==
sizeof(uint8_t),
"Unexpected uint8_t size.");
332 "bifstream::operator>>(): binary input value must be 0 or 1");
345 std::getline(*
stream(), a,
'\0');
354 bfstream_base(e), binfile_details::Fstream_Binfile_Facade(name.c_str(), ios::in | ios::out | ios::binary)
384 std::streampos pos1, len;
400 it_assert(
sizeof(
char) ==
sizeof(int8_t),
"Unexpected int8_t size.");
401 put(static_cast<char>(a));
407 it_assert(
sizeof(
char) ==
sizeof(uint8_t),
"Unexpected uint8_t size.");
408 put(static_cast<char>(a));
462 write_endian<bfstream, int32_t>(*
this,
static_cast<int32_t
>(a),
switch_endianity);
468 write(a, strlen(a) + 1);
474 write(a.c_str(), a.size() + 1);
487 it_assert(
sizeof(
char) ==
sizeof(int8_t),
"Unexpected int8_t size.");
496 it_assert(
sizeof(
char) ==
sizeof(uint8_t),
"Unexpected uint8_t size.");
556 "bfstream::operator>>(): binary input value must be 0 or 1");
569 std::getline(*
stream(), a,
'\0');