Remove duplicated checks and exceptions.

test
cc9cii 10 years ago
parent 221c57adee
commit 60e5ff8811

@ -997,7 +997,7 @@ namespace CSMWorld
static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType))); static_cast<const Record<ESXRecordT>&> (data.getRecord (RefIdData::LocalIndex (index, mType)));
// deleted by dtor of NestedTableStoring // deleted by dtor of NestedTableStoring
return new NestedTableWrapper<std::vector<ESM::ContItem> >(record.get().mInventory.mList); return new NestedTableWrapper<typename std::vector<ESM::ContItem> >(record.get().mInventory.mList);
} }
virtual QVariant getNestedData (const RefIdColumn *column, virtual QVariant getNestedData (const RefIdColumn *column,

@ -539,12 +539,9 @@ QVariant CSMWorld::RefIdCollection::getData (int index, int column) const
QVariant CSMWorld::RefIdCollection::getNestedData (int row, int column, int subRow, int subColumn) const QVariant CSMWorld::RefIdCollection::getNestedData (int row, int column, int subRow, int subColumn) const
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex(row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex(row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); return nestedAdapter.getNestedData(&mColumns.at (column), mData, localIndex.first, subRow, subColumn);
if (nestedAdapter)
return nestedAdapter->getNestedData(&mColumns.at (column), mData, localIndex.first, subRow, subColumn);
else
throw std::runtime_error("Could not find a nestedadapter");
} }
void CSMWorld::RefIdCollection::setData (int index, int column, const QVariant& data) void CSMWorld::RefIdCollection::setData (int index, int column, const QVariant& data)
@ -559,15 +556,10 @@ void CSMWorld::RefIdCollection::setData (int index, int column, const QVariant&
void CSMWorld::RefIdCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn) void CSMWorld::RefIdCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn)
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); nestedAdapter.setNestedData(&mColumns.at (column), mData, localIndex.first, data, subRow, subColumn);
if (nestedAdapter)
{
nestedAdapter->setNestedData(&mColumns.at (column), mData, localIndex.first, data, subRow, subColumn);
return; return;
}
else
throw std::runtime_error("Could not find a nestedadapter");
} }
void CSMWorld::RefIdCollection::removeRows (int index, int count) void CSMWorld::RefIdCollection::removeRows (int index, int count)
@ -578,15 +570,10 @@ void CSMWorld::RefIdCollection::removeRows (int index, int count)
void CSMWorld::RefIdCollection::removeNestedRows(int row, int column, int subRow) void CSMWorld::RefIdCollection::removeNestedRows(int row, int column, int subRow)
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); nestedAdapter.removeNestedRow(&mColumns.at (column), mData, localIndex.first, subRow);
if (nestedAdapter)
{
nestedAdapter->removeNestedRow(&mColumns.at (column), mData, localIndex.first, subRow);
return; return;
}
else
throw std::runtime_error("Could not find a nestedadapter");
} }
void CSMWorld::RefIdCollection::appendBlankRecord (const std::string& id, UniversalId::Type type) void CSMWorld::RefIdCollection::appendBlankRecord (const std::string& id, UniversalId::Type type)
@ -727,23 +714,17 @@ const CSMWorld::RefIdData& CSMWorld::RefIdCollection::getDataSet() const
int CSMWorld::RefIdCollection::getNestedRowsCount(int row, int column) const int CSMWorld::RefIdCollection::getNestedRowsCount(int row, int column) const
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); return nestedAdapter.getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
if (nestedAdapter)
return nestedAdapter->getNestedRowsCount(&mColumns.at(column), mData, localIndex.first);
else
throw std::runtime_error("Could not find a nestedadapter");
} }
int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const int CSMWorld::RefIdCollection::getNestedColumnsCount(int row, int column) const
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); return nestedAdapter.getNestedColumnsCount(&mColumns.at(column), mData);
if (nestedAdapter)
return nestedAdapter->getNestedColumnsCount(&mColumns.at(column), mData);
else
throw std::runtime_error("Could not find a nestedadapter");
} }
CSMWorld::NestableColumn *CSMWorld::RefIdCollection::getNestableColumn(int column) CSMWorld::NestableColumn *CSMWorld::RefIdCollection::getNestableColumn(int column)
@ -754,43 +735,30 @@ CSMWorld::NestableColumn *CSMWorld::RefIdCollection::getNestableColumn(int colum
void CSMWorld::RefIdCollection::addNestedRow(int row, int col, int position) void CSMWorld::RefIdCollection::addNestedRow(int row, int col, int position)
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(col), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(col), localIndex.second); nestedAdapter.addNestedRow(&mColumns.at(col), mData, localIndex.first, position);
if (nestedAdapter)
{
nestedAdapter->addNestedRow(&mColumns.at(col), mData, localIndex.first, position);
return; return;
}
else
throw std::runtime_error("Could not find a nestedadapter");
} }
void CSMWorld::RefIdCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable) void CSMWorld::RefIdCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); nestedAdapter.setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
if (nestedAdapter)
{
nestedAdapter->setNestedTable(&mColumns.at(column), mData, localIndex.first, nestedTable);
return; return;
}
else
throw std::runtime_error("Could not find a nestedadapter");
} }
CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row, int column) const CSMWorld::NestedTableWrapperBase* CSMWorld::RefIdCollection::nestedTable(int row, int column) const
{ {
RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row); RefIdData::LocalIndex localIndex = mData.globalToLocalIndex (row);
const CSMWorld::NestedRefIdAdapterBase& nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second);
const CSMWorld::NestedRefIdAdapterBase* nestedAdapter = getNestedAdapter(mColumns.at(column), localIndex.second); return nestedAdapter.nestedTable(&mColumns.at(column), mData, localIndex.first);
if (nestedAdapter)
return nestedAdapter->nestedTable(&mColumns.at(column), mData, localIndex.first);
else
throw std::runtime_error("Could not find a nestedadapter");
} }
const CSMWorld::NestedRefIdAdapterBase* CSMWorld::RefIdCollection::getNestedAdapter(const CSMWorld::ColumnBase &column, UniversalId::Type type) const const CSMWorld::NestedRefIdAdapterBase& CSMWorld::RefIdCollection::getNestedAdapter(const CSMWorld::ColumnBase &column, UniversalId::Type type) const
{ {
for (std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > >::const_iterator iter (mNestedAdapters.begin()); for (std::vector<std::pair<const ColumnBase*, std::map<UniversalId::Type, NestedRefIdAdapterBase*> > >::const_iterator iter (mNestedAdapters.begin());
iter!=mNestedAdapters.end(); ++iter) iter!=mNestedAdapters.end(); ++iter)
@ -803,7 +771,7 @@ const CSMWorld::NestedRefIdAdapterBase* CSMWorld::RefIdCollection::getNestedAdap
if (it == (iter->second).end()) if (it == (iter->second).end())
throw std::runtime_error("No such type in the nestedadapters"); throw std::runtime_error("No such type in the nestedadapters");
return it->second; return *it->second;
} }
} }
throw std::runtime_error("No such column in the nestedadapters"); throw std::runtime_error("No such column in the nestedadapters");

@ -52,7 +52,7 @@ namespace CSMWorld
const RefIdAdapter& findAdapter (UniversalId::Type) const; const RefIdAdapter& findAdapter (UniversalId::Type) const;
///< Throws an exception if no adaptor for \a Type can be found. ///< Throws an exception if no adaptor for \a Type can be found.
const NestedRefIdAdapterBase* getNestedAdapter(const ColumnBase &column, UniversalId::Type type) const; const NestedRefIdAdapterBase& getNestedAdapter(const ColumnBase &column, UniversalId::Type type) const;
public: public:

Loading…
Cancel
Save