mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 03:29:55 +00:00
Split type traits for ESM4, ESM3 and unite common
This commit is contained in:
parent
e1f580e7a0
commit
90ed24f4c9
5 changed files with 68 additions and 48 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <type_traits>
|
||||
|
||||
#include <components/esm/esmcommon.hpp>
|
||||
#include <components/esm/typetraits.hpp>
|
||||
#include <components/esm4/reader.hpp>
|
||||
#include <components/esm4/readerutils.hpp>
|
||||
#include <components/esm4/records.hpp>
|
||||
|
@ -93,7 +94,7 @@ namespace EsmTool
|
|||
std::cout << "\n Record: " << ESM::NAME(reader.hdr().record.typeId).toStringView();
|
||||
if constexpr (ESM4::hasFormId<T>)
|
||||
std::cout << "\n FormId: " << value.mFormId;
|
||||
if constexpr (ESM4::hasId<T>)
|
||||
if constexpr (ESM::hasId<T>)
|
||||
std::cout << "\n Id: " << value.mId;
|
||||
if constexpr (ESM4::hasFlags<T>)
|
||||
std::cout << "\n Record flags: " << recordFlags(value.mFlags);
|
||||
|
@ -103,7 +104,7 @@ namespace EsmTool
|
|||
std::cout << "\n Parent: " << value.mParent;
|
||||
if constexpr (ESM4::hasEditorId<T>)
|
||||
std::cout << "\n EditorId: " << value.mEditorId;
|
||||
if constexpr (ESM4::hasModel<T>)
|
||||
if constexpr (ESM::hasModel<T>)
|
||||
std::cout << "\n Model: " << value.mModel;
|
||||
if constexpr (ESM4::hasNif<T>)
|
||||
std::cout << "\n Nif:" << WriteArray("\n - ", value.mNif);
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
|
||||
#include <components/esm/defs.hpp>
|
||||
#include <components/esm/records.hpp>
|
||||
#include <components/esm/typetraits.hpp>
|
||||
#include <components/esm3/esmreader.hpp>
|
||||
#include <components/esm3/esmwriter.hpp>
|
||||
#include <components/esm3/typetraits.hpp>
|
||||
#include <components/esm4/common.hpp>
|
||||
#include <components/esm4/loadcell.hpp>
|
||||
#include <components/esm4/loadligh.hpp>
|
||||
|
@ -20,7 +22,6 @@
|
|||
#include <components/esm4/loadstat.hpp>
|
||||
#include <components/esm4/reader.hpp>
|
||||
#include <components/esm4/readerutils.hpp>
|
||||
#include <components/esm4/typetraits.hpp>
|
||||
#include <components/files/configurationmanager.hpp>
|
||||
#include <components/files/conversion.hpp>
|
||||
#include <components/loadinglistener/loadinglistener.hpp>
|
||||
|
@ -428,19 +429,6 @@ namespace
|
|||
{
|
||||
};
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasIndex : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasIndex<T, std::void_t<decltype(T::mIndex)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr bool hasIndex = HasIndex<T>::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<RecordType> && !std::is_same_v<RecordType, ESM::LandTexture>)
|
||||
if constexpr (ESM::hasIndex<RecordType> && !std::is_same_v<RecordType, ESM::LandTexture>)
|
||||
refId = RecordType::indexToRefId(index);
|
||||
else
|
||||
refId = ESM::StringRefId("foobar");
|
||||
|
@ -465,7 +453,7 @@ namespace
|
|||
|
||||
record.mId = refId;
|
||||
|
||||
if constexpr (hasIndex<RecordType>)
|
||||
if constexpr (ESM::hasIndex<RecordType>)
|
||||
record.mIndex = index;
|
||||
|
||||
if constexpr (std::is_same_v<RecordType, ESM::Global>)
|
||||
|
@ -482,7 +470,7 @@ namespace
|
|||
const RecordType* result = nullptr;
|
||||
if constexpr (std::is_same_v<RecordType, ESM::LandTexture>)
|
||||
result = esmStore.get<RecordType>().search(index, 0);
|
||||
else if constexpr (hasIndex<RecordType>)
|
||||
else if constexpr (ESM::hasIndex<RecordType>)
|
||||
result = esmStore.get<RecordType>().search(index);
|
||||
else
|
||||
result = esmStore.get<RecordType>().search(refId);
|
||||
|
@ -492,7 +480,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
static_assert(hasIndex<ESM::MagicEffect>);
|
||||
static_assert(ESM::hasIndex<ESM::MagicEffect>);
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasSaveFunction : std::false_type
|
||||
|
@ -558,9 +546,9 @@ namespace
|
|||
};
|
||||
|
||||
using RecordTypes = typename ToRecordTypes<MWWorld::ESMStore::StoreTuple>::Type;
|
||||
using RecordTypesWithId = typename FilterTypes<ESM4::HasId, RecordTypes>::Type;
|
||||
using RecordTypesWithId = typename FilterTypes<ESM::HasId, RecordTypes>::Type;
|
||||
using RecordTypesWithSave = typename FilterTypes<HasSaveFunction, RecordTypesWithId>::Type;
|
||||
using RecordTypesWithModel = typename FilterTypes<ESM4::HasModel, RecordTypesWithSave>::Type;
|
||||
using RecordTypesWithModel = typename FilterTypes<ESM::HasModel, RecordTypesWithSave>::Type;
|
||||
|
||||
REGISTER_TYPED_TEST_SUITE_P(StoreSaveLoadTest, shouldNotChangeRefId);
|
||||
|
||||
|
|
35
components/esm/typetraits.hpp
Normal file
35
components/esm/typetraits.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef OPENMW_COMPONENTS_ESM_TYPETRAITS
|
||||
#define OPENMW_COMPONENTS_ESM_TYPETRAITS
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasId : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasId<T, std::void_t<decltype(T::mId)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool hasId = HasId<T>::value;
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasModel : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasModel<T, std::void_t<decltype(T::mModel)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool hasModel = HasModel<T>::value;
|
||||
}
|
||||
|
||||
#endif // OPENMW_COMPONENTS_ESM_TYPETRAITS
|
22
components/esm3/typetraits.hpp
Normal file
22
components/esm3/typetraits.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef OPENMW_COMPONENTS_ESM3_TYPETRAITS
|
||||
#define OPENMW_COMPONENTS_ESM3_TYPETRAITS
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace ESM
|
||||
{
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasIndex : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasIndex<T, std::void_t<decltype(T::mIndex)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool hasIndex = HasIndex<T>::value;
|
||||
}
|
||||
|
||||
#endif // OPENMW_COMPONENTS_ESM3_TYPETRAITS
|
|
@ -18,19 +18,6 @@ namespace ESM4
|
|||
template <class T>
|
||||
inline constexpr bool hasFormId = HasFormId<T>::value;
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasId : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasId<T, std::void_t<decltype(T::mId)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool hasId = HasId<T>::value;
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasParentFormId : std::false_type
|
||||
{
|
||||
|
@ -83,19 +70,6 @@ namespace ESM4
|
|||
template <class T>
|
||||
inline constexpr bool hasEditorId = HasEditorId<T>::value;
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasModel : std::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct HasModel<T, std::void_t<decltype(T::mModel)>> : std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline constexpr bool hasModel = HasModel<T>::value;
|
||||
|
||||
template <class T, class = std::void_t<>>
|
||||
struct HasNif : std::false_type
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue