mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 20:26:43 +00:00 
			
		
		
		
	Added custom copy-constructor, assignment-operator and destructor for RefData
Prerequisite for the ContainerStore rewrite, which is a prerequisite for issue #117.
This commit is contained in:
		
							parent
							
								
									6a88133178
								
							
						
					
					
						commit
						7439c83623
					
				
					 2 changed files with 71 additions and 1 deletions
				
			
		|  | @ -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…
	
		Reference in a new issue