Use CRTP to define CustomData clone function

pull/3060/head
elsid 4 years ago
parent e380470558
commit bd33fa76b6
No known key found for this signature in database
GPG Key ID: D27B8E8D10A2896B

@ -46,11 +46,6 @@ namespace MWClass
mStore.readState(inventory);
}
std::unique_ptr<MWWorld::CustomData> ContainerCustomData::clone() const
{
return std::make_unique<ContainerCustomData>(*this);
}
ContainerCustomData& ContainerCustomData::asContainerCustomData()
{
return *this;

@ -13,15 +13,13 @@ namespace ESM
namespace MWClass
{
class ContainerCustomData : public MWWorld::CustomData
class ContainerCustomData : public MWWorld::TypedCustomData<ContainerCustomData>
{
MWWorld::ContainerStore mStore;
public:
ContainerCustomData(const ESM::Container& container, MWWorld::CellStore* cell);
ContainerCustomData(const ESM::InventoryState& inventory);
std::unique_ptr<MWWorld::CustomData> clone() const override;
ContainerCustomData& asContainerCustomData() override;
const ContainerCustomData& asContainerCustomData() const override;

@ -51,7 +51,7 @@ namespace
namespace MWClass
{
class CreatureCustomData : public MWWorld::CustomData
class CreatureCustomData : public MWWorld::TypedCustomData<CreatureCustomData>
{
public:
MWMechanics::CreatureStats mCreatureStats;
@ -62,8 +62,6 @@ namespace MWClass
CreatureCustomData(const CreatureCustomData& other);
CreatureCustomData(CreatureCustomData&& other) noexcept = default;
std::unique_ptr<MWWorld::CustomData> clone() const override;
CreatureCustomData& asCreatureCustomData() override
{
return *this;
@ -81,11 +79,6 @@ namespace MWClass
{
}
std::unique_ptr<MWWorld::CustomData> CreatureCustomData::clone() const
{
return std::make_unique<CreatureCustomData>(*this);
}
const Creature::GMST& Creature::getGmst()
{
static GMST gmst;

@ -10,15 +10,13 @@
namespace MWClass
{
class CreatureLevListCustomData : public MWWorld::CustomData
class CreatureLevListCustomData : public MWWorld::TypedCustomData<CreatureLevListCustomData>
{
public:
// actorId of the creature we spawned
int mSpawnActorId;
bool mSpawn; // Should a new creature be spawned?
std::unique_ptr<MWWorld::CustomData> clone() const override;
CreatureLevListCustomData& asCreatureLevListCustomData() override
{
return *this;
@ -29,11 +27,6 @@ namespace MWClass
}
};
std::unique_ptr<MWWorld::CustomData> CreatureLevListCustomData::clone() const
{
return std::make_unique<CreatureLevListCustomData>(*this);
}
std::string CreatureLevList::getName (const MWWorld::ConstPtr& ptr) const
{
return "";

@ -31,13 +31,11 @@
namespace MWClass
{
class DoorCustomData : public MWWorld::CustomData
class DoorCustomData : public MWWorld::TypedCustomData<DoorCustomData>
{
public:
MWWorld::DoorState mDoorState = MWWorld::DoorState::Idle;
std::unique_ptr<MWWorld::CustomData> clone() const override;
DoorCustomData& asDoorCustomData() override
{
return *this;
@ -48,11 +46,6 @@ namespace MWClass
}
};
std::unique_ptr<MWWorld::CustomData> DoorCustomData::clone() const
{
return std::make_unique<DoorCustomData>(*this);
}
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
if (!model.empty())

@ -246,15 +246,13 @@ namespace
namespace MWClass
{
class NpcCustomData : public MWWorld::CustomData
class NpcCustomData : public MWWorld::TypedCustomData<NpcCustomData>
{
public:
MWMechanics::NpcStats mNpcStats;
MWMechanics::Movement mMovement;
MWWorld::InventoryStore mInventoryStore;
std::unique_ptr<MWWorld::CustomData> clone() const override;
NpcCustomData& asNpcCustomData() override
{
return *this;
@ -265,11 +263,6 @@ namespace MWClass
}
};
std::unique_ptr<MWWorld::CustomData> NpcCustomData::clone() const
{
return std::make_unique<NpcCustomData>(*this);
}
const Npc::GMST& Npc::getGmst()
{
static GMST gmst;

@ -40,6 +40,15 @@ namespace MWWorld
virtual MWClass::CreatureLevListCustomData& asCreatureLevListCustomData();
virtual const MWClass::CreatureLevListCustomData& asCreatureLevListCustomData() const;
};
template <class T>
struct TypedCustomData : CustomData
{
std::unique_ptr<CustomData> clone() const final
{
return std::make_unique<T>(*static_cast<const T*>(this));
}
};
}
#endif

Loading…
Cancel
Save