diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index 01a98f810e..3ba26193a5 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -41,23 +41,23 @@ namespace CSMWorld return record.mId; } - ///< \brief Collection of ID-based records + /// \brief Single-type record collection template > - class IdCollection : public CollectionBase + class Collection : public CollectionBase { std::vector > mRecords; std::map mIndex; std::vector *> mColumns; // not implemented - IdCollection (const IdCollection&); - IdCollection& operator= (const IdCollection&); + Collection (const Collection&); + Collection& operator= (const Collection&); public: - IdCollection(); + Collection(); - virtual ~IdCollection(); + virtual ~Collection(); void add (const ESXRecordT& record); ///< Add a new record (modified) @@ -113,26 +113,21 @@ namespace CSMWorld 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 - IdCollection::IdCollection() + Collection::Collection() {} template - IdCollection::~IdCollection() + Collection::~Collection() { for (typename std::vector *>::iterator iter (mColumns.begin()); iter!=mColumns.end(); ++iter) delete *iter; } template - void IdCollection::add (const ESXRecordT& record) + void Collection::add (const ESXRecordT& record) { std::string id = Misc::StringUtils::lowerCase (IdAccessorT().getId (record)); @@ -154,19 +149,19 @@ namespace CSMWorld } template - int IdCollection::getSize() const + int Collection::getSize() const { return mRecords.size(); } template - std::string IdCollection::getId (int index) const + std::string Collection::getId (int index) const { return IdAccessorT().getId (mRecords.at (index).get()); } template - int IdCollection::getIndex (const std::string& id) const + int Collection::getIndex (const std::string& id) const { int index = searchId (id); @@ -177,37 +172,37 @@ namespace CSMWorld } template - int IdCollection::getColumns() const + int Collection::getColumns() const { return mColumns.size(); } template - QVariant IdCollection::getData (int index, int column) const + QVariant Collection::getData (int index, int column) const { return mColumns.at (column)->get (mRecords.at (index)); } template - void IdCollection::setData (int index, int column, const QVariant& data) + void Collection::setData (int index, int column, const QVariant& data) { return mColumns.at (column)->set (mRecords.at (index), data); } template - const ColumnBase& IdCollection::getColumn (int column) const + const ColumnBase& Collection::getColumn (int column) const { return *mColumns.at (column); } template - void IdCollection::addColumn (Column *column) + void Collection::addColumn (Column *column) { mColumns.push_back (column); } template - void IdCollection::merge() + void Collection::merge() { for (typename std::vector >::iterator iter (mRecords.begin()); iter!=mRecords.end(); ++iter) iter->merge(); @@ -216,7 +211,7 @@ namespace CSMWorld } template - void IdCollection::purge() + void Collection::purge() { int i = 0; @@ -230,7 +225,7 @@ namespace CSMWorld } template - void IdCollection::removeRows (int index, int count) + void Collection::removeRows (int index, int count) { mRecords.erase (mRecords.begin()+index, mRecords.begin()+index+count); @@ -255,7 +250,7 @@ namespace CSMWorld } template - void IdCollection::appendBlankRecord (const std::string& id, + void Collection::appendBlankRecord (const std::string& id, UniversalId::Type type) { ESXRecordT record; @@ -265,7 +260,7 @@ namespace CSMWorld } template - int IdCollection::searchId (const std::string& id) const + int Collection::searchId (const std::string& id) const { std::string id2 = Misc::StringUtils::lowerCase(id); @@ -278,13 +273,13 @@ namespace CSMWorld } template - void IdCollection::replace (int index, const RecordBase& record) + void Collection::replace (int index, const RecordBase& record) { mRecords.at (index) = dynamic_cast&> (record); } template - void IdCollection::appendRecord (const RecordBase& record, + void Collection::appendRecord (const RecordBase& record, UniversalId::Type type) { mRecords.push_back (dynamic_cast&> (record)); @@ -294,26 +289,26 @@ namespace CSMWorld } template - int IdCollection::getAppendIndex (UniversalId::Type type) const + int Collection::getAppendIndex (UniversalId::Type type) const { return static_cast (mRecords.size()); } template - const Record& IdCollection::getRecord (const std::string& id) const + const Record& Collection::getRecord (const std::string& id) const { int index = getIndex (id); return mRecords.at (index); } template - const Record& IdCollection::getRecord (int index) const + const Record& Collection::getRecord (int index) const { return mRecords.at (index); } template - void IdCollection::setRecord (int index, const Record& record) + void Collection::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"); @@ -321,6 +316,17 @@ namespace CSMWorld mRecords.at (index) = record; } + /// \brief Single type collection of top level records + template > + class IdCollection : public Collection + { + public: + + 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 void IdCollection::load (ESM::ESMReader& reader, bool base, UniversalId::Type type) @@ -329,7 +335,7 @@ namespace CSMWorld if (reader.isNextSub ("DELE")) { - int index = searchId (id); + int index = Collection::searchId (id); reader.skipRecord(); @@ -343,11 +349,11 @@ namespace CSMWorld } else if (base) { - removeRows (index, 1); + Collection::removeRows (index, 1); } else { - Record record = getRecord (index); + Record record = Collection::getRecord (index); record.mState = RecordBase::State_Deleted; setRecord (index, record); } @@ -372,7 +378,7 @@ namespace CSMWorld else { // old record - Record record2 = getRecord (index); + Record record2 = Collection::getRecord (index); if (base) record2.mBase = record;