forked from teamnwah/openmw-tes3coop
moved implementation of searchColumnIndex and findColumnIndex functions from IdTable to CollectionBase
This commit is contained in:
parent
baae548106
commit
62148b3247
3 changed files with 35 additions and 13 deletions
|
@ -1,6 +1,31 @@
|
|||
|
||||
#include "collectionbase.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "columnbase.hpp"
|
||||
|
||||
CSMWorld::CollectionBase::CollectionBase() {}
|
||||
|
||||
CSMWorld::CollectionBase::~CollectionBase() {}
|
||||
|
||||
int CSMWorld::CollectionBase::searchColumnIndex (Columns::ColumnId id) const
|
||||
{
|
||||
int columns = getColumns();
|
||||
|
||||
for (int i=0; i<columns; ++i)
|
||||
if (getColumn (i).mColumnId==id)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CSMWorld::CollectionBase::findColumnIndex (Columns::ColumnId id) const
|
||||
{
|
||||
int index = searchColumnIndex (id);
|
||||
|
||||
if (index==-1)
|
||||
throw std::logic_error ("invalid column index");
|
||||
|
||||
return index;
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "universalid.hpp"
|
||||
#include "columns.hpp"
|
||||
|
||||
class QVariant;
|
||||
|
||||
|
@ -83,6 +84,13 @@ namespace CSMWorld
|
|||
///< Return a sorted collection of all IDs
|
||||
///
|
||||
/// \param listDeleted include deleted record in the list
|
||||
|
||||
int searchColumnIndex (Columns::ColumnId id) const;
|
||||
///< Return index of column with the given \a id. If no such column exists, -1 is returned.
|
||||
|
||||
int findColumnIndex (Columns::ColumnId id) const;
|
||||
///< Return index of column with the given \a id. If no such column exists, an exception is
|
||||
/// thrown.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -161,21 +161,10 @@ const CSMWorld::RecordBase& CSMWorld::IdTable::getRecord (const std::string& id)
|
|||
|
||||
int CSMWorld::IdTable::searchColumnIndex (Columns::ColumnId id) const
|
||||
{
|
||||
int columns = mIdCollection->getColumns();
|
||||
|
||||
for (int i=0; i<columns; ++i)
|
||||
if (mIdCollection->getColumn (i).mColumnId==id)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
return mIdCollection->searchColumnIndex (id);
|
||||
}
|
||||
|
||||
int CSMWorld::IdTable::findColumnIndex (Columns::ColumnId id) const
|
||||
{
|
||||
int index = searchColumnIndex (id);
|
||||
|
||||
if (index==-1)
|
||||
throw std::logic_error ("invalid column index");
|
||||
|
||||
return index;
|
||||
return mIdCollection->findColumnIndex (id);
|
||||
}
|
Loading…
Reference in a new issue