From 90ed24f4c9b8bc9e005310c4fdcc7b55f180bc30 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 26 Mar 2023 15:19:24 +0200 Subject: [PATCH] Split type traits for ESM4, ESM3 and unite common --- apps/esmtool/tes4.cpp | 5 +-- apps/openmw_test_suite/mwworld/test_store.cpp | 28 +++++---------- components/esm/typetraits.hpp | 35 +++++++++++++++++++ components/esm3/typetraits.hpp | 22 ++++++++++++ components/esm4/typetraits.hpp | 26 -------------- 5 files changed, 68 insertions(+), 48 deletions(-) create mode 100644 components/esm/typetraits.hpp create mode 100644 components/esm3/typetraits.hpp diff --git a/apps/esmtool/tes4.cpp b/apps/esmtool/tes4.cpp index 6b13aa705c..25054b614a 100644 --- a/apps/esmtool/tes4.cpp +++ b/apps/esmtool/tes4.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -93,7 +94,7 @@ namespace EsmTool std::cout << "\n Record: " << ESM::NAME(reader.hdr().record.typeId).toStringView(); if constexpr (ESM4::hasFormId) std::cout << "\n FormId: " << value.mFormId; - if constexpr (ESM4::hasId) + if constexpr (ESM::hasId) std::cout << "\n Id: " << value.mId; if constexpr (ESM4::hasFlags) std::cout << "\n Record flags: " << recordFlags(value.mFlags); @@ -103,7 +104,7 @@ namespace EsmTool std::cout << "\n Parent: " << value.mParent; if constexpr (ESM4::hasEditorId) std::cout << "\n EditorId: " << value.mEditorId; - if constexpr (ESM4::hasModel) + if constexpr (ESM::hasModel) std::cout << "\n Model: " << value.mModel; if constexpr (ESM4::hasNif) std::cout << "\n Nif:" << WriteArray("\n - ", value.mNif); diff --git a/apps/openmw_test_suite/mwworld/test_store.cpp b/apps/openmw_test_suite/mwworld/test_store.cpp index a275c09bc3..268bc8bc0b 100644 --- a/apps/openmw_test_suite/mwworld/test_store.cpp +++ b/apps/openmw_test_suite/mwworld/test_store.cpp @@ -11,8 +11,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -20,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -428,19 +429,6 @@ namespace { }; - template > - struct HasIndex : std::false_type - { - }; - - template - struct HasIndex> : std::true_type - { - }; - - template - constexpr bool hasIndex = HasIndex::value; - TYPED_TEST_SUITE_P(StoreSaveLoadTest); TYPED_TEST_P(StoreSaveLoadTest, shouldNotChangeRefId) @@ -449,7 +437,7 @@ namespace const int index = 3; decltype(RecordType::mId) refId; - if constexpr (hasIndex && !std::is_same_v) + if constexpr (ESM::hasIndex && !std::is_same_v) refId = RecordType::indexToRefId(index); else refId = ESM::StringRefId("foobar"); @@ -465,7 +453,7 @@ namespace record.mId = refId; - if constexpr (hasIndex) + if constexpr (ESM::hasIndex) record.mIndex = index; if constexpr (std::is_same_v) @@ -482,7 +470,7 @@ namespace const RecordType* result = nullptr; if constexpr (std::is_same_v) result = esmStore.get().search(index, 0); - else if constexpr (hasIndex) + else if constexpr (ESM::hasIndex) result = esmStore.get().search(index); else result = esmStore.get().search(refId); @@ -492,7 +480,7 @@ namespace } } - static_assert(hasIndex); + static_assert(ESM::hasIndex); template > struct HasSaveFunction : std::false_type @@ -558,9 +546,9 @@ namespace }; using RecordTypes = typename ToRecordTypes::Type; - using RecordTypesWithId = typename FilterTypes::Type; + using RecordTypesWithId = typename FilterTypes::Type; using RecordTypesWithSave = typename FilterTypes::Type; - using RecordTypesWithModel = typename FilterTypes::Type; + using RecordTypesWithModel = typename FilterTypes::Type; REGISTER_TYPED_TEST_SUITE_P(StoreSaveLoadTest, shouldNotChangeRefId); diff --git a/components/esm/typetraits.hpp b/components/esm/typetraits.hpp new file mode 100644 index 0000000000..89f9e48695 --- /dev/null +++ b/components/esm/typetraits.hpp @@ -0,0 +1,35 @@ +#ifndef OPENMW_COMPONENTS_ESM_TYPETRAITS +#define OPENMW_COMPONENTS_ESM_TYPETRAITS + +#include + +namespace ESM +{ + template > + struct HasId : std::false_type + { + }; + + template + struct HasId> : std::true_type + { + }; + + template + inline constexpr bool hasId = HasId::value; + + template > + struct HasModel : std::false_type + { + }; + + template + struct HasModel> : std::true_type + { + }; + + template + inline constexpr bool hasModel = HasModel::value; +} + +#endif // OPENMW_COMPONENTS_ESM_TYPETRAITS diff --git a/components/esm3/typetraits.hpp b/components/esm3/typetraits.hpp new file mode 100644 index 0000000000..04529f3088 --- /dev/null +++ b/components/esm3/typetraits.hpp @@ -0,0 +1,22 @@ +#ifndef OPENMW_COMPONENTS_ESM3_TYPETRAITS +#define OPENMW_COMPONENTS_ESM3_TYPETRAITS + +#include + +namespace ESM +{ + template > + struct HasIndex : std::false_type + { + }; + + template + struct HasIndex> : std::true_type + { + }; + + template + inline constexpr bool hasIndex = HasIndex::value; +} + +#endif // OPENMW_COMPONENTS_ESM3_TYPETRAITS diff --git a/components/esm4/typetraits.hpp b/components/esm4/typetraits.hpp index 95e6f607e6..1d39a23018 100644 --- a/components/esm4/typetraits.hpp +++ b/components/esm4/typetraits.hpp @@ -18,19 +18,6 @@ namespace ESM4 template inline constexpr bool hasFormId = HasFormId::value; - template > - struct HasId : std::false_type - { - }; - - template - struct HasId> : std::true_type - { - }; - - template - inline constexpr bool hasId = HasId::value; - template > struct HasParentFormId : std::false_type { @@ -83,19 +70,6 @@ namespace ESM4 template inline constexpr bool hasEditorId = HasEditorId::value; - template > - struct HasModel : std::false_type - { - }; - - template - struct HasModel> : std::true_type - { - }; - - template - inline constexpr bool hasModel = HasModel::value; - template > struct HasNif : std::false_type {