From f5ad22ecf4445a2b90e9fe0ece149c2ddd438b05 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 18 Apr 2020 03:46:24 -0400 Subject: [PATCH 1/2] MemoryReader/MemoryWriter: Remove unnecessary reinterpret_casts In most cases, these can be static casts or removed entirely. --- src/athena/MemoryReader.cpp | 4 ++-- src/athena/MemoryWriter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/athena/MemoryReader.cpp b/src/athena/MemoryReader.cpp index 9b60938..bdbd3df 100644 --- a/src/athena/MemoryReader.cpp +++ b/src/athena/MemoryReader.cpp @@ -21,7 +21,7 @@ MemoryReader::MemoryReader(const void* data, atUint64 length, bool takeOwnership MemoryReader::~MemoryReader() { if (m_owns) - delete[] reinterpret_cast(m_data); + delete[] static_cast(m_data); } MemoryCopyReader::MemoryCopyReader(const void* data, atUint64 length) : MemoryReader(data, length, false) { @@ -111,7 +111,7 @@ atUint64 MemoryReader::readUBytesToBuf(void* buf, atUint64 length) { } length = std::min(length, m_length - m_position); - memmove(buf, reinterpret_cast(m_data) + m_position, length); + memmove(buf, static_cast(m_data) + m_position, length); m_position += length; return length; } diff --git a/src/athena/MemoryWriter.cpp b/src/athena/MemoryWriter.cpp index a0be0e2..a825fd6 100644 --- a/src/athena/MemoryWriter.cpp +++ b/src/athena/MemoryWriter.cpp @@ -233,7 +233,7 @@ void MemoryWriter::writeUBytes(const atUint8* data, atUint64 length) { return; } - memmove(reinterpret_cast(m_data + m_position), data, length); + memmove(m_data + m_position, data, length); m_position += length; } @@ -248,7 +248,7 @@ void MemoryCopyWriter::writeUBytes(const atUint8* data, atUint64 length) { if (m_position + length > m_length) resize(m_position + length); - memmove(reinterpret_cast(m_data + m_position), data, length); + memmove(m_data + m_position, data, length); m_position += length; } From 25d3ed0f33529d342bffef7a1a7ff4dc3b109798 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 18 Apr 2020 03:54:22 -0400 Subject: [PATCH 2/2] DNAOp: Make use of template keyword for dependent templates Prevents potential ambiguities from occurring. --- include/athena/DNAOp.hpp | 61 ++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/include/athena/DNAOp.hpp b/include/athena/DNAOp.hpp index ba502d3..be7f68d 100644 --- a/include/athena/DNAOp.hpp +++ b/include/athena/DNAOp.hpp @@ -147,18 +147,20 @@ struct BinarySize { } template static std::enable_if_t> Do(const PropId& id, T& var, StreamT& s) { - for (auto& v : var) - BinarySize::Do, DNAE>(id, v, s); + for (auto& v : var) { + BinarySize::template Do, DNAE>(id, v, s); + } } template static void DoSize(const PropId& id, T& var, StreamT& s) { - BinarySize::Do(id, var, s); + BinarySize::template Do(id, var, s); } template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count, StreamT& s) { - for (T& v : vector) - BinarySize::Do(id, v, s); + for (T& v : vector) { + BinarySize::template Do(id, v, s); + } } template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count, @@ -255,7 +257,7 @@ struct PropCount { } template static void DoSize(const PropId& id, T& var, StreamT& s) { - PropCount::Do(id, var, s); + PropCount::template Do(id, var, s); } template static void Do(const PropId& id, std::vector& vector, const S& count, StreamT& s) { @@ -327,12 +329,13 @@ struct Read { } template static std::enable_if_t> Do(const PropId& id, T& var, StreamT& s) { - for (auto& v : var) - Read::Do, DNAE>(id, v, s); + for (auto& v : var) { + Read::template Do, DNAE>(id, v, s); + } } template static void DoSize(const PropId& id, T& var, StreamT& s) { - Read::Do(id, var, s); + Read::template Do(id, var, s); } template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count, @@ -341,7 +344,7 @@ struct Read { vector.reserve(count); for (size_t i = 0; i < static_cast(count); ++i) { vector.emplace_back(); - Read::Do(id, vector.back(), r); + Read::template Do(id, vector.back(), r); } } template @@ -483,18 +486,20 @@ struct Write { } template static std::enable_if_t> Do(const PropId& id, T& var, StreamT& s) { - for (auto& v : var) - Write::Do, DNAE>(id, v, s); + for (auto& v : var) { + Write::template Do, DNAE>(id, v, s); + } } template static void DoSize(const PropId& id, T& var, StreamT& s) { - Write::Do(id, var, s); + Write::template Do(id, var, s); } template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count, StreamT& w) { - for (T& v : vector) - Write::Do(id, v, w); + for (T& v : vector) { + Write::template Do(id, v, w); + } } template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count, @@ -596,9 +601,11 @@ struct ReadYaml { template static std::enable_if_t> Do(const PropId& id, T& var, StreamT& r) { size_t _count; - if (auto __v = r.enterSubVector(id.name, _count)) - for (size_t i = 0; i < _count && i < std::extent_v; ++i) - ReadYaml::Do, DNAE>({}, var[i], r); + if (auto __v = r.enterSubVector(id.name, _count)) { + for (size_t i = 0; i < _count && i < std::extent_v; ++i) { + ReadYaml::template Do, DNAE>({}, var[i], r); + } + } } template static void DoSize(const PropId& id, T& var, StreamT& s) { @@ -613,7 +620,7 @@ struct ReadYaml { vector.reserve(_count); for (size_t i = 0; i < _count; ++i) { vector.emplace_back(); - ReadYaml::Do({}, vector.back(), r); + ReadYaml::template Do({}, vector.back(), r); } } /* Horrible reference abuse (but it works) */ @@ -712,9 +719,11 @@ struct WriteYaml { } template static std::enable_if_t> Do(const PropId& id, T& var, StreamT& w) { - if (auto __v = w.enterSubVector(id.name)) - for (auto& v : var) - WriteYaml::Do, DNAE>({}, v, w); + if (auto __v = w.enterSubVector(id.name)) { + for (auto& v : var) { + WriteYaml::template Do, DNAE>({}, v, w); + } + } } template static void DoSize(const PropId& id, T& var, StreamT& s) { @@ -723,9 +732,11 @@ struct WriteYaml { template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count, StreamT& w) { - if (auto __v = w.enterSubVector(id.name)) - for (T& v : vector) - WriteYaml::Do(id, v, w); + if (auto __v = w.enterSubVector(id.name)) { + for (T& v : vector) { + WriteYaml::template Do(id, v, w); + } + } } template static std::enable_if_t> Do(const PropId& id, std::vector& vector, const S& count,