mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-28 03:57:02 +02:00
Remove remaining boost::mpl usages
This commit is contained in:
parent
ad3c870fb6
commit
f8a7f6e5a7
@ -247,8 +247,8 @@ namespace JsonDetail
|
|||||||
static Type convert(const JsonNode & node)
|
static Type convert(const JsonNode & node)
|
||||||
{
|
{
|
||||||
///this should be triggered only for numeric types and enums
|
///this should be triggered only for numeric types and enums
|
||||||
static_assert(boost::mpl::or_<std::is_arithmetic<Type>, std::is_enum<Type>, boost::is_class<Type> >::value, "Unsupported type for JsonNode::convertTo()!");
|
static_assert(std::is_arithmetic_v<Type> || std::is_enum_v<Type> || std::is_class_v<Type>, "Unsupported type for JsonNode::convertTo()!");
|
||||||
return JsonConvImpl<Type, boost::mpl::or_<std::is_enum<Type>, boost::is_class<Type> >::value >::convertImpl(node);
|
return JsonConvImpl<Type, std::is_enum_v<Type> || std::is_class_v<Type> >::convertImpl(node);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
CSelector(const T &t, //SFINAE trick -> include this c-tor in overload resolution only if parameter is class
|
CSelector(const T &t, //SFINAE trick -> include this c-tor in overload resolution only if parameter is class
|
||||||
//(includes functors, lambdas) or function. Without that VC is going mad about ambiguities.
|
//(includes functors, lambdas) or function. Without that VC is going mad about ambiguities.
|
||||||
typename std::enable_if < boost::mpl::or_ < std::is_class<T>, std::is_function<T >> ::value>::type *dummy = nullptr)
|
typename std::enable_if_t < std::is_class_v<T> || std::is_function_v<T> > *dummy = nullptr)
|
||||||
: TBase(t)
|
: TBase(t)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -9,9 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <boost/mpl/vector.hpp>
|
|
||||||
#include <boost/mpl/for_each.hpp>
|
|
||||||
|
|
||||||
#include "CTypeList.h"
|
#include "CTypeList.h"
|
||||||
#include "../mapObjects/CGHeroInstance.h"
|
#include "../mapObjects/CGHeroInstance.h"
|
||||||
#include "../../Global.h"
|
#include "../../Global.h"
|
||||||
@ -37,41 +34,6 @@ public:
|
|||||||
/// Effectively revesed version of BinarySerializer
|
/// Effectively revesed version of BinarySerializer
|
||||||
class DLL_LINKAGE BinaryDeserializer : public CLoaderBase
|
class DLL_LINKAGE BinaryDeserializer : public CLoaderBase
|
||||||
{
|
{
|
||||||
template<typename Variant, typename Source>
|
|
||||||
struct VariantLoaderHelper
|
|
||||||
{
|
|
||||||
Source & source;
|
|
||||||
std::vector<std::function<Variant()>> funcs;
|
|
||||||
|
|
||||||
template <class V>
|
|
||||||
struct mpl_types_impl;
|
|
||||||
|
|
||||||
template <class... Ts>
|
|
||||||
struct mpl_types_impl<std::variant<Ts...>> {
|
|
||||||
using type = boost::mpl::vector<Ts...>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class V>
|
|
||||||
using mpl_types = typename mpl_types_impl<V>::type;
|
|
||||||
|
|
||||||
VariantLoaderHelper(Source & source):
|
|
||||||
source(source)
|
|
||||||
{
|
|
||||||
boost::mpl::for_each<mpl_types<Variant>>(std::ref(*this));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
void operator()(Type)
|
|
||||||
{
|
|
||||||
funcs.push_back([&]() -> Variant
|
|
||||||
{
|
|
||||||
Type obj;
|
|
||||||
source.load(obj);
|
|
||||||
return Variant(obj);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Ser,typename T>
|
template<typename Ser,typename T>
|
||||||
struct LoadIfStackInstance
|
struct LoadIfStackInstance
|
||||||
{
|
{
|
||||||
@ -510,17 +472,19 @@ public:
|
|||||||
this->read((void*)data.c_str(),length);
|
this->read((void*)data.c_str(),length);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T0, typename... TN>
|
template<typename... TN>
|
||||||
void load(std::variant<T0, TN...> & data)
|
void load(std::variant<TN...> & data)
|
||||||
{
|
{
|
||||||
using TVariant = std::variant<T0, TN...>;
|
|
||||||
|
|
||||||
VariantLoaderHelper<TVariant, BinaryDeserializer> loader(*this);
|
|
||||||
|
|
||||||
si32 which;
|
si32 which;
|
||||||
load( which );
|
load( which );
|
||||||
assert(which < loader.funcs.size());
|
assert(which < sizeof...(TN));
|
||||||
data = loader.funcs.at(which)();
|
|
||||||
|
// Create array of variants that contains all default-constructed alternatives
|
||||||
|
const std::variant<TN...> table[] = { TN{ }... };
|
||||||
|
// use appropriate alternative for result
|
||||||
|
data = table[which];
|
||||||
|
// perform actual load via std::visit dispatch
|
||||||
|
std::visit([this](auto& o) { load(o); }, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -149,42 +149,49 @@ struct is_serializeable
|
|||||||
template <typename T> //metafunction returning CGObjectInstance if T is its derivate or T elsewise
|
template <typename T> //metafunction returning CGObjectInstance if T is its derivate or T elsewise
|
||||||
struct VectorizedTypeFor
|
struct VectorizedTypeFor
|
||||||
{
|
{
|
||||||
using type = typename
|
using type = std::conditional_t<std::is_base_of_v<CGObjectInstance, T>, CGObjectInstance, T>;
|
||||||
//if
|
|
||||||
boost::mpl::eval_if<std::is_same<CGHeroInstance, T>,
|
|
||||||
boost::mpl::identity<CGHeroInstance>,
|
|
||||||
//else if
|
|
||||||
boost::mpl::eval_if<std::is_base_of<CGObjectInstance, T>,
|
|
||||||
boost::mpl::identity<CGObjectInstance>,
|
|
||||||
//else
|
|
||||||
boost::mpl::identity<T>
|
|
||||||
>>::type;
|
|
||||||
};
|
};
|
||||||
template <typename U>
|
|
||||||
|
template <>
|
||||||
|
struct VectorizedTypeFor<CGHeroInstance>
|
||||||
|
{
|
||||||
|
using type = CGHeroInstance;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
struct VectorizedIDType
|
struct VectorizedIDType
|
||||||
{
|
{
|
||||||
using type = typename
|
using type = std::conditional_t<std::is_base_of_v<CGObjectInstance, T>, ObjectInstanceID, int32_t>;
|
||||||
//if
|
};
|
||||||
boost::mpl::eval_if<std::is_same<CArtifact, U>,
|
|
||||||
boost::mpl::identity<ArtifactID>,
|
template <>
|
||||||
//else if
|
struct VectorizedIDType<CArtifact>
|
||||||
boost::mpl::eval_if<std::is_same<CCreature, U>,
|
{
|
||||||
boost::mpl::identity<CreatureID>,
|
using type = ArtifactID;
|
||||||
//else if
|
};
|
||||||
boost::mpl::eval_if<std::is_same<CHero, U>,
|
|
||||||
boost::mpl::identity<HeroTypeID>,
|
template <>
|
||||||
//else if
|
struct VectorizedIDType<CCreature>
|
||||||
boost::mpl::eval_if<std::is_same<CArtifactInstance, U>,
|
{
|
||||||
boost::mpl::identity<ArtifactInstanceID>,
|
using type = CreatureID;
|
||||||
//else if
|
};
|
||||||
boost::mpl::eval_if<std::is_same<CGHeroInstance, U>,
|
|
||||||
boost::mpl::identity<HeroTypeID>,
|
template <>
|
||||||
//else if
|
struct VectorizedIDType<CHero>
|
||||||
boost::mpl::eval_if<std::is_base_of<CGObjectInstance, U>,
|
{
|
||||||
boost::mpl::identity<ObjectInstanceID>,
|
using type = HeroTypeID;
|
||||||
//else
|
};
|
||||||
boost::mpl::identity<si32>
|
|
||||||
>>>>>>::type;
|
template <>
|
||||||
|
struct VectorizedIDType<CArtifactInstance>
|
||||||
|
{
|
||||||
|
using type = ArtifactInstanceID;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct VectorizedIDType<CGHeroInstance>
|
||||||
|
{
|
||||||
|
using type = HeroTypeID;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Base class for deserializers
|
/// Base class for deserializers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user