From 7439c83623d0b6e627654ffc7c6ae802e2c747e8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 22 Jan 2012 11:20:05 +0100 Subject: [PATCH] Added custom copy-constructor, assignment-operator and destructor for RefData Prerequisite for the ContainerStore rewrite, which is a prerequisite for issue #117. --- apps/openmw/mwworld/refdata.cpp | 60 +++++++++++++++++++++++++++++++++ apps/openmw/mwworld/refdata.hpp | 12 ++++++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/refdata.cpp b/apps/openmw/mwworld/refdata.cpp index aed0b5ae0..bb470733c 100644 --- a/apps/openmw/mwworld/refdata.cpp +++ b/apps/openmw/mwworld/refdata.cpp @@ -3,10 +3,70 @@ namespace MWWorld { + void RefData::copy (const RefData& refData) + { + mBaseNode = refData.mBaseNode; + mLocals = refData.mLocals; + mHasLocals = refData.mHasLocals; + mEnabled = refData.mEnabled; + mCount = refData.mCount; + mPosition = refData.mPosition; + + mCreatureStats = refData.mCreatureStats; + mNpcStats = refData.mNpcStats; + mMovement = refData.mMovement; + mContainerStore = refData.mContainerStore; + } + + void RefData::cleanup() + { + mBaseNode = 0; + } + RefData::RefData (const ESMS::CellRef& cellRef) : mBaseNode(0), mHasLocals (false), mEnabled (true), mCount (1), mPosition (cellRef.pos) {} + RefData::RefData (const RefData& refData) + : mBaseNode(0) + { + try + { + copy (refData); + } + catch (...) + { + cleanup(); + throw; + } + } + + RefData::RefData& RefData::operator= (const RefData& refData) + { + try + { + cleanup(); + copy (refData); + } + catch (...) + { + cleanup(); + throw; + } + + return *this; + } + + RefData::~RefData() + { + try + { + cleanup(); + } + catch (...) + {} + } + std::string RefData::getHandle() { return mBaseNode->getName(); diff --git a/apps/openmw/mwworld/refdata.hpp b/apps/openmw/mwworld/refdata.hpp index 7875c2e12..01f70f951 100644 --- a/apps/openmw/mwworld/refdata.hpp +++ b/apps/openmw/mwworld/refdata.hpp @@ -34,6 +34,8 @@ namespace MWWorld bool mEnabled; int mCount; // 0: deleted + ESM::Position mPosition; + // we are using shared pointer here to avoid having to create custom copy-constructor, // assignment operator and destructor. As a consequence though copying a RefData object // manually will probably give unexcepted results. This is not a problem since RefData @@ -44,7 +46,9 @@ namespace MWWorld boost::shared_ptr > mContainerStore; - ESM::Position mPosition; + void copy (const RefData& refData); + + void cleanup(); public: @@ -53,6 +57,12 @@ namespace MWWorld /// to reset the position as the orignal data is still held in the CellRef RefData (const ESMS::CellRef& cellRef); + RefData (const RefData& refData); + + ~RefData(); + + RefData& operator= (const RefData& refData); + /// Return OGRE handle (may be empty). std::string getHandle();