From 0d4729dcd5b57c0e7ed507ee64b59b6a27c25d56 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 Dec 2015 16:19:52 +0100 Subject: [PATCH] Use the const version of CustomData::as* --- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/creaturelevlist.cpp | 6 +++++- apps/openmw/mwclass/door.cpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwworld/customdata.cpp | 7 +++++++ apps/openmw/mwworld/customdata.hpp | 1 + 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 4b513a640..a94c70719 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -734,7 +734,7 @@ namespace MWClass return; } - const CreatureCustomData& customData = dynamic_cast(*ptr.getRefData().getCustomData()); + const CreatureCustomData& customData = ptr.getRefData().getCustomData()->asCreatureCustomData(); customData.mContainerStore->writeState (state2.mInventory); customData.mCreatureStats.writeState (state2.mCreatureStats); diff --git a/apps/openmw/mwclass/creaturelevlist.cpp b/apps/openmw/mwclass/creaturelevlist.cpp index 1f9e9b0fc..db2ba45bc 100644 --- a/apps/openmw/mwclass/creaturelevlist.cpp +++ b/apps/openmw/mwclass/creaturelevlist.cpp @@ -22,6 +22,10 @@ namespace MWClass { return *this; } + virtual const CreatureLevListCustomData& asCreatureLevListCustomData() const + { + return *this; + } }; MWWorld::CustomData *CreatureLevListCustomData::clone() const @@ -121,7 +125,7 @@ namespace MWClass return; } - const CreatureLevListCustomData& customData = dynamic_cast(*ptr.getRefData().getCustomData()); + const CreatureLevListCustomData& customData = ptr.getRefData().getCustomData()->asCreatureLevListCustomData(); state2.mSpawnActorId = customData.mSpawnActorId; state2.mSpawn = customData.mSpawn; } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index b8013177a..ce987bebf 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -351,7 +351,7 @@ namespace MWClass state.mHasCustomState = false; return; } - const DoorCustomData& customData = dynamic_cast(*ptr.getRefData().getCustomData()); + const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData(); ESM::DoorState& state2 = dynamic_cast(state); state2.mDoorState = customData.mDoorState; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index fc82b143a..a5f997e1c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1184,7 +1184,7 @@ namespace MWClass return; } - const NpcCustomData& customData = dynamic_cast(*ptr.getRefData().getCustomData()); + const NpcCustomData& customData = ptr.getRefData().getCustomData()->asNpcCustomData(); customData.mInventoryStore.writeState (state2.mInventory); customData.mNpcStats.writeState (state2.mNpcStats); diff --git a/apps/openmw/mwworld/customdata.cpp b/apps/openmw/mwworld/customdata.cpp index 4b3e143f2..a63123bcf 100644 --- a/apps/openmw/mwworld/customdata.cpp +++ b/apps/openmw/mwworld/customdata.cpp @@ -63,5 +63,12 @@ MWClass::CreatureLevListCustomData &CustomData::asCreatureLevListCustomData() throw std::logic_error(error.str()); } +const MWClass::CreatureLevListCustomData &CustomData::asCreatureLevListCustomData() const +{ + std::stringstream error; + error << "bad cast " << typeid(this).name() << " to CreatureLevListCustomData"; + throw std::logic_error(error.str()); +} + } diff --git a/apps/openmw/mwworld/customdata.hpp b/apps/openmw/mwworld/customdata.hpp index 80d706e39..11932e690 100644 --- a/apps/openmw/mwworld/customdata.hpp +++ b/apps/openmw/mwworld/customdata.hpp @@ -35,6 +35,7 @@ namespace MWWorld virtual const MWClass::DoorCustomData& asDoorCustomData() const; virtual MWClass::CreatureLevListCustomData& asCreatureLevListCustomData(); + virtual const MWClass::CreatureLevListCustomData& asCreatureLevListCustomData() const; }; }