mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
vcmi: modernize headers
This commit is contained in:
@@ -98,7 +98,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase
|
||||
}
|
||||
else
|
||||
{
|
||||
auto hero = dynamic_cast<CGHeroInstance *>(armedObj);
|
||||
auto * hero = dynamic_cast<CGHeroInstance *>(armedObj);
|
||||
assert(hero);
|
||||
assert(hero->commander);
|
||||
data = hero->commander;
|
||||
@@ -158,7 +158,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase
|
||||
public:
|
||||
const std::type_info * loadPtr(CLoaderBase &ar, void *data, ui32 pid) const override //data is pointer to the ACTUAL POINTER
|
||||
{
|
||||
BinaryDeserializer &s = static_cast<BinaryDeserializer&>(ar);
|
||||
auto & s = static_cast<BinaryDeserializer &>(ar);
|
||||
T *&ptr = *static_cast<T**>(data);
|
||||
|
||||
//create new object under pointer
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
assert( fileVersion != 0 );
|
||||
////that const cast is evil because it allows to implicitly overwrite const objects when deserializing
|
||||
typedef typename std::remove_const<T>::type nonConstT;
|
||||
nonConstT &hlp = const_cast<nonConstT&>(data);
|
||||
auto & hlp = const_cast<nonConstT &>(data);
|
||||
hlp.serialize(*this,fileVersion);
|
||||
}
|
||||
template < typename T, typename std::enable_if < std::is_array<T>::value, int >::type = 0 >
|
||||
@@ -301,7 +301,7 @@ public:
|
||||
if(smartPointerSerialization)
|
||||
{
|
||||
load( pid ); //get the id
|
||||
std::map<ui32, void*>::iterator i = loadedPointers.find(pid); //lookup
|
||||
auto i = loadedPointers.find(pid); //lookup
|
||||
|
||||
if(i != loadedPointers.end())
|
||||
{
|
||||
@@ -327,7 +327,7 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
auto app = applier.getApplier(tid);
|
||||
auto * app = applier.getApplier(tid);
|
||||
if(app == nullptr)
|
||||
{
|
||||
logGlobal->error("load %d %d - no loader exists", tid, pid);
|
||||
|
||||
@@ -100,7 +100,7 @@ class DLL_LINKAGE BinarySerializer : public CSaverBase
|
||||
public:
|
||||
void savePtr(CSaverBase &ar, const void *data) const override
|
||||
{
|
||||
BinarySerializer &s = static_cast<BinarySerializer&>(ar);
|
||||
auto & s = static_cast<BinarySerializer &>(ar);
|
||||
const T *ptr = static_cast<const T*>(data);
|
||||
|
||||
//T is most derived known type, it's time to call actual serialize
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
// We might have an object that has multiple inheritance and store it via the non-first base pointer.
|
||||
// Therefore, all pointers need to be normalized to the actual object address.
|
||||
auto actualPointer = typeList.castToMostDerived(data);
|
||||
std::map<const void*,ui32>::iterator i = savedPointers.find(actualPointer);
|
||||
auto i = savedPointers.find(actualPointer);
|
||||
if(i != savedPointers.end())
|
||||
{
|
||||
//this pointer has been already serialized - write only it's id
|
||||
@@ -275,28 +275,28 @@ public:
|
||||
template <typename T>
|
||||
void save(const std::set<T> &data)
|
||||
{
|
||||
std::set<T> &d = const_cast<std::set<T> &>(data);
|
||||
auto & d = const_cast<std::set<T> &>(data);
|
||||
ui32 length = (ui32)d.size();
|
||||
save(length);
|
||||
for(typename std::set<T>::iterator i=d.begin();i!=d.end();i++)
|
||||
for(auto i = d.begin(); i != d.end(); i++)
|
||||
save(*i);
|
||||
}
|
||||
template <typename T, typename U>
|
||||
void save(const std::unordered_set<T, U> &data)
|
||||
{
|
||||
std::unordered_set<T, U> &d = const_cast<std::unordered_set<T, U> &>(data);
|
||||
auto & d = const_cast<std::unordered_set<T, U> &>(data);
|
||||
ui32 length = (ui32)d.size();
|
||||
*this & length;
|
||||
for(typename std::unordered_set<T, U>::iterator i=d.begin();i!=d.end();i++)
|
||||
for(auto i = d.begin(); i != d.end(); i++)
|
||||
save(*i);
|
||||
}
|
||||
template <typename T>
|
||||
void save(const std::list<T> &data)
|
||||
{
|
||||
std::list<T> &d = const_cast<std::list<T> &>(data);
|
||||
auto & d = const_cast<std::list<T> &>(data);
|
||||
ui32 length = (ui32)d.size();
|
||||
*this & length;
|
||||
for(typename std::list<T>::iterator i=d.begin();i!=d.end();i++)
|
||||
for(auto i = d.begin(); i != d.end(); i++)
|
||||
save(*i);
|
||||
}
|
||||
void save(const std::string &data)
|
||||
@@ -314,7 +314,7 @@ public:
|
||||
void save(const std::map<T1,T2> &data)
|
||||
{
|
||||
*this & ui32(data.size());
|
||||
for(typename std::map<T1,T2>::const_iterator i=data.begin();i!=data.end();i++)
|
||||
for(auto i = data.begin(); i != data.end(); i++)
|
||||
{
|
||||
save(i->first);
|
||||
save(i->second);
|
||||
@@ -324,7 +324,7 @@ public:
|
||||
void save(const std::multimap<T1, T2> &data)
|
||||
{
|
||||
*this & ui32(data.size());
|
||||
for(typename std::map<T1, T2>::const_iterator i = data.begin(); i != data.end(); i++)
|
||||
for(auto i = data.begin(); i != data.end(); i++)
|
||||
{
|
||||
save(i->first);
|
||||
save(i->second);
|
||||
|
||||
@@ -76,7 +76,7 @@ class DLL_LINKAGE CSerializer
|
||||
vectors[&typeid(T)] = VectorizedObjectInfo<T, U>(Vector, idRetriever);
|
||||
}
|
||||
|
||||
typedef std::map<const std::type_info *, std::any, TypeComparer> TTypeVecMap;
|
||||
using TTypeVecMap = std::map<const std::type_info *, std::any, TypeComparer>;
|
||||
TTypeVecMap vectors; //entry must be a pointer to vector containing pointers to the objects of key type
|
||||
|
||||
public:
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
|
||||
myType = &typeid(T);
|
||||
|
||||
TTypeVecMap::iterator i = vectors.find(myType);
|
||||
auto i = vectors.find(myType);
|
||||
if(i == vectors.end())
|
||||
return nullptr;
|
||||
else
|
||||
@@ -134,8 +134,8 @@ public:
|
||||
template<class S, class T>
|
||||
struct is_serializeable
|
||||
{
|
||||
typedef char (&Yes)[1];
|
||||
typedef char (&No)[2];
|
||||
using Yes = char (&)[1];
|
||||
using No = char (&)[2];
|
||||
|
||||
template<class U>
|
||||
static Yes test(U * data, S* arg1 = 0,
|
||||
@@ -149,42 +149,42 @@ struct is_serializeable
|
||||
template <typename T> //metafunction returning CGObjectInstance if T is its derivate or T elsewise
|
||||
struct VectorizedTypeFor
|
||||
{
|
||||
typedef typename
|
||||
using type = typename
|
||||
//if
|
||||
boost::mpl::eval_if<std::is_same<CGHeroInstance,T>,
|
||||
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::eval_if<std::is_base_of<CGObjectInstance, T>,
|
||||
boost::mpl::identity<CGObjectInstance>,
|
||||
//else
|
||||
boost::mpl::identity<T>
|
||||
> >::type type;
|
||||
>>::type;
|
||||
};
|
||||
template <typename U>
|
||||
struct VectorizedIDType
|
||||
{
|
||||
typedef typename
|
||||
using type = typename
|
||||
//if
|
||||
boost::mpl::eval_if<std::is_same<CArtifact,U>,
|
||||
boost::mpl::eval_if<std::is_same<CArtifact, U>,
|
||||
boost::mpl::identity<ArtifactID>,
|
||||
//else if
|
||||
boost::mpl::eval_if<std::is_same<CCreature,U>,
|
||||
boost::mpl::eval_if<std::is_same<CCreature, U>,
|
||||
boost::mpl::identity<CreatureID>,
|
||||
//else if
|
||||
boost::mpl::eval_if<std::is_same<CHero,U>,
|
||||
boost::mpl::eval_if<std::is_same<CHero, U>,
|
||||
boost::mpl::identity<HeroTypeID>,
|
||||
//else if
|
||||
boost::mpl::eval_if<std::is_same<CArtifactInstance,U>,
|
||||
boost::mpl::eval_if<std::is_same<CArtifactInstance, U>,
|
||||
boost::mpl::identity<ArtifactInstanceID>,
|
||||
//else if
|
||||
boost::mpl::eval_if<std::is_same<CGHeroInstance,U>,
|
||||
boost::mpl::eval_if<std::is_same<CGHeroInstance, U>,
|
||||
boost::mpl::identity<HeroTypeID>,
|
||||
//else if
|
||||
boost::mpl::eval_if<std::is_base_of<CGObjectInstance,U>,
|
||||
boost::mpl::eval_if<std::is_base_of<CGObjectInstance, U>,
|
||||
boost::mpl::identity<ObjectInstanceID>,
|
||||
//else
|
||||
boost::mpl::identity<si32>
|
||||
> > > > > >::type type;
|
||||
>>>>>>::type;
|
||||
};
|
||||
|
||||
/// Base class for deserializers
|
||||
|
||||
@@ -66,17 +66,18 @@ class DLL_LINKAGE CTypeList: public boost::noncopyable
|
||||
{
|
||||
//public:
|
||||
struct TypeDescriptor;
|
||||
typedef std::shared_ptr<TypeDescriptor> TypeInfoPtr;
|
||||
typedef std::weak_ptr<TypeDescriptor> WeakTypeInfoPtr;
|
||||
using TypeInfoPtr = std::shared_ptr<TypeDescriptor>;
|
||||
using WeakTypeInfoPtr = std::weak_ptr<TypeDescriptor>;
|
||||
struct TypeDescriptor
|
||||
{
|
||||
ui16 typeID;
|
||||
const char *name;
|
||||
std::vector<WeakTypeInfoPtr> children, parents;
|
||||
};
|
||||
typedef boost::shared_mutex TMutex;
|
||||
typedef boost::unique_lock<TMutex> TUniqueLock;
|
||||
typedef boost::shared_lock<TMutex> TSharedLock;
|
||||
using TMutex = boost::shared_mutex;
|
||||
using TUniqueLock = boost::unique_lock<TMutex>;
|
||||
using TSharedLock = boost::shared_lock<TMutex>;
|
||||
|
||||
private:
|
||||
mutable TMutex mx;
|
||||
|
||||
@@ -103,7 +104,7 @@ private:
|
||||
if(!casters.count(castingPair))
|
||||
THROW_FORMAT("Cannot find caster for conversion %s -> %s which is needed to cast %s -> %s", from->name % to->name % fromArg->name() % toArg->name());
|
||||
|
||||
auto &caster = casters.at(castingPair);
|
||||
const auto & caster = casters.at(castingPair);
|
||||
ptr = (*caster.*CastingFunction)(ptr); //Why does unique_ptr not have operator->* ..?
|
||||
}
|
||||
|
||||
@@ -150,7 +151,7 @@ public:
|
||||
template<typename TInput>
|
||||
void * castToMostDerived(const TInput * inputPtr) const
|
||||
{
|
||||
auto &baseType = typeid(typename std::remove_cv<TInput>::type);
|
||||
const auto & baseType = typeid(typename std::remove_cv<TInput>::type);
|
||||
auto derivedType = getTypeInfo(inputPtr);
|
||||
|
||||
if (strcmp(baseType.name(), derivedType->name()) == 0)
|
||||
@@ -166,7 +167,7 @@ public:
|
||||
template<typename TInput>
|
||||
std::any castSharedToMostDerived(const std::shared_ptr<TInput> inputPtr) const
|
||||
{
|
||||
auto &baseType = typeid(typename std::remove_cv<TInput>::type);
|
||||
const auto & baseType = typeid(typename std::remove_cv<TInput>::type);
|
||||
auto derivedType = getTypeInfo(inputPtr.get());
|
||||
|
||||
if (!strcmp(baseType.name(), derivedType->name()))
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
#if BOOST_VERSION >= 107000 // Boost version >= 1.70
|
||||
#include <boost/asio.hpp>
|
||||
typedef boost::asio::basic_stream_socket < boost::asio::ip::tcp > TSocket;
|
||||
typedef boost::asio::basic_socket_acceptor < boost::asio::ip::tcp > TAcceptor;
|
||||
using TSocket = boost::asio::basic_stream_socket<boost::asio::ip::tcp>;
|
||||
using TAcceptor = boost::asio::basic_socket_acceptor<boost::asio::ip::tcp>;
|
||||
#else
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -461,7 +461,7 @@ private:
|
||||
void doSerializeInternal(const std::string & fieldName, VType & value, const std::optional<DVType> & defaultValue, Args... args)
|
||||
{
|
||||
const std::optional<IType> tempDefault = defaultValue ? std::optional<IType>(static_cast<IType>(defaultValue.value())) : std::nullopt;
|
||||
IType temp = static_cast<IType>(value);
|
||||
auto temp = static_cast<IType>(value);
|
||||
|
||||
serializeInternal(fieldName, temp, tempDefault, args...);
|
||||
|
||||
@@ -476,7 +476,7 @@ private:
|
||||
{
|
||||
if(value)
|
||||
{
|
||||
IType temp = static_cast<IType>(value.value());
|
||||
auto temp = static_cast<IType>(value.value());
|
||||
pushField(fieldName);
|
||||
serializeInternal(temp, args...);
|
||||
pop();
|
||||
@@ -518,7 +518,7 @@ void JsonArraySerializer::syncSize(Container & c, JsonNode::JsonType type)
|
||||
template <typename T>
|
||||
void JsonArraySerializer::serializeInt(const size_t index, T & value)
|
||||
{
|
||||
int64_t temp = static_cast<int64_t>(value);
|
||||
auto temp = static_cast<int64_t>(value);
|
||||
|
||||
serializeInt64(index, temp);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user