diff --git a/apps/opencs/model/world/idadapterimp.hpp b/apps/opencs/model/world/idadapterimp.hpp index 2ce0777ac..7df653059 100644 --- a/apps/opencs/model/world/idadapterimp.hpp +++ b/apps/opencs/model/world/idadapterimp.hpp @@ -6,11 +6,10 @@ #include #include "idadapter.hpp" +#include "nestedtablewrapper.hpp" namespace CSMWorld { - struct NestedTableWrapperBase; - template class PathgridPointListAdapter : public NestedIdAdapter { diff --git a/apps/opencs/model/world/nestedidcollection.hpp b/apps/opencs/model/world/nestedidcollection.hpp new file mode 100644 index 000000000..c7e840955 --- /dev/null +++ b/apps/opencs/model/world/nestedidcollection.hpp @@ -0,0 +1,172 @@ +#ifndef CSM_WOLRD_NESTEDIDCOLLECTION_H +#define CSM_WOLRD_NESTEDIDCOLLECTION_H + +#include +#include + +#include "nestedcollection.hpp" +#include "idadapterimp.hpp" + +namespace ESM +{ + class ESMReader; +} + +namespace CSMWorld +{ + struct NestedTableWrapperBase; + struct Cell; + + template + class IdCollection; + + template > + class NestedIdCollection : public IdCollection, public NestedCollection + { + std::map* > mAdapters; + + const NestedIdAdapter& getAdapter(const ColumnBase &column) const; + + public: + + NestedIdCollection (); + ~NestedIdCollection(); + + virtual void addNestedRow(int row, int column, int position); + + virtual void removeNestedRows(int row, int column, int subRow); + + virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const; + + virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn); + + virtual NestedTableWrapperBase* nestedTable(int row, int column) const; + + virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable); + + virtual int getNestedRowsCount(int row, int column) const; + + virtual int getNestedColumnsCount(int row, int column) const; + + // this method is inherited from NestedCollection, not from Collection + virtual NestableColumn *getNestableColumn(int column); + + void addAdapter(std::pair* > adapter); + }; + + template + NestedIdCollection::NestedIdCollection () + {} + + template + NestedIdCollection::~NestedIdCollection() + { + for (typename std::map* >::iterator iter (mAdapters.begin()); + iter!=mAdapters.end(); ++iter) + delete (*iter).second; + } + + template + void NestedIdCollection::addAdapter(std::pair* > adapter) + { + mAdapters.insert(adapter); + } + + template + const NestedIdAdapter& NestedIdCollection::getAdapter(const ColumnBase &column) const + { + typename std::map* >::const_iterator iter = + mAdapters.find (&column); + + if (iter==mAdapters.end()) + throw std::logic_error("No such column in the nestedidadapter"); + + return *iter->second; + } + + template + void NestedIdCollection::addNestedRow(int row, int column, int position) + { + Record record; + record.assign(Collection::getRecord(row)); + + getAdapter(Collection::getColumn(column)).addNestedRow(record, position); + + Collection::setRecord(row, record); + } + + template + void NestedIdCollection::removeNestedRows(int row, int column, int subRow) + { + Record record; + record.assign(Collection::getRecord(row)); + + getAdapter(Collection::getColumn(column)).removeNestedRow(record, subRow); + + Collection::setRecord(row, record); + } + + template + QVariant NestedIdCollection::getNestedData (int row, + int column, int subRow, int subColumn) const + { + return getAdapter(Collection::getColumn(column)).getNestedData( + Collection::getRecord(row), subRow, subColumn); + } + + template + void NestedIdCollection::setNestedData(int row, + int column, const QVariant& data, int subRow, int subColumn) + { + Record record; + record.assign(Collection::getRecord(row)); + + getAdapter(Collection::getColumn(column)).setNestedData( + record, data, subRow, subColumn); + + Collection::setRecord(row, record); + } + + template + CSMWorld::NestedTableWrapperBase* NestedIdCollection::nestedTable(int row, + int column) const + { + return getAdapter(Collection::getColumn(column)).nestedTable( + Collection::getRecord(row)); + } + + template + void NestedIdCollection::setNestedTable(int row, + int column, const CSMWorld::NestedTableWrapperBase& nestedTable) + { + Record record; + record.assign(Collection::getRecord(row)); + + getAdapter(Collection::getColumn(column)).setNestedTable( + record, nestedTable); + + Collection::setRecord(row, record); + } + + template + int NestedIdCollection::getNestedRowsCount(int row, int column) const + { + return getAdapter(Collection::getColumn(column)).getNestedRowsCount( + Collection::getRecord(row)); + } + + template + int NestedIdCollection::getNestedColumnsCount(int row, int column) const + { + return getAdapter(Collection::getColumn(column)).getNestedColumnsCount( + Collection::getRecord(row)); + } + + template + CSMWorld::NestableColumn *NestedIdCollection::getNestableColumn(int column) + { + return Collection::getNestableColumn(column); + } +} + +#endif // CSM_WOLRD_NESTEDIDCOLLECTION_H diff --git a/apps/opencs/model/world/subcellcollection.hpp b/apps/opencs/model/world/subcellcollection.hpp index c53c7006a..df1f8a12e 100644 --- a/apps/opencs/model/world/subcellcollection.hpp +++ b/apps/opencs/model/world/subcellcollection.hpp @@ -1,16 +1,7 @@ #ifndef CSM_WOLRD_SUBCOLLECTION_H #define CSM_WOLRD_SUBCOLLECTION_H -#include -#include - -#include - -#include "columnimp.hpp" -#include "idcollection.hpp" -#include "nestedcollection.hpp" -#include "nestedtablewrapper.hpp" -#include "idadapterimp.hpp" +#include "nestedidcollection.hpp" namespace ESM { @@ -25,40 +16,15 @@ namespace CSMWorld /// \brief Single type collection of top level records that are associated with cells template > - class SubCellCollection : public IdCollection, public NestedCollection + class SubCellCollection : public NestedIdCollection { const IdCollection& mCells; - std::map* > mAdapters; virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader); - const NestedIdAdapter& getAdapter(const ColumnBase &column) const; - public: SubCellCollection (const IdCollection& cells); - ~SubCellCollection(); - - virtual void addNestedRow(int row, int column, int position); - - virtual void removeNestedRows(int row, int column, int subRow); - - virtual QVariant getNestedData(int row, int column, int subRow, int subColumn) const; - - virtual void setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn); - - virtual NestedTableWrapperBase* nestedTable(int row, int column) const; - - virtual void setNestedTable(int row, int column, const NestedTableWrapperBase& nestedTable); - - virtual int getNestedRowsCount(int row, int column) const; - - virtual int getNestedColumnsCount(int row, int column) const; - - // this method is inherited from NestedCollection, not from Collection - virtual NestableColumn *getNestableColumn(int column); - - void addAdapter(std::pair* > adapter); }; template @@ -69,119 +35,10 @@ namespace CSMWorld } template - SubCellCollection::SubCellCollection (const IdCollection& cells) + SubCellCollection::SubCellCollection ( + const IdCollection& cells) : mCells (cells) {} - - template - SubCellCollection::~SubCellCollection() - { - for (typename std::map* >::iterator iter (mAdapters.begin()); - iter!=mAdapters.end(); ++iter) - delete (*iter).second; - } - - template - void SubCellCollection::addAdapter(std::pair* > adapter) - { - mAdapters.insert(adapter); - } - - template - const NestedIdAdapter& SubCellCollection::getAdapter(const ColumnBase &column) const - { - typename std::map* >::const_iterator iter = - mAdapters.find (&column); - - if (iter==mAdapters.end()) - throw std::logic_error("No such column in the nestedidadapter"); - - return *iter->second; - } - - template - void SubCellCollection::addNestedRow(int row, int column, int position) - { - Record record; - record.assign(Collection::getRecord(row)); - - getAdapter(Collection::getColumn(column)).addNestedRow(record, position); - - Collection::setRecord(row, record); - } - - template - void SubCellCollection::removeNestedRows(int row, int column, int subRow) - { - Record record; - record.assign(Collection::getRecord(row)); - - getAdapter(Collection::getColumn(column)).removeNestedRow(record, subRow); - - Collection::setRecord(row, record); - } - - template - QVariant SubCellCollection::getNestedData (int row, - int column, int subRow, int subColumn) const - { - return getAdapter(Collection::getColumn(column)).getNestedData( - Collection::getRecord(row), subRow, subColumn); - } - - template - void SubCellCollection::setNestedData(int row, - int column, const QVariant& data, int subRow, int subColumn) - { - Record record; - record.assign(Collection::getRecord(row)); - - getAdapter(Collection::getColumn(column)).setNestedData( - record, data, subRow, subColumn); - - Collection::setRecord(row, record); - } - - template - CSMWorld::NestedTableWrapperBase* SubCellCollection::nestedTable(int row, - int column) const - { - return getAdapter(Collection::getColumn(column)).nestedTable( - Collection::getRecord(row)); - } - - template - void SubCellCollection::setNestedTable(int row, - int column, const CSMWorld::NestedTableWrapperBase& nestedTable) - { - Record record; - record.assign(Collection::getRecord(row)); - - getAdapter(Collection::getColumn(column)).setNestedTable( - record, nestedTable); - - Collection::setRecord(row, record); - } - - template - int SubCellCollection::getNestedRowsCount(int row, int column) const - { - return getAdapter(Collection::getColumn(column)).getNestedRowsCount( - Collection::getRecord(row)); - } - - template - int SubCellCollection::getNestedColumnsCount(int row, int column) const - { - return getAdapter(Collection::getColumn(column)).getNestedColumnsCount( - Collection::getRecord(row)); - } - - template - CSMWorld::NestableColumn *SubCellCollection::getNestableColumn(int column) - { - return Collection::getNestableColumn(column); - } } #endif