Respect data constness in Write methods
This commit is contained in:
parent
71e7d6d6b8
commit
fe2beb6f68
@ -223,7 +223,7 @@ class FileWriter
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write count objects of type T from pointer src to output stream */
|
/* Write count objects of type T from pointer src to output stream */
|
||||||
template <typename T> bool WriteFrom(T *src, const std::size_t count)
|
template <typename T> bool WriteFrom(const T *src, const std::size_t count)
|
||||||
{
|
{
|
||||||
#if not defined __GNUC__ or __GNUC__ > 4
|
#if not defined __GNUC__ or __GNUC__ > 4
|
||||||
static_assert(std::is_trivially_copyable<T>::value,
|
static_assert(std::is_trivially_copyable<T>::value,
|
||||||
@ -233,7 +233,8 @@ class FileWriter
|
|||||||
if (count == 0)
|
if (count == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
const auto &result = output_stream.write(reinterpret_cast<char *>(src), count * sizeof(T));
|
const auto &result =
|
||||||
|
output_stream.write(reinterpret_cast<const char *>(src), count * sizeof(T));
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
throw util::exception("Error writing to " + filepath.string());
|
throw util::exception("Error writing to " + filepath.string());
|
||||||
@ -242,14 +243,14 @@ class FileWriter
|
|||||||
return static_cast<bool>(output_stream);
|
return static_cast<bool>(output_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool WriteFrom(T &target) { return WriteFrom(&target, 1); }
|
template <typename T> bool WriteFrom(const T &target) { return WriteFrom(&target, 1); }
|
||||||
|
|
||||||
template <typename T> bool WriteOne(T tmp) { return WriteFrom(tmp); }
|
template <typename T> bool WriteOne(const T tmp) { return WriteFrom(tmp); }
|
||||||
|
|
||||||
bool WriteElementCount32(const std::uint32_t count) { return WriteOne<std::uint32_t>(count); }
|
bool WriteElementCount32(const std::uint32_t count) { return WriteOne<std::uint32_t>(count); }
|
||||||
bool WriteElementCount64(const std::uint64_t count) { return WriteOne<std::uint64_t>(count); }
|
bool WriteElementCount64(const std::uint64_t count) { return WriteOne<std::uint64_t>(count); }
|
||||||
|
|
||||||
template <typename T> bool SerializeVector(std::vector<T> &data)
|
template <typename T> bool SerializeVector(const std::vector<T> &data)
|
||||||
{
|
{
|
||||||
const auto count = data.size();
|
const auto count = data.size();
|
||||||
WriteElementCount64(count);
|
WriteElementCount64(count);
|
||||||
|
Loading…
Reference in New Issue
Block a user