From 9d2628b74f9ba7742955cd178c42a1bd09a55523 Mon Sep 17 00:00:00 2001 From: Pepijn Schoen Date: Tue, 31 Jan 2017 19:18:26 +0100 Subject: [PATCH] Don't use bool return values on successful write, instead rely on exception throwing --- include/storage/io.hpp | 19 +++++++++---------- include/util/io.hpp | 11 ++--------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/include/storage/io.hpp b/include/storage/io.hpp index a9b7eca96..07a2a0244 100644 --- a/include/storage/io.hpp +++ b/include/storage/io.hpp @@ -224,7 +224,7 @@ class FileWriter } /* Write count objects of type T from pointer src to output stream */ - template bool WriteFrom(const T *src, const std::size_t count) + template void WriteFrom(const T *src, const std::size_t count) { #if not defined __GNUC__ or __GNUC__ > 4 static_assert(std::is_trivially_copyable::value, @@ -232,33 +232,32 @@ class FileWriter #endif if (count == 0) - return true; + return; const auto &result = output_stream.write(reinterpret_cast(src), count * sizeof(T)); + if (!result) { throw util::exception("Error writing to " + filepath.string()); } - - return static_cast(output_stream); } - template bool WriteFrom(const T &target) { return WriteFrom(&target, 1); } + template void WriteFrom(const T &target) { WriteFrom(&target, 1); } - template bool WriteOne(const T tmp) { return WriteFrom(tmp); } + template void WriteOne(const T tmp) { WriteFrom(tmp); } - bool WriteElementCount32(const std::uint32_t count) { return WriteOne(count); } - bool WriteElementCount64(const std::uint64_t count) { return WriteOne(count); } + void WriteElementCount32(const std::uint32_t count) { WriteOne(count); } + void WriteElementCount64(const std::uint64_t count) { WriteOne(count); } - template bool SerializeVector(const std::vector &data) + template void SerializeVector(const std::vector &data) { const auto count = data.size(); WriteElementCount64(count); return WriteFrom(data.data(), count); } - bool WriteFingerprint() + void WriteFingerprint() { const auto fingerprint = util::FingerPrint::GetValid(); return WriteOne(fingerprint); diff --git a/include/util/io.hpp b/include/util/io.hpp index f450efc1e..be307ea20 100644 --- a/include/util/io.hpp +++ b/include/util/io.hpp @@ -71,15 +71,8 @@ bool serializeVectorIntoAdjacencyArray(const std::string &filename, for (auto const &vec : data) all_data.insert(all_data.end(), vec.begin(), vec.end()); - if (!file.SerializeVector(offsets)) - { - return false; - } - - if (!file.SerializeVector(all_data)) - { - return false; - } + file.SerializeVector(offsets); + file.SerializeVector(all_data); return true; }