From 17a0959dbd0a79f9f9630dc616adc79fff65ad80 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 23 Feb 2018 20:14:19 -1000 Subject: [PATCH] Fix implicitly-converted vector serialization --- include/athena/DNAOp.hpp | 26 ++++++++++++++++++++------ include/athena/YAMLCommon.hpp | 3 +-- src/athena/DNAYaml.cpp | 8 ++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/athena/DNAOp.hpp b/include/athena/DNAOp.hpp index f60e924..cd31c17 100644 --- a/include/athena/DNAOp.hpp +++ b/include/athena/DNAOp.hpp @@ -76,6 +76,15 @@ static inline constexpr bool __IsPODType() std::is_convertible_v; } +template +using __CastPODType = typename std::conditional_t, atVec2f, + std::conditional_t, atVec3f, + std::conditional_t, atVec4f, + std::conditional_t, atVec2d, + std::conditional_t, atVec3d, + std::conditional_t, atVec4d, + T>>>>>>; + template static inline uint16_t __Read16(IStreamReader& r) { @@ -138,7 +147,8 @@ struct BinarySize /* Accessed via Enumerate, header */ s += 6; } - BinarySize::Do(id, var, s); + using CastT = __CastPODType; + BinarySize::Do(id, static_cast(var), s); } template static typename std::enable_if_t<__IsDNARecord() && PropOp != PropType::None> @@ -334,7 +344,8 @@ struct Read static typename std::enable_if_t<__IsPODType()> Do(const PropId& id, T& var, StreamT& r) { - Read::Do(id, var, r); + using CastT = __CastPODType; + Read::Do(id, static_cast(var), r); } template static typename std::enable_if_t<__IsDNARecord() && PropOp == PropType::None> @@ -504,6 +515,7 @@ struct Write static typename std::enable_if_t<__IsPODType()> Do(const PropId& id, T& var, StreamT& w) { + using CastT = __CastPODType; if (PropOp != PropType::None) { /* Accessed via Enumerate, header */ @@ -512,10 +524,10 @@ struct Write else __Write32(w, id.rcrc32); size_t binarySize = 0; - BinarySize::Do(id, var, binarySize); + BinarySize::Do(id, static_cast(var), binarySize); __Write16(w, atUint16(binarySize)); } - Write::Do(id, var, w); + Write::Do(id, static_cast(var), w); } template static typename std::enable_if_t<__IsDNARecord() && PropOp != PropType::None> @@ -664,7 +676,8 @@ struct ReadYaml static typename std::enable_if_t<__IsPODType()> Do(const PropId& id, T& var, StreamT& r) { - ReadYaml::Do(id, var, r); + using CastT = __CastPODType; + ReadYaml::Do(id, static_cast(var), r); } template static typename std::enable_if_t<__IsDNARecord()> @@ -802,7 +815,8 @@ struct WriteYaml static typename std::enable_if_t<__IsPODType()> Do(const PropId& id, T& var, StreamT& w) { - WriteYaml::Do(id, var, w); + using CastT = __CastPODType; + WriteYaml::Do(id, static_cast(var), w); } template static typename std::enable_if_t<__IsDNARecord()> diff --git a/include/athena/YAMLCommon.hpp b/include/athena/YAMLCommon.hpp index 6452654..96b79ae 100644 --- a/include/athena/YAMLCommon.hpp +++ b/include/athena/YAMLCommon.hpp @@ -28,8 +28,7 @@ struct YAMLNode yaml_node_type_t m_type; std::string m_scalarString; std::vector> m_seqChildren; - std::vector>> - m_mapChildren; + std::vector>> m_mapChildren; YAMLNodeStyle m_style = YAMLNodeStyle::Any; YAMLNode(yaml_node_type_t type) : m_type(type) {} diff --git a/src/athena/DNAYaml.cpp b/src/athena/DNAYaml.cpp index 70b39b1..826b389 100644 --- a/src/athena/DNAYaml.cpp +++ b/src/athena/DNAYaml.cpp @@ -584,7 +584,7 @@ YAMLDocWriter::RecordRAII YAMLDocWriter::enterSubRecord(const char* name) return {}; YAMLNode* newNode = new YAMLNode(YAML_MAPPING_NODE); if (curSub->m_type == YAML_MAPPING_NODE) - curSub->assignMapChild(name?std::string(name):std::string(), std::unique_ptr(newNode)); + curSub->assignMapChild(name?name:std::string_view{}, std::unique_ptr(newNode)); else if (curSub->m_type == YAML_SEQUENCE_NODE) curSub->m_seqChildren.emplace_back(newNode); m_subStack.push_back(newNode); @@ -629,7 +629,7 @@ YAMLDocWriter::VectorRAII YAMLDocWriter::enterSubVector(const char* name) return {}; YAMLNode* newNode = new YAMLNode(YAML_SEQUENCE_NODE); if (curSub->m_type == YAML_MAPPING_NODE) - curSub->assignMapChild(name?std::string(name):std::string(), std::unique_ptr(newNode)); + curSub->assignMapChild(name?name:std::string_view{}, std::unique_ptr(newNode)); else if (curSub->m_type == YAML_SEQUENCE_NODE) curSub->m_seqChildren.emplace_back(newNode); m_subStack.push_back(newNode); @@ -647,7 +647,7 @@ void YAMLDocWriter::writeVal(const char* name, const INTYPE& val) { YAMLNode* curSub = m_subStack.back(); if (curSub->m_type == YAML_MAPPING_NODE) - curSub->assignMapChild(name?name:std::string(), std::move(ValToNode(val))); + curSub->assignMapChild(name?name:std::string_view{}, std::move(ValToNode(val))); else if (curSub->m_type == YAML_SEQUENCE_NODE) curSub->m_seqChildren.emplace_back(std::move(ValToNode(val))); } @@ -669,7 +669,7 @@ void YAMLDocWriter::writeVal(const char* name, const INTYPE& val, size_t byteCou { YAMLNode* curSub = m_subStack.back(); if (curSub->m_type == YAML_MAPPING_NODE) - curSub->assignMapChild(name?name:std::string(), std::move(ValToNode(val, byteCount))); + curSub->assignMapChild(name?name:std::string_view{}, std::move(ValToNode(val, byteCount))); else if (curSub->m_type == YAML_SEQUENCE_NODE) curSub->m_seqChildren.emplace_back(std::move(ValToNode(val, byteCount))); }