mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 18:35:20 +00:00
Merge branch 'esmstore-round-2' into 'master'
More ESMStore cleanup See merge request OpenMW/openmw!2383
This commit is contained in:
commit
95ad1d91df
@ -316,13 +316,6 @@ void ESMStore::setIdType(const std::string& id, ESM::RecNameInts type)
|
||||
mStoreImp->mIds[id] = type;
|
||||
}
|
||||
|
||||
static std::size_t sTypeIndexCounter = 0;
|
||||
|
||||
std::size_t ESMStore::geNextTypeIndex()
|
||||
{
|
||||
return sTypeIndexCounter++;
|
||||
}
|
||||
|
||||
ESM::LuaScriptsCfg ESMStore::getLuaScriptsCfg() const
|
||||
{
|
||||
ESM::LuaScriptsCfg cfg;
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <components/esm/luascripts.hpp>
|
||||
#include <components/esm3/loadgmst.hpp>
|
||||
#include <components/misc/tuplemeta.hpp>
|
||||
|
||||
#include "store.hpp"
|
||||
|
||||
@ -125,22 +126,11 @@ namespace MWWorld
|
||||
// Special entry which is hardcoded and not loaded from an ESM
|
||||
Store<ESM::Attribute >>;
|
||||
|
||||
template <class T, class Tuple>
|
||||
struct HasMember;
|
||||
|
||||
template <class T, class ... Args>
|
||||
struct HasMember<T, std::tuple<Store<Args> ...>> {
|
||||
static constexpr bool value = (std::is_same_v<T, Args> || ...);
|
||||
};
|
||||
|
||||
static std::size_t geNextTypeIndex();
|
||||
|
||||
template<typename T>
|
||||
static std::size_t getTypeIndex()
|
||||
static constexpr std::size_t getTypeIndex()
|
||||
{
|
||||
static_assert(HasMember<T, StoreTuple>::value);
|
||||
static std::size_t sIndex = geNextTypeIndex();
|
||||
return sIndex;
|
||||
static_assert(Misc::TupleHasType<Store<T>, StoreTuple>::value);
|
||||
return Misc::TupleTypeIndex<Store<T>, StoreTuple>::value;
|
||||
}
|
||||
|
||||
std::unique_ptr<ESMStoreImp> mStoreImp;
|
||||
|
35
components/misc/tuplemeta.hpp
Normal file
35
components/misc/tuplemeta.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef OPENMW_COMPONENTS_MISC_META_H
|
||||
#define OPENMW_COMPONENTS_MISC_META_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
template <class T, class Tuple>
|
||||
struct TupleHasType;
|
||||
|
||||
template <class T, class... Args>
|
||||
struct TupleHasType<T, std::tuple<Args...>>
|
||||
{
|
||||
static constexpr bool value = (std::is_same_v<T, Args> || ...);
|
||||
};
|
||||
|
||||
template <class T, class Tuple>
|
||||
struct TupleTypeIndex;
|
||||
|
||||
template <class T, class... Types>
|
||||
struct TupleTypeIndex<T, std::tuple<T, Types...>>
|
||||
{
|
||||
static constexpr std::size_t value = 0;
|
||||
};
|
||||
|
||||
template <class T, class U, class... Types>
|
||||
struct TupleTypeIndex<T, std::tuple<U, Types...>>
|
||||
{
|
||||
static constexpr std::size_t value = 1 + TupleTypeIndex<T, std::tuple<Types...>>::value;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user