#ifndef CSM_WOLRD_RECORD_H #define CSM_WOLRD_RECORD_H #include namespace CSMWorld { template struct Record { enum state { State_BaseOnly, // defined in base only State_Modified, // exists in base, but has been modified State_ModifiedOnly, // newly created in modified State_Deleted // exists in base, but has been deleted }; ESXRecordT mBase; ESXRecordT mModified; state mState; bool isDeleted() const; bool isModified() const; const ESXRecordT& get() const; ///< Throws an exception, if the record is deleted. ESXRecordT& get(); ///< Throws an exception, if the record is deleted. void setModified (const ESXRecordT& modified); }; template bool Record::isDeleted() const { return mState==State_Deleted; } template bool Record::isModified() const { return mState==State_Modified || mState==State_ModifiedOnly; } template const ESXRecordT& Record::get() const { if (isDeleted()) throw std::logic_error ("attempt to access a deleted record"); return mState==State_BaseOnly ? mBase : mModified; } template ESXRecordT& Record::get() { if (isDeleted()) throw std::logic_error ("attempt to access a deleted record"); return mState==State_BaseOnly ? mBase : mModified; } template void Record::setModified (const ESXRecordT& modified) { mModified = modified; if (mState!=State_ModifiedOnly) mState = State_Modified; } } #endif