From 8ee1244099d381b73ac1b52b8913907fe54e628f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 30 Nov 2022 23:42:23 +0100 Subject: [PATCH] Trade: allow multiple SceneFieldType accepted for a T. With the upcoming string field support, field() will be allowed to peek into SceneFieldType::UnsignedShort, but also SceneFieldType::StringOffset16 or SceneFieldType::StringRangeNullTerminated16. Most types still have a 1:1 mapping, which is why this delegates to the existing SceneFieldTypeFor trait (which is also still needed to autodetect the SceneFieldType in a SceneFieldData constructor), but certain type will be able to provide a specialized handling. --- src/Magnum/Trade/SceneData.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Magnum/Trade/SceneData.h b/src/Magnum/Trade/SceneData.h index 9f63f004b..dfb674a45 100644 --- a/src/Magnum/Trade/SceneData.h +++ b/src/Magnum/Trade/SceneData.h @@ -2991,6 +2991,15 @@ namespace Implementation { } }; + /* Used by field(). Delegates to SceneFieldTypeFor by default, types + that can work with multiple SceneFieldType values have a + specialization. */ + template struct SceneFieldTypeTraits { + constexpr static bool isCompatible(SceneFieldType type) { + return type == SceneFieldTypeFor::type(); + } + }; + template constexpr SceneMappingType sceneMappingTypeFor() { static_assert(sizeof(T) == 0, "unsupported mapping type"); return {}; @@ -3149,7 +3158,7 @@ template Containers::StridedArrayView1D SceneData::mutableMapping(co #ifndef CORRADE_NO_ASSERT template bool SceneData::checkFieldTypeCompatibility(const SceneFieldData& field, const char* const prefix) const { - CORRADE_ASSERT(Implementation::SceneFieldTypeFor::type>::type() == field._fieldType, + CORRADE_ASSERT(Implementation::SceneFieldTypeTraits::type>::isCompatible(field._fieldType), prefix << field._name << "is" << field._fieldType << "but requested a type equivalent to" << Implementation::SceneFieldTypeFor::type>::type(), false); if(field._fieldArraySize) CORRADE_ASSERT(std::is_array::value, prefix << field._name << "is an array field, use T[] to access it", false);