From 43ec933b7ba44186de8b2fd0ffa4f4d89a7cfcec Mon Sep 17 00:00:00 2001 From: cc9cii Date: Tue, 10 Mar 2015 09:45:35 +1100 Subject: [PATCH] Revert to the original clone() method. Create a new copy method for modified records. --- apps/opencs/model/world/record.hpp | 25 +++++++++------------ apps/opencs/model/world/refidcollection.cpp | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/opencs/model/world/record.hpp b/apps/opencs/model/world/record.hpp index 814e116dd..a0ddd8bc8 100644 --- a/apps/opencs/model/world/record.hpp +++ b/apps/opencs/model/world/record.hpp @@ -22,6 +22,8 @@ namespace CSMWorld virtual RecordBase *clone() const = 0; + virtual RecordBase *modifiedCopy() const = 0; + virtual void assign (const RecordBase& record) = 0; ///< Will throw an exception if the types don't match. @@ -38,13 +40,10 @@ namespace CSMWorld ESXRecordT mBase; ESXRecordT mModified; - Record() = default; - Record(const Record&) = default; - Record(State state, - const ESXRecordT *base = 0, const ESXRecordT *modified = 0); - virtual RecordBase *clone() const; + virtual RecordBase *modifiedCopy() const; + virtual void assign (const RecordBase& record); const ESXRecordT& get() const; @@ -64,21 +63,19 @@ namespace CSMWorld }; template - Record::Record(State state, const ESXRecordT *base, const ESXRecordT *modified) + RecordBase *Record::modifiedCopy() const { - if(base) - mBase = *base; - - if(modified) - mModified = *modified; - - this->mState = state; + Record *record = new Record (*this); + record->mModified = record->mBase; + record->mBase = ESXRecordT(); + record->mState = RecordBase::State_ModifiedOnly; + return record; } template RecordBase *Record::clone() const { - return new Record (State_ModifiedOnly, 0, &(this->get())); + return new Record (*this); } template diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 011b5cc0e..14a8890ad 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -470,7 +470,7 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin, const std::string& destination, const CSMWorld::UniversalId::Type type) { - std::auto_ptr newRecord(mData.getRecord(mData.searchId(origin)).clone()); + std::auto_ptr newRecord(mData.getRecord(mData.searchId(origin)).modifiedCopy()); mAdapters.find(type)->second->setId(*newRecord, destination); mData.insertRecord(*newRecord, type, destination); }