Added custom copy-constructor, assignment-operator and destructor for RefData

Prerequisite for the ContainerStore rewrite, which is a prerequisite for issue #117.
actorid
Marc Zinnschlag 13 years ago
parent 6a88133178
commit 7439c83623

@ -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();

@ -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<ContainerStore<RefData> > 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();

Loading…
Cancel
Save