Revert to the original clone() method. Create a new copy method for modified records.

celladd
cc9cii 10 years ago
parent 8b3adec3ec
commit 43ec933b7b

@ -22,6 +22,8 @@ namespace CSMWorld
virtual RecordBase *clone() const = 0; virtual RecordBase *clone() const = 0;
virtual RecordBase *modifiedCopy() const = 0;
virtual void assign (const RecordBase& record) = 0; virtual void assign (const RecordBase& record) = 0;
///< Will throw an exception if the types don't match. ///< Will throw an exception if the types don't match.
@ -38,13 +40,10 @@ namespace CSMWorld
ESXRecordT mBase; ESXRecordT mBase;
ESXRecordT mModified; 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 *clone() const;
virtual RecordBase *modifiedCopy() const;
virtual void assign (const RecordBase& record); virtual void assign (const RecordBase& record);
const ESXRecordT& get() const; const ESXRecordT& get() const;
@ -64,21 +63,19 @@ namespace CSMWorld
}; };
template <typename ESXRecordT> template <typename ESXRecordT>
Record<ESXRecordT>::Record(State state, const ESXRecordT *base, const ESXRecordT *modified) RecordBase *Record<ESXRecordT>::modifiedCopy() const
{ {
if(base) Record<ESXRecordT> *record = new Record<ESXRecordT> (*this);
mBase = *base; record->mModified = record->mBase;
record->mBase = ESXRecordT();
if(modified) record->mState = RecordBase::State_ModifiedOnly;
mModified = *modified; return record;
this->mState = state;
} }
template <typename ESXRecordT> template <typename ESXRecordT>
RecordBase *Record<ESXRecordT>::clone() const RecordBase *Record<ESXRecordT>::clone() const
{ {
return new Record<ESXRecordT> (State_ModifiedOnly, 0, &(this->get())); return new Record<ESXRecordT> (*this);
} }
template <typename ESXRecordT> template <typename ESXRecordT>

@ -470,7 +470,7 @@ void CSMWorld::RefIdCollection::cloneRecord(const std::string& origin,
const std::string& destination, const std::string& destination,
const CSMWorld::UniversalId::Type type) const CSMWorld::UniversalId::Type type)
{ {
std::auto_ptr<RecordBase> newRecord(mData.getRecord(mData.searchId(origin)).clone()); std::auto_ptr<RecordBase> newRecord(mData.getRecord(mData.searchId(origin)).modifiedCopy());
mAdapters.find(type)->second->setId(*newRecord, destination); mAdapters.find(type)->second->setId(*newRecord, destination);
mData.insertRecord(*newRecord, type, destination); mData.insertRecord(*newRecord, type, destination);
} }

Loading…
Cancel
Save