Improve const-correctness in writeAdditionalState

This commit is contained in:
scrawl 2015-12-18 00:18:06 +01:00
parent b48445dea7
commit ed3486e816
19 changed files with 33 additions and 32 deletions

View file

@ -313,7 +313,7 @@ namespace MWClass
readState (state2.mInventory); readState (state2.mInventory);
} }
void Container::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) const void Container::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const
{ {
ESM::ContainerState& state2 = dynamic_cast<ESM::ContainerState&> (state); ESM::ContainerState& state2 = dynamic_cast<ESM::ContainerState&> (state);
@ -323,7 +323,7 @@ namespace MWClass
return; return;
} }
dynamic_cast<ContainerCustomData&> (*ptr.getRefData().getCustomData()).mContainerStore. dynamic_cast<const ContainerCustomData&> (*ptr.getRefData().getCustomData()).mContainerStore.
writeState (state2.mInventory); writeState (state2.mInventory);
} }
} }

View file

@ -63,7 +63,7 @@ namespace MWClass
const; const;
///< Read additional state from \a state into \a ptr. ///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const; const;
///< Write additional state from \a ptr into \a state. ///< Write additional state from \a ptr into \a state.

View file

@ -724,7 +724,7 @@ namespace MWClass
customData.mCreatureStats.readState (state2.mCreatureStats); customData.mCreatureStats.readState (state2.mCreatureStats);
} }
void Creature::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) void Creature::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const const
{ {
ESM::CreatureState& state2 = dynamic_cast<ESM::CreatureState&> (state); ESM::CreatureState& state2 = dynamic_cast<ESM::CreatureState&> (state);
@ -735,7 +735,7 @@ namespace MWClass
return; return;
} }
CreatureCustomData& customData = ptr.getRefData().getCustomData()->asCreatureCustomData(); const CreatureCustomData& customData = dynamic_cast<const CreatureCustomData&>(*ptr.getRefData().getCustomData());
customData.mContainerStore->writeState (state2.mInventory); customData.mContainerStore->writeState (state2.mInventory);
customData.mCreatureStats.writeState (state2.mCreatureStats); customData.mCreatureStats.writeState (state2.mCreatureStats);

View file

@ -117,12 +117,10 @@ namespace MWClass
/// Get a blood texture suitable for \a ptr (see Blood Texture 0-2 in Morrowind.ini) /// Get a blood texture suitable for \a ptr (see Blood Texture 0-2 in Morrowind.ini)
virtual int getBloodTexture (const MWWorld::Ptr& ptr) const; virtual int getBloodTexture (const MWWorld::Ptr& ptr) const;
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const;
const;
///< Read additional state from \a state into \a ptr. ///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const;
const;
///< Write additional state from \a ptr into \a state. ///< Write additional state from \a ptr into \a state.
virtual int getBaseGold(const MWWorld::Ptr& ptr) const; virtual int getBaseGold(const MWWorld::Ptr& ptr) const;

View file

@ -115,7 +115,7 @@ namespace MWClass
customData.mSpawn = state2.mSpawn; customData.mSpawn = state2.mSpawn;
} }
void CreatureLevList::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) void CreatureLevList::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const const
{ {
ESM::CreatureLevListState& state2 = dynamic_cast<ESM::CreatureLevListState&> (state); ESM::CreatureLevListState& state2 = dynamic_cast<ESM::CreatureLevListState&> (state);
@ -126,7 +126,7 @@ namespace MWClass
return; return;
} }
CreatureLevListCustomData& customData = ptr.getRefData().getCustomData()->asCreatureLevListCustomData(); const CreatureLevListCustomData& customData = dynamic_cast<const CreatureLevListCustomData&>(*ptr.getRefData().getCustomData());
state2.mSpawnActorId = customData.mSpawnActorId; state2.mSpawnActorId = customData.mSpawnActorId;
state2.mSpawn = customData.mSpawn; state2.mSpawn = customData.mSpawn;
} }

