mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
vcmi: use std::any_cast
This commit is contained in:
parent
e3ed728193
commit
25783066e8
1
Global.h
1
Global.h
@ -101,6 +101,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include <algorithm>
|
||||
#include <any>
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <bitset>
|
||||
|
@ -365,13 +365,13 @@ public:
|
||||
if(*actualType == *typeWeNeedToReturn)
|
||||
{
|
||||
// No casting needed, just unpack already stored shared_ptr and return it
|
||||
data = boost::any_cast<std::shared_ptr<T>>(itr->second);
|
||||
data = std::any_cast<std::shared_ptr<T>>(itr->second);
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need to perform series of casts
|
||||
auto ret = typeList.castShared(itr->second, actualType, typeWeNeedToReturn);
|
||||
data = boost::any_cast<std::shared_ptr<T>>(ret);
|
||||
data = std::any_cast<std::shared_ptr<T>>(ret);
|
||||
}
|
||||
}
|
||||
catch(std::exception &e)
|
||||
|
@ -103,7 +103,7 @@ public:
|
||||
#ifndef __APPLE__
|
||||
assert(i->second.type() == typeid(VectorizedObjectInfo<T, U>));
|
||||
#endif
|
||||
VectorizedObjectInfo<T, U> *ret = &(boost::any_cast<VectorizedObjectInfo<T, U>&>(i->second));
|
||||
VectorizedObjectInfo<T, U> *ret = std::any_cast<VectorizedObjectInfo<T, U>*>(&(i->second));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ struct PointerCaster : IPointerCaster
|
||||
{
|
||||
virtual boost::any castRawPtr(const boost::any &ptr) const override // takes void* pointing to From object, performs dynamic cast, returns void* pointing to To object
|
||||
{
|
||||
From * from = (From*)boost::any_cast<void*>(ptr);
|
||||
From * from = (From*)std::any_cast<void*>(ptr);
|
||||
To * ret = static_cast<To*>(from);
|
||||
return (void*)ret;
|
||||
}
|
||||
@ -38,7 +38,7 @@ struct PointerCaster : IPointerCaster
|
||||
{
|
||||
try
|
||||
{
|
||||
auto from = boost::any_cast<SmartPt>(ptr);
|
||||
auto from = std::any_cast<SmartPt>(ptr);
|
||||
auto ret = std::static_pointer_cast<To>(from);
|
||||
return ret;
|
||||
}
|
||||
@ -54,7 +54,7 @@ struct PointerCaster : IPointerCaster
|
||||
}
|
||||
virtual boost::any castWeakPtr(const boost::any &ptr) const override
|
||||
{
|
||||
auto from = boost::any_cast<std::weak_ptr<From>>(ptr);
|
||||
auto from = std::any_cast<std::weak_ptr<From>>(ptr);
|
||||
return castSmartPtr<std::shared_ptr<From>>(from.lock());
|
||||
}
|
||||
};
|
||||
@ -158,7 +158,7 @@ public:
|
||||
return const_cast<void*>(reinterpret_cast<const void*>(inputPtr));
|
||||
}
|
||||
|
||||
return boost::any_cast<void*>(castHelper<&IPointerCaster::castRawPtr>(
|
||||
return std::any_cast<void*>(castHelper<&IPointerCaster::castRawPtr>(
|
||||
const_cast<void*>(reinterpret_cast<const void*>(inputPtr)), &baseType,
|
||||
derivedType));
|
||||
}
|
||||
@ -177,7 +177,7 @@ public:
|
||||
|
||||
void * castRaw(void *inputPtr, const std::type_info *from, const std::type_info *to) const
|
||||
{
|
||||
return boost::any_cast<void*>(castHelper<&IPointerCaster::castRawPtr>(inputPtr, from, to));
|
||||
return std::any_cast<void*>(castHelper<&IPointerCaster::castRawPtr>(inputPtr, from, to));
|
||||
}
|
||||
boost::any castShared(boost::any inputPtr, const std::type_info *from, const std::type_info *to) const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user