Use an enum type for the 'should read fingerprint' flag, rather than a mysterious boolean
Fix tests.
This commit is contained in:
@@ -31,19 +31,24 @@ class FileReader
|
||||
boost::filesystem::ifstream input_stream;
|
||||
|
||||
public:
|
||||
FileReader(const std::string &filename, const bool check_fingerprint = false)
|
||||
: FileReader(boost::filesystem::path(filename), check_fingerprint)
|
||||
enum FingerprintFlag
|
||||
{
|
||||
VerifyFingerprint,
|
||||
HasNoFingerprint
|
||||
};
|
||||
FileReader(const std::string &filename, const FingerprintFlag flag)
|
||||
: FileReader(boost::filesystem::path(filename), flag)
|
||||
{
|
||||
}
|
||||
|
||||
FileReader(const boost::filesystem::path &filename_, const bool check_fingerprint = false)
|
||||
FileReader(const boost::filesystem::path &filename_, const FingerprintFlag flag)
|
||||
: filename(filename_.string())
|
||||
{
|
||||
input_stream.open(filename_, std::ios::binary);
|
||||
if (!input_stream)
|
||||
throw util::exception("Error opening " + filename + ":" + std::strerror(errno));
|
||||
|
||||
if (check_fingerprint && !ReadAndCheckFingerprint())
|
||||
if (flag == VerifyFingerprint && !ReadAndCheckFingerprint())
|
||||
{
|
||||
throw util::exception("Fingerprint mismatch in " + filename);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
|
||||
+8
-12
@@ -30,12 +30,8 @@ inline bool writeFingerprint(std::ostream &stream)
|
||||
}
|
||||
|
||||
template <typename simple_type>
|
||||
bool serializeVector(const std::string &filename, const std::vector<simple_type> &data)
|
||||
bool serializeVector(std::ostream &stream, 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())
|
||||
@@ -44,13 +40,13 @@ bool serializeVector(const std::string &filename, const std::vector<simple_type>
|
||||
}
|
||||
|
||||
template <typename simple_type>
|
||||
bool serializeVector(std::ostream &stream, const std::vector<simple_type> &data)
|
||||
bool serializeVector(const std::string &filename, const std::vector<simple_type> &data)
|
||||
{
|
||||
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);
|
||||
std::ofstream stream(filename, std::ios::binary);
|
||||
|
||||
writeFingerprint(stream);
|
||||
|
||||
return serializeVector(stream, data);
|
||||
}
|
||||
|
||||
// serializes a vector of vectors into an adjacency array (creates a copy of the data internally)
|
||||
@@ -116,7 +112,7 @@ void deserializeAdjacencyArray(const std::string &filename,
|
||||
std::vector<std::uint32_t> &offsets,
|
||||
std::vector<simple_type> &data)
|
||||
{
|
||||
storage::io::FileReader file(filename);
|
||||
storage::io::FileReader file(filename, storage::io::FileReader::HasNoFingerprint);
|
||||
|
||||
file.DeserializeVector(offsets);
|
||||
file.DeserializeVector(data);
|
||||
|
||||
@@ -346,7 +346,8 @@ class StaticRTree
|
||||
const CoordinateListT &coordinate_list)
|
||||
: m_coordinate_list(coordinate_list)
|
||||
{
|
||||
storage::io::FileReader tree_node_file(node_file);
|
||||
storage::io::FileReader tree_node_file(node_file,
|
||||
storage::io::FileReader::HasNoFingerprint);
|
||||
|
||||
const auto tree_size = tree_node_file.ReadElementCount64();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user