From 72b129b90e662c10df1d756ea0875197bb517523 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Tue, 22 Jul 2014 17:44:56 +0200 Subject: [PATCH] Code shuffling. Created CastableHelper to store actually usefull function. --- apps/opencs/model/world/nestedadaptors.hpp | 55 +++++++++++++--------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/apps/opencs/model/world/nestedadaptors.hpp b/apps/opencs/model/world/nestedadaptors.hpp index 806dc587d..3807f0219 100644 --- a/apps/opencs/model/world/nestedadaptors.hpp +++ b/apps/opencs/model/world/nestedadaptors.hpp @@ -60,25 +60,47 @@ namespace CSMWorld }; template - class InventoryHelper : public HelperBase + class CastableHelper : public HelperBase + { + + public: + CastableHelper(CSMWorld::UniversalId::Type type) + : HelperBase(type) {} + + protected: + const Record& getRecord(const RefIdData& data, int index) const + { + return dynamic_cast&> ( + data.getRecord (RefIdData::LocalIndex (index, mType))); + } + + Record& getRecord(RefIdData& data, int index) const + { + return dynamic_cast&> ( + data.getRecord (RefIdData::LocalIndex (index, mType))); + } + }; + + template + class InventoryHelper : public CastableHelper { public: InventoryHelper(CSMWorld::UniversalId::Type type) - : HelperBase(type) {} + : CastableHelper(type) {} virtual void setNestedTable(RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) { - getRecord(data, index).get().mInventory.mList = + CastableHelper::getRecord(data, index).get().mInventory.mList = (static_cast >&>(nestedTable)).mNestedTable; } virtual NestedTableWrapperBase* nestedTable(const RefIdData& data, int index) const { - return new NestedTableWrapper >(getRecord(data, index).get().mInventory.mList); + return new NestedTableWrapper >(CastableHelper::getRecord(data, index).get().mInventory.mList); } virtual QVariant getNestedData(const CSMWorld::RefIdData& data, @@ -86,7 +108,7 @@ namespace CSMWorld int subRowIndex, int subColIndex) const { - const ESM::ContItem& content = getRecord(data, index).get().mInventory.mList.at(subRowIndex); + const ESM::ContItem& content = CastableHelper::getRecord(data, index).get().mInventory.mList.at(subRowIndex); switch (subColIndex) { @@ -103,7 +125,7 @@ namespace CSMWorld virtual void removeNestedRow (RefIdData& data, int index, int rowToRemove) const { - std::vector& list = getRecord(data, index).get().mInventory.mList; + std::vector& list = CastableHelper::getRecord(data, index).get().mInventory.mList; list.erase (list.begin () + rowToRemove); } @@ -117,11 +139,11 @@ namespace CSMWorld switch(subColIndex) { case 0: - getRecord(data, index).get().mInventory.mList.at(subRowIndex).mItem.assign(std::string(value.toString().toUtf8().constData())); + CastableHelper::getRecord(data, index).get().mInventory.mList.at(subRowIndex).mItem.assign(std::string(value.toString().toUtf8().constData())); break; case 1: - getRecord(data, index).get().mInventory.mList.at(subRowIndex).mCount = value.toInt(); + CastableHelper::getRecord(data, index).get().mInventory.mList.at(subRowIndex).mCount = value.toInt(); break; default: @@ -131,7 +153,7 @@ namespace CSMWorld virtual void addNestedRow (RefIdData& data, int index, int position) const { - std::vector& list = getRecord(data, index).get().mInventory.mList; + std::vector& list = CastableHelper::getRecord(data, index).get().mInventory.mList; ESM::ContItem newRow = {0, ""}; if (position >= (int)list.size()) @@ -152,22 +174,9 @@ namespace CSMWorld virtual int getNestedRowsCount(const RefIdData& data, int index) const { - return getRecord(data, index).get().mInventory.mList.size(); + return CastableHelper::getRecord(data, index).get().mInventory.mList.size(); } - private: - - const Record& getRecord(const RefIdData& data, int index) const - { - return dynamic_cast&> ( - data.getRecord (RefIdData::LocalIndex (index, mType))); - } - - Record& getRecord(RefIdData& data, int index) const - { - return dynamic_cast&> ( - data.getRecord (RefIdData::LocalIndex (index, mType))); - } }; }