From 4b2d920f9d65a32bba03538e3dcbf11e747fcf23 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 17 Jun 2013 13:49:32 +0200 Subject: [PATCH] rewrote IdCollection::load (not using private members of IdCollection anymore) --- apps/opencs/model/world/idcollection.hpp | 68 +++++++++++++++--------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 158c4ccfc3..01a98f810e 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -106,14 +106,18 @@ namespace CSMWorld virtual const Record& getRecord (int index) const; - virtual void load (ESM::ESMReader& reader, bool base, - UniversalId::Type type = UniversalId::Type_None); - ///< \param type Will be ignored, unless the collection supports multiple record types - virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const; ///< \param type Will be ignored, unless the collection supports multiple record types void addColumn (Column *column); + + void setRecord (int index, const Record& record); + ///< \attention This function must not change the ID. + + void load (ESM::ESMReader& reader, bool base, + UniversalId::Type type = UniversalId::Type_None); + ///< \param type Will be ignored, unless the collection supports multiple record types + }; template @@ -289,6 +293,34 @@ namespace CSMWorld mRecords.size()-1)); } + template + int IdCollection::getAppendIndex (UniversalId::Type type) const + { + return static_cast (mRecords.size()); + } + + template + const Record& IdCollection::getRecord (const std::string& id) const + { + int index = getIndex (id); + return mRecords.at (index); + } + + template + const Record& IdCollection::getRecord (int index) const + { + return mRecords.at (index); + } + + template + void IdCollection::setRecord (int index, const Record& record) + { + if (IdAccessorT().getId (mRecords.at (index).get())!=IdAccessorT().getId (record.get())) + throw std::runtime_error ("attempt to change the ID of a record"); + + mRecords.at (index) = record; + } + template void IdCollection::load (ESM::ESMReader& reader, bool base, UniversalId::Type type) @@ -315,7 +347,9 @@ namespace CSMWorld } else { - mRecords[index].mState = RecordBase::State_Deleted; + Record record = getRecord (index); + record.mState = RecordBase::State_Deleted; + setRecord (index, record); } } else @@ -338,35 +372,17 @@ namespace CSMWorld else { // old record - Record& record2 = mRecords[index]; + Record record2 = getRecord (index); if (base) record2.mBase = record; else record2.setModified (record); + + setRecord (index, record2); } } } - - template - int IdCollection::getAppendIndex (UniversalId::Type type) const - { - return static_cast (mRecords.size()); - } - - template - const Record& IdCollection::getRecord (const std::string& id) const - { - int index = getIndex (id); - return mRecords.at (index); - } - - template - const Record& IdCollection::getRecord (int index) const - { - return mRecords.at (index); - } - } #endif