View file

@ -23,12 +23,10 @@ namespace MWClass
virtual void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const; virtual void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const;
///< Add reference into a cell for rendering ///< Add reference into a cell for rendering
virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) virtual void readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const;
const;
///< Read additional state from \a state into \a ptr. ///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const;
const;
///< Write additional state from \a ptr into \a state. ///< Write additional state from \a ptr into \a state.
virtual void respawn (const MWWorld::Ptr& ptr) const; virtual void respawn (const MWWorld::Ptr& ptr) const;

View file

@ -351,14 +351,14 @@ namespace MWClass
customData.mDoorState = state2.mDoorState; customData.mDoorState = state2.mDoorState;
} }
void Door::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) const void Door::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const
{ {
if (!ptr.getRefData().getCustomData()) if (!ptr.getRefData().getCustomData())
{ {
state.mHasCustomState = false; state.mHasCustomState = false;
return; return;
} }
const DoorCustomData& customData = ptr.getRefData().getCustomData()->asDoorCustomData(); const DoorCustomData& customData = dynamic_cast<const DoorCustomData&>(*ptr.getRefData().getCustomData());
ESM::DoorState& state2 = dynamic_cast<ESM::DoorState&>(state); ESM::DoorState& state2 = dynamic_cast<ESM::DoorState&>(state);
state2.mDoorState = customData.mDoorState; state2.mDoorState = customData.mDoorState;

View file

@ -66,7 +66,7 @@ namespace MWClass
const; const;
///< Read additional state from \a state into \a ptr. ///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const; const;
///< Write additional state from \a ptr into \a state. ///< Write additional state from \a ptr into \a state.
}; };

View file

@ -1175,7 +1175,7 @@ namespace MWClass
static_cast<MWMechanics::CreatureStats&> (customData.mNpcStats).readState (state2.mCreatureStats); static_cast<MWMechanics::CreatureStats&> (customData.mNpcStats).readState (state2.mCreatureStats);
} }
void Npc::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) void Npc::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const const
{ {
ESM::NpcState& state2 = dynamic_cast<ESM::NpcState&> (state); ESM::NpcState& state2 = dynamic_cast<ESM::NpcState&> (state);
@ -1186,7 +1186,7 @@ namespace MWClass
return; return;
} }
NpcCustomData& customData = ptr.getRefData().getCustomData()->asNpcCustomData(); const NpcCustomData& customData = dynamic_cast<const NpcCustomData&>(*ptr.getRefData().getCustomData());
customData.mInventoryStore.writeState (state2.mInventory); customData.mInventoryStore.writeState (state2.mInventory);
customData.mNpcStats.writeState (state2.mNpcStats); customData.mNpcStats.writeState (state2.mNpcStats);

View file

@ -145,7 +145,7 @@ namespace MWClass
const; const;
///< Read additional state from \a state into \a ptr. ///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const; const;
///< Write additional state from \a ptr into \a state. ///< Write additional state from \a ptr into \a state.

View file

