#include <iostream>
using namespace std;
class IType
{
public:
virtual __int64 GetType() = 0;
};
class TypeIsItem : public IType{};
class TypeIsEquipmentEx : public TypeIsItem
{
public:
virtual __int64 GetEquipmentType() = 0;
virtual __int64 GetType(){return GetEquipmentType();}
};
class TypeIsClothesEx : public TypeIsEquipmentEx
{
public:
virtual __int64 GetClothesType() = 0;
virtual __int64 GetType(){return GetClothesType();}
};
class TypeIsHelmEx : public TypeIsClothesEx
{
public:
virtual __int64 GetHelmType() = 0;
virtual __int64 GetType(){return GetHelmType();}
};
class TypeIsArmorEx : public TypeIsClothesEx
{
public:
virtual __int64 GetArmorType() = 0;
virtual __int64 GetType(){return GetArmorType();}
};
class TypeIsJewelryEx : public TypeIsEquipmentEx
{
public:
virtual __int64 GetJewelryType() = 0;
virtual __int64 GetType(){return GetJewelryType();}
};
class IItemType : public TypeIsHelmEx,public TypeIsArmorEx,public TypeIsJewelryEx
{
public:
virtual __int64 GetHelmType()
{
return reinterpret_cast<__int64>(static_cast<TypeIsHelmEx*>(reinterpret_cast<IItemType*>(0x10000000))-0x10000000);
}
virtual __int64 GetClothesType()
{
return reinterpret_cast<__int64>(static_cast<TypeIsHelmEx*>(reinterpret_cast<IItemType*>(0x10000000))-0x10000000);
}
virtual __int64 GetArmorType()
{
return reinterpret_cast<__int64>(static_cast<TypeIsArmorEx*>(reinterpret_cast<IItemType*>(0x10000000))-0x10000000);
}
virtual __int64 GetJewelryType()
{
return reinterpret_cast<__int64>(static_cast<TypeIsJewelryEx*>(reinterpret_cast<IItemType*>(0x10000000))-0x10000000);
}
virtual __int64 GetEquipmentType()
{
return reinterpret_cast<__int64>(static_cast<TypeIsJewelryEx*>(reinterpret_cast<IItemType*>(0x10000000))-0x10000000);
}
};
//物品
class Item : public IItemType{};
//装备
class IEquipment : public Item{};
//武器
class IWeapon : public IEquipment{};
//盾
class IShield : public IEquipment{};
//饰品
class IJewelry : public IEquipment{};
//衣服
class IClothes : public IEquipment{};
//头盔
class IHelm : public IClothes
{
public:
virtual __int64 GetArmorType()
{
return -1;
}
};
//铠甲
class IArmor : public IClothes
{
public:
virtual __int64 GetHelmType()
{
return -1;
}
};
//头盔1
class HelmEx : public IHelm
{
};
//铠甲1
class ArmorEx : public IArmor
{
};
template<typename InterfaceItemType,typename InstItemType>
class ItemGrid
{
public:
ItemGrid():m_pItem(NULL){m_pItem = new InstItemType;}
~ItemGrid(){delete m_pItem;}
template<typename ExceptItemType,typename ParamType>
bool ItemSwap(ParamType*){return true;}
template<typename ExceptItemType,typename SrcInterfaceItemType,typename SrcInstItemType>
bool ItemIsEqual(ItemGrid<SrcInterfaceItemType,SrcInstItemType>* pSrcItem)
{
__int64 ul1 = static_cast<ExceptItemType*>(m_pItem)->GetType();
if (ul1 == -1)
return false;
__int64 ul2 = pSrcItem->GetType<ExceptItemType>();
if (ul2 == -1)
return false;
return ul1 == ul2;
}
template<typename ExceptItemType>
bool ItemIsEqual(IItemType* pSrcItem)
{
__int64 ul1 = static_cast<ExceptItemType*>(m_pItem)->GetType();
if (ul1 == -1)
return false;
__int64 ul2 = static_cast<ExceptItemType*>(pSrcItem)->GetType();
if (ul2 == -1)
return false;
return ul1 == ul2;
}
template<typename ExceptItemType>
__int64 GetType()
{
return static_cast<ExceptItemType*>(m_pItem)->GetType();
}
private:
InterfaceItemType* m_pItem;
};
int main()
{
ItemGrid<IHelm,HelmEx> ItemGrid1;
ItemGrid<IArmor,ArmorEx> ItemGrid2;
cout << ItemGrid1.ItemIsEqual<TypeIsHelmEx>(&ItemGrid2) << endl;
cout << ItemGrid1.ItemIsEqual<TypeIsArmorEx>(&ItemGrid2) << endl;
HelmEx Helm1;
ArmorEx Armor1;
cout << ItemGrid1.ItemIsEqual<TypeIsHelmEx>(&Helm1) << endl;
cout << ItemGrid1.ItemIsEqual<TypeIsHelmEx>(&Armor1) << endl;
return 0;
}