Implement clone() using a new Record constructor.

This commit is contained in:
cc9cii 2015-03-09 14:58:07 +11:00
parent 128371c902
commit 6087a18c94
2 changed files with 17 additions and 4 deletions

View file

@ -38,6 +38,10 @@ namespace CSMWorld
ESXRecordT mBase;
ESXRecordT mModified;
Record() {}
Record(State state,
const ESXRecordT *base = 0, const ESXRecordT *modified = 0);
virtual RecordBase *clone() const;
virtual void assign (const RecordBase& record);
@ -58,12 +62,22 @@ namespace CSMWorld
///< Merge modified into base.
};
template <typename ESXRecordT>
Record<ESXRecordT>::Record(State state, const ESXRecordT *base = 0, const ESXRecordT *modified = 0)
{
if(base)
mBase = *base;
if(modified)
mModified = *modified;
this->mState = state;
}
template <typename ESXRecordT>
RecordBase *Record<ESXRecordT>::clone() const
{
Record<ESXRecordT> *copy = new Record<ESXRecordT> (*this);
copy->mModified = (*this).get();
return copy;
return new Record<ESXRecordT> (State_ModifiedOnly, 0, &(this->get()));
}
template <typename ESXRecordT>

View file

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