inline bool serializeFlags(const boost::filesystem::path &path, const std::vector<bool> &flags) { // TODO this should be replaced with a FILE-based write using error checking std::ofstream flag_stream(path.string(), std::ios::binary); writeFingerprint(flag_stream); std::uint32_t number_of_bits = flags.size(); flag_stream.write(reinterpret_cast<const char *>(&number_of_bits), sizeof(number_of_bits)); // putting bits in ints std::uint32_t chunk = 0; std::size_t chunk_count = 0; for (std::size_t bit_nr = 0; bit_nr < number_of_bits;) { std::bitset<32> chunk_bitset; for (std::size_t chunk_bit = 0; chunk_bit < 32 && bit_nr < number_of_bits; ++chunk_bit, ++bit_nr) chunk_bitset[chunk_bit] = flags[bit_nr]; chunk = chunk_bitset.to_ulong(); ++chunk_count; flag_stream.write(reinterpret_cast<const char *>(&chunk), sizeof(chunk)); } Log() << "Wrote " << number_of_bits << " bits in " << chunk_count << " chunks (Flags)."; return static_cast<bool>(flag_stream); }
bool serializeVector(const std::string &filename, const std::vector<simple_type> &data) { std::ofstream stream(filename, std::ios::binary); writeFingerprint(stream); return serializeVector(stream, data); }
bool serializeVector(const std::string &filename, const std::vector<simple_type> &data) { std::ofstream stream(filename, std::ios::binary); writeFingerprint(stream); std::uint64_t count = data.size(); stream.write(reinterpret_cast<const char *>(&count), sizeof(count)); if (!data.empty()) stream.write(reinterpret_cast<const char *>(&data[0]), sizeof(simple_type) * count); return static_cast<bool>(stream); }