@ -397,7 +397,7 @@ namespace MWWorld
void Class::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const {} void Class::readAdditionalState (const MWWorld::Ptr& ptr, const ESM::ObjectState& state) const {}
void Class::writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) const {} void Class::writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state) const {}
int Class::getBaseGold(const MWWorld::Ptr& ptr) const int Class::getBaseGold(const MWWorld::Ptr& ptr) const
{ {

View file

@ -313,7 +313,7 @@ namespace MWWorld
const; const;
///< Read additional state from \a state into \a ptr. ///< Read additional state from \a state into \a ptr.
virtual void writeAdditionalState (const MWWorld::Ptr& ptr, ESM::ObjectState& state) virtual void writeAdditionalState (const MWWorld::ConstPtr& ptr, ESM::ObjectState& state)
const; const;
///< Write additional state from \a ptr into \a state. ///< Write additional state from \a ptr into \a state.

View file

@ -94,7 +94,7 @@ void MWWorld::ContainerStore::storeState (const LiveCellRef<T>& ref, ESM::Object
} }
template<typename T> template<typename T>
void MWWorld::ContainerStore::storeStates (CellRefList<T>& collection, void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
ESM::InventoryState& inventory, int& index, bool equipable) const ESM::InventoryState& inventory, int& index, bool equipable) const
{ {
for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin()); for (typename CellRefList<T>::List::const_iterator iter (collection.mList.begin());
@ -707,7 +707,7 @@ MWWorld::Ptr MWWorld::ContainerStore::search (const std::string& id)
return Ptr(); return Ptr();
} }
void MWWorld::ContainerStore::writeState (ESM::InventoryState& state) void MWWorld::ContainerStore::writeState (ESM::InventoryState& state) const
{ {
state.mItems.clear(); state.mItems.clear();

View file

@ -86,7 +86,7 @@ namespace MWWorld
void storeState (const LiveCellRef<T>& ref, ESM::ObjectState& state) const; void storeState (const LiveCellRef<T>& ref, ESM::ObjectState& state) const;
template<typename T> template<typename T>
void storeStates (CellRefList<T>& collection, void storeStates (const CellRefList<T>& collection,
ESM::InventoryState& inventory, int& index, ESM::InventoryState& inventory, int& index,
bool equipable = false) const; bool equipable = false) const;
@ -169,8 +169,7 @@ namespace MWWorld
Ptr search (const std::string& id); Ptr search (const std::string& id);
/// \todo make this method const once const-correct ContainerStoreIterators are available virtual void writeState (ESM::InventoryState& state) const;
virtual void writeState (ESM::InventoryState& state);
virtual void readState (const ESM::InventoryState& state); virtual void readState (const ESM::InventoryState& state);

View file

@ -752,7 +752,7 @@ bool MWWorld::InventoryStore::isEquipped(const MWWorld::Ptr &item)
return false; return false;
} }
void MWWorld::InventoryStore::writeState(ESM::InventoryState &state) void MWWorld::InventoryStore::writeState(ESM::InventoryState &state) const
{ {
MWWorld::ContainerStore::writeState(state); MWWorld::ContainerStore::writeState(state);

View file

@ -207,7 +207,7 @@ namespace MWWorld
virtual void clear(); virtual void clear();
///< Empty container. ///< Empty container.
virtual void writeState (ESM::InventoryState& state); virtual void writeState (ESM::InventoryState& state) const;
virtual void readState (const ESM::InventoryState& state); virtual void readState (const ESM::InventoryState& state);
}; };

View file

@ -54,8 +54,7 @@ void MWWorld::LiveCellRefBase::saveImp (ESM::ObjectState& state) const
{ {
mRef.writeState(state); mRef.writeState(state);
/// \todo get rid of this cast once const-correct Ptr are available ConstPtr ptr (this);
Ptr ptr (const_cast<LiveCellRefBase *> (this));
mData.write (state, mClass->getScript (ptr)); mData.write (state, mClass->getScript (ptr));

View file

@ -205,6 +205,11 @@ namespace MWWorld
return mCustomData; return mCustomData;
} }
const CustomData *RefData::getCustomData() const
{
return mCustomData;
}
bool RefData::hasChanged() const bool RefData::hasChanged() const
{ {
return mChanged; return mChanged;

View file

@ -116,6 +116,8 @@ namespace MWWorld
CustomData *getCustomData(); CustomData *getCustomData();
///< May return a 0-pointer. The ownership of the return data object is not transferred. ///< May return a 0-pointer. The ownership of the return data object is not transferred.
const CustomData *getCustomData() const;
bool hasChanged() const; bool hasChanged() const;
///< Has this RefData changed since it was originally loaded? ///< Has this RefData changed since it was originally loaded?
}; };