Code reorganisation to prepare for nested sound table in regions.

test
cc9cii 10 years ago
parent ce7e2e06c1
commit 5da2f53bec

@ -6,11 +6,10 @@
#include <components/esm/loadpgrd.hpp>
#include "idadapter.hpp"
#include "nestedtablewrapper.hpp"
namespace CSMWorld
{
struct NestedTableWrapperBase;
template<typename ESXRecordT>
class PathgridPointListAdapter : public NestedIdAdapter<ESXRecordT>
{

@ -0,0 +1,172 @@
#ifndef CSM_WOLRD_NESTEDIDCOLLECTION_H
#define CSM_WOLRD_NESTEDIDCOLLECTION_H
#include <map>
#include <stdexcept>
#include "nestedcollection.hpp"
#include "idadapterimp.hpp"
namespace ESM
{
class ESMReader;
}
namespace CSMWorld
{
struct NestedTableWrapperBase;
struct Cell;
template<typename T, typename AT>
class IdCollection;
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class NestedIdCollection : public IdCollection<ESXRecordT, IdAccessorT>, public NestedCollection
{
std::map<const ColumnBase*, NestedIdAdapter<ESXRecordT>* > mAdapters;
const NestedIdAdapter<ESXRecordT>& 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<ESXRecordT>
virtual NestableColumn *getNestableColumn(int column);
void addAdapter(std::pair<const ColumnBase*, NestedIdAdapter<ESXRecordT>* > adapter);
};
template<typename ESXRecordT, typename IdAccessorT>
NestedIdCollection<ESXRecordT, IdAccessorT>::NestedIdCollection ()
{}
template<typename ESXRecordT, typename IdAccessorT>
NestedIdCollection<ESXRecordT, IdAccessorT>::~NestedIdCollection()
{
for (typename std::map<const ColumnBase *, NestedIdAdapter<ESXRecordT>* >::iterator iter (mAdapters.begin());
iter!=mAdapters.end(); ++iter)
delete (*iter).second;
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::addAdapter(std::pair<const ColumnBase*, NestedIdAdapter<ESXRecordT>* > adapter)
{
mAdapters.insert(adapter);
}
template<typename ESXRecordT, typename IdAccessorT>
const NestedIdAdapter<ESXRecordT>& NestedIdCollection<ESXRecordT, IdAccessorT>::getAdapter(const ColumnBase &column) const
{
typename std::map<const ColumnBase *, NestedIdAdapter<ESXRecordT>* >::const_iterator iter =
mAdapters.find (&column);
if (iter==mAdapters.end())
throw std::logic_error("No such column in the nestedidadapter");
return *iter->second;
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::addNestedRow(int row, int column, int position)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).addNestedRow(record, position);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::removeNestedRows(int row, int column, int subRow)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).removeNestedRow(record, subRow);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
QVariant NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedData (int row,
int column, int subRow, int subColumn) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedData(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow, subColumn);
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedData(int row,
int column, const QVariant& data, int subRow, int subColumn)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setNestedData(
record, data, subRow, subColumn);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestedTableWrapperBase* NestedIdCollection<ESXRecordT, IdAccessorT>::nestedTable(int row,
int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).nestedTable(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedTable(int row,
int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setNestedTable(
record, nestedTable);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedRowsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedColumnsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestableColumn *NestedIdCollection<ESXRecordT, IdAccessorT>::getNestableColumn(int column)
{
return Collection<ESXRecordT, IdAccessorT>::getNestableColumn(column);
}
}
#endif // CSM_WOLRD_NESTEDIDCOLLECTION_H

@ -1,16 +1,7 @@
#ifndef CSM_WOLRD_SUBCOLLECTION_H
#define CSM_WOLRD_SUBCOLLECTION_H
#include <map>
#include <stdexcept>
#include <components/esm/loadpgrd.hpp>
#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<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class SubCellCollection : public IdCollection<ESXRecordT, IdAccessorT>, public NestedCollection
class SubCellCollection : public NestedIdCollection<ESXRecordT, IdAccessorT>
{
const IdCollection<Cell>& mCells;
std::map<const ColumnBase*, NestedIdAdapter<ESXRecordT>* > mAdapters;
virtual void loadRecord (ESXRecordT& record, ESM::ESMReader& reader);
const NestedIdAdapter<ESXRecordT>& getAdapter(const ColumnBase &column) const;
public:
SubCellCollection (const IdCollection<Cell>& 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<ESXRecordT>
virtual NestableColumn *getNestableColumn(int column);
void addAdapter(std::pair<const ColumnBase*, NestedIdAdapter<ESXRecordT>* > adapter);
};
template<typename ESXRecordT, typename IdAccessorT>
@ -69,119 +35,10 @@ namespace CSMWorld
}
template<typename ESXRecordT, typename IdAccessorT>
SubCellCollection<ESXRecordT, IdAccessorT>::SubCellCollection (const IdCollection<Cell>& cells)
SubCellCollection<ESXRecordT, IdAccessorT>::SubCellCollection (
const IdCollection<Cell>& cells)
: mCells (cells)
{}
template<typename ESXRecordT, typename IdAccessorT>
SubCellCollection<ESXRecordT, IdAccessorT>::~SubCellCollection()
{
for (typename std::map<const ColumnBase *, NestedIdAdapter<ESXRecordT>* >::iterator iter (mAdapters.begin());
iter!=mAdapters.end(); ++iter)
delete (*iter).second;
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::addAdapter(std::pair<const ColumnBase*, NestedIdAdapter<ESXRecordT>* > adapter)
{
mAdapters.insert(adapter);
}
template<typename ESXRecordT, typename IdAccessorT>
const NestedIdAdapter<ESXRecordT>& SubCellCollection<ESXRecordT, IdAccessorT>::getAdapter(const ColumnBase &column) const
{
typename std::map<const ColumnBase *, NestedIdAdapter<ESXRecordT>* >::const_iterator iter =
mAdapters.find (&column);
if (iter==mAdapters.end())
throw std::logic_error("No such column in the nestedidadapter");
return *iter->second;
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::addNestedRow(int row, int column, int position)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).addNestedRow(record, position);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::removeNestedRows(int row, int column, int subRow)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).removeNestedRow(record, subRow);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
QVariant SubCellCollection<ESXRecordT, IdAccessorT>::getNestedData (int row,
int column, int subRow, int subColumn) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedData(
Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow, subColumn);
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::setNestedData(int row,
int column, const QVariant& data, int subRow, int subColumn)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setNestedData(
record, data, subRow, subColumn);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestedTableWrapperBase* SubCellCollection<ESXRecordT, IdAccessorT>::nestedTable(int row,
int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).nestedTable(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::setNestedTable(int row,
int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
Record<ESXRecordT> record;
record.assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setNestedTable(
record, nestedTable);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, record);
}
template<typename ESXRecordT, typename IdAccessorT>
int SubCellCollection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedRowsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
int SubCellCollection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).getNestedColumnsCount(
Collection<ESXRecordT, IdAccessorT>::getRecord(row));
}
template<typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestableColumn *SubCellCollection<ESXRecordT, IdAccessorT>::getNestableColumn(int column)
{
return Collection<ESXRecordT, IdAccessorT>::getNestableColumn(column);
}
}
#endif

Loading…
Cancel
Save