1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixes for previous rev.

This commit is contained in:
Michał W. Urbańczyk 2013-02-14 02:17:46 +00:00
parent 9e00090c42
commit 827d7b8681
3 changed files with 34 additions and 15 deletions

View File

@ -368,10 +368,11 @@ public:
{
/* if(id < 0)
return NULL;*/
si32 idAsNumber = idToNumber(id);
assert(oInfo.vector);
assert(oInfo.vector->size() > id);
return const_cast<T*>((*oInfo.vector)[id].get());
assert(oInfo.vector->size() > idAsNumber);
return const_cast<T*>((*oInfo.vector)[idAsNumber].get());
}
template <typename T, typename U>
@ -431,12 +432,30 @@ struct VectorizedIDType
//else if
mpl::eval_if<boost::is_same<CCreature,U>,
mpl::identity<CreatureID>,
//else if
mpl::eval_if<boost::is_same<CArtifactInstance,U>,
mpl::identity<ArtifactInstanceID>,
//else if
mpl::eval_if<boost::is_base_of<CGObjectInstance,U>,
mpl::identity<ObjectInstanceID>,
//else
mpl::identity<si32>
>
>::type type;
> > > >::type type;
};
template<typename T>
si32 idToNumber(const T &t, typename boost::enable_if<boost::is_convertible<T,si32> >::type * dummy = 0)
{
return t;
}
template<typename T>
si32 idToNumber(const BaseForID<T> &t)
{
return t.getNum();
}
template <typename Handler>
struct VariantVisitorSaver : boost::static_visitor<>
{
@ -586,9 +605,9 @@ public:
typedef typename VectorizedIDType<TObjectType>::type IDType;
if(const auto *info = getVectorisedTypeInfo<VType, IDType>())
{
si32 id = getIdFromVectorItem<VType>(*info, data);
IDType id = getIdFromVectorItem<VType>(*info, data);
*this << id;
if(id != -1) //vector id is enough
if(id != IDType(-1)) //vector id is enough
return;
}
}
@ -961,11 +980,11 @@ public:
typedef typename VectorizedIDType<TObjectType>::type IDType;
if(const auto *info = getVectorisedTypeInfo<VType, IDType>())
{
si32 id;
IDType id;
*this >> id;
if(id != -1)
if(id != IDType(-1))
{
data = static_cast<T>(getVectorItemFromId<VType, IDType>(*info, IDType(id)));
data = static_cast<T>(getVectorItemFromId<VType, IDType>(*info, id));
return;
}
}

View File

@ -89,5 +89,5 @@ CSpell * SpellID::toSpell() const
return VLC->spellh->spells[*this];
}
template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
//template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
//template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);

View File

@ -223,10 +223,10 @@ class ObjectInstanceID : public BaseForID<ObjectInstanceID>
friend class CNonConstInfoCallback;
};
#ifndef INSTANTIATE_BASE_FOR_ID_HERE
extern template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
extern template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
#endif
// #ifndef INSTANTIATE_BASE_FOR_ID_HERE
// extern template std::ostream & operator << <ArtifactInstanceID>(std::ostream & os, BaseForID<ArtifactInstanceID> id);
// extern template std::ostream & operator << <ObjectInstanceID>(std::ostream & os, BaseForID<ObjectInstanceID> id);
// #endif
// Enum declarations
namespace PrimarySkill