1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Merge pull request #126 from vmarkovtsev/issue/2306

Fix typeid ordering bug on MacOSX
This commit is contained in:
Alexander Shishkin 2015-10-25 15:47:11 +03:00
commit 07f99f06ef
2 changed files with 74 additions and 71 deletions

View File

@ -448,14 +448,14 @@ CTypeList::TypeInfoPtr CTypeList::registerType( const std::type_info *type )
return newType; return newType;
} }
ui16 CTypeList::getTypeID(const std::type_info * type) const ui16 CTypeList::getTypeID( const std::type_info *type, bool throws ) const
{ {
TSharedLock lock(mx); auto descriptor = getTypeDescriptor(type, throws);
auto i = typeInfos.find(type); if (descriptor == nullptr)
if(i != typeInfos.end()) {
return i->second->typeID;
else
return 0; return 0;
}
return descriptor->typeID;
} }
std::vector<CTypeList::TypeInfoPtr> CTypeList::castSequence(TypeInfoPtr from, TypeInfoPtr to) const std::vector<CTypeList::TypeInfoPtr> CTypeList::castSequence(TypeInfoPtr from, TypeInfoPtr to) const
@ -645,4 +645,3 @@ CMemorySerializer::CMemorySerializer(): iser(this), oser(this)
registerTypes(iser); registerTypes(iser);
registerTypes(oser); registerTypes(oser);
} }

View File

@ -81,10 +81,14 @@ enum SerializationLvl
struct TypeComparer struct TypeComparer
{ {
bool operator()(const std::type_info *a, const std::type_info *b) const bool operator()(const std::type_info *a, const std::type_info *b) const
{ {
return a->before(*b); #ifndef __APPLE__
} return a->before(*b);
#else
return std::string(a->name()) < std::string(b->name());
#endif
}
}; };
struct IPointerCaster struct IPointerCaster
@ -207,12 +211,12 @@ public:
casters[std::make_pair(dti, bti)] = make_unique<const PointerCaster<Derived, Base>>(); casters[std::make_pair(dti, bti)] = make_unique<const PointerCaster<Derived, Base>>();
} }
ui16 getTypeID(const std::type_info *type) const; ui16 getTypeID(const std::type_info *type, bool throws = false) const;
template <typename T> template <typename T>
ui16 getTypeID(const T * t = nullptr) const ui16 getTypeID(const T * t = nullptr, bool throws = false) const
{ {
return getTypeID(getTypeInfo(t)); return getTypeID(getTypeInfo(t), throws);
} }
template<typename TInput> template<typename TInput>