No shared_memory_wrapper, (De)SerializeVector
This commit is contained in:
committed by
Patrick Niklaus
parent
dce0ce0e17
commit
d94017dfae
@@ -128,20 +128,6 @@ class FileReader
|
||||
std::uint32_t ReadElementCount32() { return ReadOne<std::uint32_t>(); }
|
||||
std::uint64_t ReadElementCount64() { return ReadOne<std::uint64_t>(); }
|
||||
|
||||
template <typename VectorT> void DeserializeVector(VectorT &data)
|
||||
{
|
||||
const auto count = ReadElementCount64();
|
||||
data.resize(count);
|
||||
ReadInto(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> std::size_t GetVectorMemorySize()
|
||||
{
|
||||
const auto count = ReadElementCount64();
|
||||
Skip<T>(count);
|
||||
return sizeof(count) + sizeof(T) * count;
|
||||
}
|
||||
|
||||
template <typename T> std::size_t ReadVectorSize()
|
||||
{
|
||||
const auto count = ReadElementCount64();
|
||||
@@ -149,19 +135,6 @@ class FileReader
|
||||
return count;
|
||||
}
|
||||
|
||||
template <typename T> void *DeserializeVector(void *begin, const void *end)
|
||||
{
|
||||
auto count = ReadElementCount64();
|
||||
auto required = reinterpret_cast<char *>(begin) + sizeof(count) + sizeof(T) * count;
|
||||
if (required > end)
|
||||
throw util::exception("Not enough memory ");
|
||||
|
||||
*reinterpret_cast<decltype(count) *>(begin) = count;
|
||||
ReadInto(reinterpret_cast<T *>(reinterpret_cast<char *>(begin) + sizeof(decltype(count))),
|
||||
count);
|
||||
return required;
|
||||
}
|
||||
|
||||
bool ReadAndCheckFingerprint()
|
||||
{
|
||||
auto loaded_fingerprint = ReadOne<util::FingerPrint>();
|
||||
@@ -199,42 +172,6 @@ class FileReader
|
||||
input_stream.seekg(current_pos, input_stream.beg);
|
||||
return length;
|
||||
}
|
||||
|
||||
std::vector<std::string> ReadLines()
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::string thisline;
|
||||
try
|
||||
{
|
||||
while (std::getline(input_stream, thisline))
|
||||
{
|
||||
result.push_back(thisline);
|
||||
}
|
||||
}
|
||||
catch (const std::ios_base::failure &)
|
||||
{
|
||||
// EOF is OK here, everything else, re-throw
|
||||
if (!input_stream.eof())
|
||||
throw;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ReadLine()
|
||||
{
|
||||
std::string thisline;
|
||||
try
|
||||
{
|
||||
std::getline(input_stream, thisline);
|
||||
}
|
||||
catch (const std::ios_base::failure & /*e*/)
|
||||
{
|
||||
// EOF is OK here, everything else, re-throw
|
||||
if (!input_stream.eof())
|
||||
throw;
|
||||
}
|
||||
return thisline;
|
||||
}
|
||||
};
|
||||
|
||||
class FileWriter
|
||||
@@ -296,13 +233,6 @@ class FileWriter
|
||||
void WriteElementCount32(const std::uint32_t count) { WriteOne<std::uint32_t>(count); }
|
||||
void WriteElementCount64(const std::uint64_t count) { WriteOne<std::uint64_t>(count); }
|
||||
|
||||
template <typename VectorT> void SerializeVector(const VectorT &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
WriteElementCount64(count);
|
||||
return WriteFrom(data.data(), count);
|
||||
}
|
||||
|
||||
void WriteFingerprint()
|
||||
{
|
||||
const auto fingerprint = util::FingerPrint::GetValid();
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef OSRM_STORAGE_SERIALIZATION_HPP
|
||||
#define OSRM_STORAGE_SERIALIZATION_HPP
|
||||
|
||||
#include "util/vector_view.hpp"
|
||||
|
||||
#include "storage/io.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace storage
|
||||
{
|
||||
namespace serialization
|
||||
{
|
||||
|
||||
template <typename T> void read(io::FileReader &reader, std::vector<T> &data)
|
||||
{
|
||||
const auto count = reader.ReadElementCount64();
|
||||
data.resize(count);
|
||||
reader.ReadInto(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void write(io::FileWriter &writer, const std::vector<T> &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
writer.WriteElementCount64(count);
|
||||
return writer.WriteFrom(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void read(io::FileReader &reader, util::vector_view<T> &data)
|
||||
{
|
||||
const auto count = reader.ReadElementCount64();
|
||||
data.resize(count);
|
||||
reader.ReadInto(data.data(), count);
|
||||
}
|
||||
|
||||
template <typename T> void write(io::FileWriter &writer, const util::vector_view<T> &data)
|
||||
{
|
||||
const auto count = data.size();
|
||||
writer.WriteElementCount64(count);
|
||||
return writer.WriteFrom(data.data(), count);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user