Merge branch 'rm_id_accessor' into 'master'

Remove redundant IdAccessor type

See merge request OpenMW/openmw!2764
update_gitlab_rules
psi29a 2 years ago
commit 99acfdccb8

@ -14,10 +14,8 @@ namespace CSMDoc
namespace CSMWorld
{
struct Pathgrid;
template <typename T, typename AT>
template <typename T>
class SubCellCollection;
template <typename ESXRecordT>
struct IdAccessor;
}
namespace CSMTools
@ -35,12 +33,11 @@ namespace CSMTools
class PathgridCheckStage : public CSMDoc::Stage
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid, CSMWorld::IdAccessor<CSMWorld::Pathgrid>>& mPathgrids;
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& mPathgrids;
bool mIgnoreBaseRecords;
public:
PathgridCheckStage(
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid, CSMWorld::IdAccessor<CSMWorld::Pathgrid>>& pathgrids);
explicit PathgridCheckStage(const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids);
int setup() override;

@ -24,38 +24,34 @@
namespace CSMWorld
{
/// \brief Access to ID field in records
template <typename ESXRecordT>
struct IdAccessor
{
void setId(ESXRecordT& record, const ESM::RefId& id) const;
const ESM::RefId getId(const ESXRecordT& record) const;
};
template <typename ESXRecordT>
void IdAccessor<ESXRecordT>::setId(ESXRecordT& record, const ESM::RefId& id) const
template <typename T>
void setRecordId(const decltype(T::mId)& id, T& record)
{
record.mId = id;
}
template <typename ESXRecordT>
const ESM::RefId IdAccessor<ESXRecordT>::getId(const ESXRecordT& record) const
template <typename T>
auto getRecordId(const T& record)
{
return record.mId;
}
template <>
inline void IdAccessor<Land>::setId(Land& record, const ESM::RefId& id) const
inline void setRecordId(const ESM::RefId& id, Land& record)
{
int x = 0, y = 0;
int x = 0;
int y = 0;
Land::parseUniqueRecordId(id.getRefIdString(), x, y);
record.mX = x;
record.mY = y;
}
template <>
inline void IdAccessor<LandTexture>::setId(LandTexture& record, const ESM::RefId& id) const
inline ESM::RefId getRecordId(const Land& record)
{
return ESM::RefId::stringRefId(Land::createUniqueRecordId(record.mX, record.mY));
}
inline void setRecordId(LandTexture& record, const ESM::RefId& id)
{
int plugin = 0;
int index = 0;
@ -65,20 +61,13 @@ namespace CSMWorld
record.mIndex = index;
}
template <>
inline const ESM::RefId IdAccessor<Land>::getId(const Land& record) const
{
return ESM::RefId::stringRefId(Land::createUniqueRecordId(record.mX, record.mY));
}
template <>
inline const ESM::RefId IdAccessor<LandTexture>::getId(const LandTexture& record) const
inline ESM::RefId getRecordId(const LandTexture& record)
{
return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex));
}
/// \brief Single-type record collection
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
template <typename ESXRecordT>
class Collection : public CollectionBase
{
public:
@ -196,14 +185,14 @@ namespace CSMWorld
NestableColumn* getNestableColumn(int column) const;
};
template <typename ESXRecordT, typename IdAccessorT>
const std::vector<std::unique_ptr<Record<ESXRecordT>>>& Collection<ESXRecordT, IdAccessorT>::getRecords() const
template <typename ESXRecordT>
const std::vector<std::unique_ptr<Record<ESXRecordT>>>& Collection<ESXRecordT>::getRecords() const
{
return mRecords;
}
template <typename ESXRecordT, typename IdAccessorT>
bool Collection<ESXRecordT, IdAccessorT>::reorderRowsImp(int baseIndex, const std::vector<int>& newOrder)
template <typename ESXRecordT>
bool Collection<ESXRecordT>::reorderRowsImp(int baseIndex, const std::vector<int>& newOrder)
{
if (!newOrder.empty())
{
@ -236,14 +225,14 @@ namespace CSMWorld
return true;
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::cloneRecordImp(
template <typename ESXRecordT>
int Collection<ESXRecordT>::cloneRecordImp(
const std::string& origin, const std::string& destination, UniversalId::Type type)
{
auto copy = std::make_unique<Record<ESXRecordT>>();
copy->mModified = getRecord(ESM::RefId::stringRefId(origin)).get();
copy->mState = RecordBase::State_ModifiedOnly;
IdAccessorT().setId(copy->get(), ESM::RefId::stringRefId(destination));
setRecordId(ESM::RefId::stringRefId(destination), copy->get());
if (type == UniversalId::Type_Reference)
{
@ -257,8 +246,8 @@ namespace CSMWorld
return index;
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::touchRecordImp(const std::string& id)
template <typename ESXRecordT>
int Collection<ESXRecordT>::touchRecordImp(const std::string& id)
{
int index = getIndex(ESM::RefId::stringRefId(id));
Record<ESXRecordT>& record = *mRecords.at(index);
@ -276,29 +265,29 @@ namespace CSMWorld
return -1;
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::cloneRecord(
template <typename ESXRecordT>
void Collection<ESXRecordT>::cloneRecord(
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
{
cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
}
template <>
inline void Collection<Land, IdAccessor<Land>>::cloneRecord(
inline void Collection<Land>::cloneRecord(
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
{
int index = cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
mRecords.at(index)->get().setPlugin(0);
}
template <typename ESXRecordT, typename IdAccessorT>
bool Collection<ESXRecordT, IdAccessorT>::touchRecord(const ESM::RefId& id)
template <typename ESXRecordT>
bool Collection<ESXRecordT>::touchRecord(const ESM::RefId& id)
{
return touchRecordImp(id.getRefIdString()) != -1;
}
template <>
inline bool Collection<Land, IdAccessor<Land>>::touchRecord(const ESM::RefId& id)
inline bool Collection<Land>::touchRecord(const ESM::RefId& id)
{
int index = touchRecordImp(id.getRefIdString());
if (index >= 0)
@ -310,22 +299,22 @@ namespace CSMWorld
return false;
}
template <typename ESXRecordT, typename IdAccessorT>
Collection<ESXRecordT, IdAccessorT>::Collection()
template <typename ESXRecordT>
Collection<ESXRecordT>::Collection()
{
}
template <typename ESXRecordT, typename IdAccessorT>
Collection<ESXRecordT, IdAccessorT>::~Collection()
template <typename ESXRecordT>
Collection<ESXRecordT>::~Collection()
{
for (typename std::vector<Column<ESXRecordT>*>::iterator iter(mColumns.begin()); iter != mColumns.end(); ++iter)
delete *iter;
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::add(const ESXRecordT& record)
template <typename ESXRecordT>
void Collection<ESXRecordT>::add(const ESXRecordT& record)
{
const ESM::RefId id = IdAccessorT().getId(record);
const ESM::RefId id = getRecordId(record);
auto iter = mIndex.find(id);
@ -343,20 +332,20 @@ namespace CSMWorld
}
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::getSize() const
template <typename ESXRecordT>
int Collection<ESXRecordT>::getSize() const
{
return mRecords.size();
}
template <typename ESXRecordT, typename IdAccessorT>
ESM::RefId Collection<ESXRecordT, IdAccessorT>::getId(int index) const
template <typename ESXRecordT>
ESM::RefId Collection<ESXRecordT>::getId(int index) const
{
return IdAccessorT().getId(mRecords.at(index)->get());
return getRecordId(mRecords.at(index)->get());
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::getIndex(const ESM::RefId& id) const
template <typename ESXRecordT>
int Collection<ESXRecordT>::getIndex(const ESM::RefId& id) const
{
int index = searchId(id);
@ -366,32 +355,32 @@ namespace CSMWorld
return index;
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::getColumns() const
template <typename ESXRecordT>
int Collection<ESXRecordT>::getColumns() const
{
return mColumns.size();
}
template <typename ESXRecordT, typename IdAccessorT>
QVariant Collection<ESXRecordT, IdAccessorT>::getData(int index, int column) const
template <typename ESXRecordT>
QVariant Collection<ESXRecordT>::getData(int index, int column) const
{
return mColumns.at(column)->get(*mRecords.at(index));
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::setData(int index, int column, const QVariant& data)
template <typename ESXRecordT>
void Collection<ESXRecordT>::setData(int index, int column, const QVariant& data)
{
return mColumns.at(column)->set(*mRecords.at(index), data);
}
template <typename ESXRecordT, typename IdAccessorT>
const ColumnBase& Collection<ESXRecordT, IdAccessorT>::getColumn(int column) const
template <typename ESXRecordT>
const ColumnBase& Collection<ESXRecordT>::getColumn(int column) const
{
return *mColumns.at(column);
}
template <typename ESXRecordT, typename IdAccessorT>
NestableColumn* Collection<ESXRecordT, IdAccessorT>::getNestableColumn(int column) const
template <typename ESXRecordT>
NestableColumn* Collection<ESXRecordT>::getNestableColumn(int column) const
{
if (column < 0 || column >= static_cast<int>(mColumns.size()))
throw std::runtime_error("column index out of range");
@ -399,14 +388,14 @@ namespace CSMWorld
return mColumns.at(column);
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::addColumn(Column<ESXRecordT>* column)
template <typename ESXRecordT>
void Collection<ESXRecordT>::addColumn(Column<ESXRecordT>* column)
{
mColumns.push_back(column);
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::merge()
template <typename ESXRecordT>
void Collection<ESXRecordT>::merge()
{
for (typename std::vector<std::unique_ptr<Record<ESXRecordT>>>::iterator iter(mRecords.begin());
iter != mRecords.end(); ++iter)
@ -415,8 +404,8 @@ namespace CSMWorld
purge();
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::purge()
template <typename ESXRecordT>
void Collection<ESXRecordT>::purge()
{
int i = 0;
@ -429,8 +418,8 @@ namespace CSMWorld
}
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::removeRows(int index, int count)
template <typename ESXRecordT>
void Collection<ESXRecordT>::removeRows(int index, int count)
{
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
@ -455,11 +444,11 @@ namespace CSMWorld
}
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::appendBlankRecord(const ESM::RefId& id, UniversalId::Type type)
template <typename ESXRecordT>
void Collection<ESXRecordT>::appendBlankRecord(const ESM::RefId& id, UniversalId::Type type)
{
ESXRecordT record;
IdAccessorT().setId(record, id);
setRecordId(id, record);
record.blank();
auto record2 = std::make_unique<Record<ESXRecordT>>();
@ -469,8 +458,8 @@ namespace CSMWorld
insertRecord(std::move(record2), getAppendIndex(id, type), type);
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
template <typename ESXRecordT>
int Collection<ESXRecordT>::searchId(const ESM::RefId& id) const
{
const auto iter = mIndex.find(id);
@ -480,63 +469,62 @@ namespace CSMWorld
return iter->second;
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::replace(int index, std::unique_ptr<RecordBase> record)
template <typename ESXRecordT>
void Collection<ESXRecordT>::replace(int index, std::unique_ptr<RecordBase> record)
{
std::unique_ptr<Record<ESXRecordT>> tmp(static_cast<Record<ESXRecordT>*>(record.release()));
mRecords.at(index) = std::move(tmp);
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::appendRecord(std::unique_ptr<RecordBase> record, UniversalId::Type type)
template <typename ESXRecordT>
void Collection<ESXRecordT>::appendRecord(std::unique_ptr<RecordBase> record, UniversalId::Type type)
{
int index = getAppendIndex(IdAccessorT().getId(static_cast<Record<ESXRecordT>*>(record.get())->get()), type);
int index = getAppendIndex(getRecordId(static_cast<Record<ESXRecordT>*>(record.get())->get()), type);
insertRecord(std::move(record), index, type);
}
template <typename ESXRecordT, typename IdAccessorT>
int Collection<ESXRecordT, IdAccessorT>::getAppendIndex(const ESM::RefId& id, UniversalId::Type type) const
template <typename ESXRecordT>
int Collection<ESXRecordT>::getAppendIndex(const ESM::RefId& id, UniversalId::Type type) const
{
return static_cast<int>(mRecords.size());
}
template <typename ESXRecordT, typename IdAccessorT>
std::vector<ESM::RefId> Collection<ESXRecordT, IdAccessorT>::getIds(bool listDeleted) const
template <typename ESXRecordT>
std::vector<ESM::RefId> Collection<ESXRecordT>::getIds(bool listDeleted) const
{
std::vector<ESM::RefId> ids;
for (auto iter = mIndex.begin(); iter != mIndex.end(); ++iter)
{
if (listDeleted || !mRecords[iter->second]->isDeleted())
ids.push_back(IdAccessorT().getId(mRecords[iter->second]->get()));
ids.push_back(getRecordId(mRecords[iter->second]->get()));
}
return ids;
}
template <typename ESXRecordT, typename IdAccessorT>
const Record<ESXRecordT>& Collection<ESXRecordT, IdAccessorT>::getRecord(const ESM::RefId& id) const
template <typename ESXRecordT>
const Record<ESXRecordT>& Collection<ESXRecordT>::getRecord(const ESM::RefId& id) const
{
int index = getIndex(id);
return *mRecords.at(index);
}
template <typename ESXRecordT, typename IdAccessorT>
const Record<ESXRecordT>& Collection<ESXRecordT, IdAccessorT>::getRecord(int index) const
template <typename ESXRecordT>
const Record<ESXRecordT>& Collection<ESXRecordT>::getRecord(int index) const
{
return *mRecords.at(index);
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::insertRecord(
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
template <typename ESXRecordT>
void Collection<ESXRecordT>::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
{
int size = static_cast<int>(mRecords.size());
if (index < 0 || index > size)
throw std::runtime_error("index out of range");
std::unique_ptr<Record<ESXRecordT>> record2(static_cast<Record<ESXRecordT>*>(record.release()));
ESM::RefId id = IdAccessorT().getId(record2->get());
ESM::RefId id = getRecordId(record2->get());
if (index == size)
mRecords.push_back(std::move(record2));
@ -555,17 +543,17 @@ namespace CSMWorld
mIndex.insert(std::make_pair(id, index));
}
template <typename ESXRecordT, typename IdAccessorT>
void Collection<ESXRecordT, IdAccessorT>::setRecord(int index, std::unique_ptr<Record<ESXRecordT>> record)
template <typename ESXRecordT>
void Collection<ESXRecordT>::setRecord(int index, std::unique_ptr<Record<ESXRecordT>> record)
{
if (IdAccessorT().getId(mRecords.at(index)->get()) != IdAccessorT().getId(record->get()))
if (getRecordId(mRecords.at(index)->get()) != getRecordId(record->get()))
throw std::runtime_error("attempt to change the ID of a record");
mRecords.at(index) = std::move(record);
}
template <typename ESXRecordT, typename IdAccessorT>
bool Collection<ESXRecordT, IdAccessorT>::reorderRows(int baseIndex, const std::vector<int>& newOrder)
template <typename ESXRecordT>
bool Collection<ESXRecordT>::reorderRows(int baseIndex, const std::vector<int>& newOrder)
{
return false;
}

@ -18,14 +18,14 @@ namespace ESM
namespace CSMWorld
{
template <>
int IdCollection<Pathgrid, IdAccessor<Pathgrid>>::load(ESM::ESMReader& reader, bool base)
int IdCollection<Pathgrid>::load(ESM::ESMReader& reader, bool base)
{
Pathgrid record;
bool isDeleted = false;
loadRecord(record, reader, isDeleted);
auto id = IdAccessor<Pathgrid>().getId(record);
const ESM::RefId id = getRecordId(record);
int index = this->searchId(id);
if (record.mPoints.empty() || record.mEdges.empty())

@ -24,8 +24,8 @@ namespace CSMWorld
struct Pathgrid;
/// \brief Single type collection of top level records
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
class IdCollection : public Collection<ESXRecordT, IdAccessorT>
template <typename ESXRecordT>
class IdCollection : public Collection<ESXRecordT>
{
virtual void loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted);
@ -46,14 +46,14 @@ namespace CSMWorld
/// \return Has the ID been deleted?
};
template <typename ESXRecordT, typename IdAccessorT>
void IdCollection<ESXRecordT, IdAccessorT>::loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
template <typename ESXRecordT>
void IdCollection<ESXRecordT>::loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
{
record.load(reader, isDeleted);
}
template <>
inline void IdCollection<Land, IdAccessor<Land>>::loadRecord(Land& record, ESM::ESMReader& reader, bool& isDeleted)
inline void IdCollection<Land>::loadRecord(Land& record, ESM::ESMReader& reader, bool& isDeleted)
{
record.load(reader, isDeleted);
@ -66,15 +66,15 @@ namespace CSMWorld
record.mContext.filename.clear();
}
template <typename ESXRecordT, typename IdAccessorT>
int IdCollection<ESXRecordT, IdAccessorT>::load(ESM::ESMReader& reader, bool base)
template <typename ESXRecordT>
int IdCollection<ESXRecordT>::load(ESM::ESMReader& reader, bool base)
{
ESXRecordT record;
bool isDeleted = false;
loadRecord(record, reader, isDeleted);
ESM::RefId id = IdAccessorT().getId(record);
ESM::RefId id = getRecordId(record);
int index = this->searchId(id);
if (isDeleted)
@ -102,11 +102,11 @@ namespace CSMWorld
return load(record, base, index);
}
template <typename ESXRecordT, typename IdAccessorT>
int IdCollection<ESXRecordT, IdAccessorT>::load(const ESXRecordT& record, bool base, int index)
template <typename ESXRecordT>
int IdCollection<ESXRecordT>::load(const ESXRecordT& record, bool base, int index)
{
if (index == -2) // index unknown
index = this->searchId(IdAccessorT().getId(record));
index = this->searchId(getRecordId(record));
if (index == -1)
{
@ -121,7 +121,7 @@ namespace CSMWorld
else
{
// old record
auto record2 = std::make_unique<Record<ESXRecordT>>(Collection<ESXRecordT, IdAccessorT>::getRecord(index));
auto record2 = std::make_unique<Record<ESXRecordT>>(Collection<ESXRecordT>::getRecord(index));
if (base)
record2->mBase = record;
@ -134,26 +134,26 @@ namespace CSMWorld
return index;
}
template <typename ESXRecordT, typename IdAccessorT>
bool IdCollection<ESXRecordT, IdAccessorT>::tryDelete(const ESM::RefId& id)
template <typename ESXRecordT>
bool IdCollection<ESXRecordT>::tryDelete(const ESM::RefId& id)
{
int index = this->searchId(id);
if (index == -1)
return false;
const Record<ESXRecordT>& record = Collection<ESXRecordT, IdAccessorT>::getRecord(index);
const Record<ESXRecordT>& record = Collection<ESXRecordT>::getRecord(index);
if (record.isDeleted())
return false;
if (record.mState == RecordBase::State_ModifiedOnly)
{
Collection<ESXRecordT, IdAccessorT>::removeRows(index, 1);
Collection<ESXRecordT>::removeRows(index, 1);
}
else
{
auto record2 = std::make_unique<Record<ESXRecordT>>(Collection<ESXRecordT, IdAccessorT>::getRecord(index));
auto record2 = std::make_unique<Record<ESXRecordT>>(Collection<ESXRecordT>::getRecord(index));
record2->mState = RecordBase::State_Deleted;
this->setRecord(index, std::move(record2));
}
@ -162,7 +162,7 @@ namespace CSMWorld
}
template <>
int IdCollection<Pathgrid, IdAccessor<Pathgrid>>::load(ESM::ESMReader& reader, bool base);
int IdCollection<Pathgrid>::load(ESM::ESMReader& reader, bool base);
}
#endif

@ -19,7 +19,7 @@ namespace CSMWorld
using InfosByTopic = std::unordered_map<ESM::RefId, std::vector<ESM::RefId>>;
using InfosRecordPtrByTopic = std::unordered_map<ESM::RefId, std::vector<const Record<Info>*>>;
class InfoCollection : public Collection<Info, IdAccessor<Info>>
class InfoCollection : public Collection<Info>
{
private:
bool load(const Info& record, bool base);

@ -21,16 +21,13 @@ namespace CSMWorld
struct ColumnBase;
template <typename ESXRecordT>
struct IdAccessor;
template <typename ESXRecordT, typename IdAccessorT>
class IdCollection;
template <typename ESXRecordT>
class NestedColumnAdapter;
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
class NestedIdCollection : public IdCollection<ESXRecordT, IdAccessorT>, public NestedCollection
template <typename ESXRecordT>
class NestedIdCollection : public IdCollection<ESXRecordT>, public NestedCollection
{
std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> mAdapters;
@ -62,13 +59,13 @@ namespace CSMWorld
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> adapter);
};
template <typename ESXRecordT, typename IdAccessorT>
NestedIdCollection<ESXRecordT, IdAccessorT>::NestedIdCollection()
template <typename ESXRecordT>
NestedIdCollection<ESXRecordT>::NestedIdCollection()
{
}
template <typename ESXRecordT, typename IdAccessorT>
NestedIdCollection<ESXRecordT, IdAccessorT>::~NestedIdCollection()
template <typename ESXRecordT>
NestedIdCollection<ESXRecordT>::~NestedIdCollection()
{
for (typename std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*>::iterator iter(mAdapters.begin());
iter != mAdapters.end(); ++iter)
@ -77,16 +74,15 @@ namespace CSMWorld
}
}
template <typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::addAdapter(
template <typename ESXRecordT>
void NestedIdCollection<ESXRecordT>::addAdapter(
std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> adapter)
{
mAdapters.insert(adapter);
}
template <typename ESXRecordT, typename IdAccessorT>
const NestedColumnAdapter<ESXRecordT>& NestedIdCollection<ESXRecordT, IdAccessorT>::getAdapter(
const ColumnBase& column) const
template <typename ESXRecordT>
const NestedColumnAdapter<ESXRecordT>& NestedIdCollection<ESXRecordT>::getAdapter(const ColumnBase& column) const
{
typename std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*>::const_iterator iter
= mAdapters.find(&column);
@ -97,83 +93,80 @@ namespace CSMWorld
return *iter->second;
}
template <typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::addNestedRow(int row, int column, int position)
template <typename ESXRecordT>
void NestedIdCollection<ESXRecordT>::addNestedRow(int row, int column, int position)
{
auto record = std::make_unique<Record<ESXRecordT>>();
record->assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
record->assign(Collection<ESXRecordT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).addRow(*record, position);
getAdapter(Collection<ESXRecordT>::getColumn(column)).addRow(*record, position);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, std::move(record));
Collection<ESXRecordT>::setRecord(row, std::move(record));
}
template <typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::removeNestedRows(int row, int column, int subRow)
template <typename ESXRecordT>
void NestedIdCollection<ESXRecordT>::removeNestedRows(int row, int column, int subRow)
{
auto record = std::make_unique<Record<ESXRecordT>>();
record->assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
record->assign(Collection<ESXRecordT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).removeRow(*record, subRow);
getAdapter(Collection<ESXRecordT>::getColumn(column)).removeRow(*record, subRow);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, std::move(record));
Collection<ESXRecordT>::setRecord(row, std::move(record));
}
template <typename ESXRecordT, typename IdAccessorT>
QVariant NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedData(
int row, int column, int subRow, int subColumn) const
template <typename ESXRecordT>
QVariant NestedIdCollection<ESXRecordT>::getNestedData(int row, int column, int subRow, int subColumn) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))
.getData(Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow, subColumn);
return getAdapter(Collection<ESXRecordT>::getColumn(column))
.getData(Collection<ESXRecordT>::getRecord(row), subRow, subColumn);
}
template <typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedData(
template <typename ESXRecordT>
void NestedIdCollection<ESXRecordT>::setNestedData(
int row, int column, const QVariant& data, int subRow, int subColumn)
{
auto record = std::make_unique<Record<ESXRecordT>>();
record->assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
record->assign(Collection<ESXRecordT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setData(*record, data, subRow, subColumn);
getAdapter(Collection<ESXRecordT>::getColumn(column)).setData(*record, data, subRow, subColumn);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, std::move(record));
Collection<ESXRecordT>::setRecord(row, std::move(record));
}
template <typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestedTableWrapperBase* NestedIdCollection<ESXRecordT, IdAccessorT>::nestedTable(
int row, int column) const
template <typename ESXRecordT>
CSMWorld::NestedTableWrapperBase* NestedIdCollection<ESXRecordT>::nestedTable(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))
.table(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
return getAdapter(Collection<ESXRecordT>::getColumn(column)).table(Collection<ESXRecordT>::getRecord(row));
}
template <typename ESXRecordT, typename IdAccessorT>
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedTable(
template <typename ESXRecordT>
void NestedIdCollection<ESXRecordT>::setNestedTable(
int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
auto record = std::make_unique<Record<ESXRecordT>>();
record->assign(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
record->assign(Collection<ESXRecordT>::getRecord(row));
getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column)).setTable(*record, nestedTable);
getAdapter(Collection<ESXRecordT>::getColumn(column)).setTable(*record, nestedTable);
Collection<ESXRecordT, IdAccessorT>::setRecord(row, std::move(record));
Collection<ESXRecordT>::setRecord(row, std::move(record));
}
template <typename ESXRecordT, typename IdAccessorT>
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
template <typename ESXRecordT>
int NestedIdCollection<ESXRecordT>::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))
.getRowsCount(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
return getAdapter(Collection<ESXRecordT>::getColumn(column))
.getRowsCount(Collection<ESXRecordT>::getRecord(row));
}
template <typename ESXRecordT, typename IdAccessorT>
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int row, int column) const
template <typename ESXRecordT>
int NestedIdCollection<ESXRecordT>::getNestedColumnsCount(int row, int column) const
{
const ColumnBase& nestedColumn = Collection<ESXRecordT, IdAccessorT>::getColumn(column);
int numRecords = Collection<ESXRecordT, IdAccessorT>::getSize();
const ColumnBase& nestedColumn = Collection<ESXRecordT>::getColumn(column);
int numRecords = Collection<ESXRecordT>::getSize();
if (row >= 0 && row < numRecords)
{
const Record<ESXRecordT>& record = Collection<ESXRecordT, IdAccessorT>::getRecord(row);
const Record<ESXRecordT>& record = Collection<ESXRecordT>::getRecord(row);
return getAdapter(nestedColumn).getColumnsCount(record);
}
else
@ -184,10 +177,10 @@ namespace CSMWorld
}
}
template <typename ESXRecordT, typename IdAccessorT>
CSMWorld::NestableColumn* NestedIdCollection<ESXRecordT, IdAccessorT>::getNestableColumn(int column)
template <typename ESXRecordT>
CSMWorld::NestableColumn* NestedIdCollection<ESXRecordT>::getNestableColumn(int column)
{
return Collection<ESXRecordT, IdAccessorT>::getNestableColumn(column);
return Collection<ESXRecordT>::getNestableColumn(column);
}
}

@ -46,69 +46,66 @@ namespace CSMWorld
void NestedInfoCollection::addNestedRow(int row, int column, int position)
{
auto record = std::make_unique<Record<Info>>();
record->assign(Collection<Info, IdAccessor<Info>>::getRecord(row));
record->assign(Collection<Info>::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column)).addRow(*record, position);
getAdapter(Collection<Info>::getColumn(column)).addRow(*record, position);
Collection<Info, IdAccessor<Info>>::setRecord(row, std::move(record));
Collection<Info>::setRecord(row, std::move(record));
}
void NestedInfoCollection::removeNestedRows(int row, int column, int subRow)
{
auto record = std::make_unique<Record<Info>>();
record->assign(Collection<Info, IdAccessor<Info>>::getRecord(row));
record->assign(Collection<Info>::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column)).removeRow(*record, subRow);
getAdapter(Collection<Info>::getColumn(column)).removeRow(*record, subRow);
Collection<Info, IdAccessor<Info>>::setRecord(row, std::move(record));
Collection<Info>::setRecord(row, std::move(record));
}
QVariant NestedInfoCollection::getNestedData(int row, int column, int subRow, int subColumn) const
{
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
.getData(Collection<Info, IdAccessor<Info>>::getRecord(row), subRow, subColumn);
return getAdapter(Collection<Info>::getColumn(column))
.getData(Collection<Info>::getRecord(row), subRow, subColumn);
}
void NestedInfoCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn)
{
auto record = std::make_unique<Record<Info>>();
record->assign(Collection<Info, IdAccessor<Info>>::getRecord(row));
record->assign(Collection<Info>::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column)).setData(*record, data, subRow, subColumn);
getAdapter(Collection<Info>::getColumn(column)).setData(*record, data, subRow, subColumn);
Collection<Info, IdAccessor<Info>>::setRecord(row, std::move(record));
Collection<Info>::setRecord(row, std::move(record));
}
CSMWorld::NestedTableWrapperBase* NestedInfoCollection::nestedTable(int row, int column) const
{
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
.table(Collection<Info, IdAccessor<Info>>::getRecord(row));
return getAdapter(Collection<Info>::getColumn(column)).table(Collection<Info>::getRecord(row));
}
void NestedInfoCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
{
auto record = std::make_unique<Record<Info>>();
record->assign(Collection<Info, IdAccessor<Info>>::getRecord(row));
record->assign(Collection<Info>::getRecord(row));
getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column)).setTable(*record, nestedTable);
getAdapter(Collection<Info>::getColumn(column)).setTable(*record, nestedTable);
Collection<Info, IdAccessor<Info>>::setRecord(row, std::move(record));
Collection<Info>::setRecord(row, std::move(record));
}
int NestedInfoCollection::getNestedRowsCount(int row, int column) const
{
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
.getRowsCount(Collection<Info, IdAccessor<Info>>::getRecord(row));
return getAdapter(Collection<Info>::getColumn(column)).getRowsCount(Collection<Info>::getRecord(row));
}
int NestedInfoCollection::getNestedColumnsCount(int row, int column) const
{
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
.getColumnsCount(Collection<Info, IdAccessor<Info>>::getRecord(row));
return getAdapter(Collection<Info>::getColumn(column)).getColumnsCount(Collection<Info>::getRecord(row));
}
CSMWorld::NestableColumn* NestedInfoCollection::getNestableColumn(int column)
{
return Collection<Info, IdAccessor<Info>>::getNestableColumn(column);
return Collection<Info>::getNestableColumn(column);
}
}

@ -45,7 +45,7 @@ namespace CSMWorld
int getNestedColumnsCount(int row, int column) const override;
// this method is inherited from NestedCollection, not from Collection<Info, IdAccessor<Info> >
// this method is inherited from NestedCollection, not from Collection<Info>
NestableColumn* getNestableColumn(int column) override;
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<Info>*> adapter);

@ -14,12 +14,9 @@ namespace ESM
namespace CSMWorld
{
struct Cell;
template <typename T, typename AT>
template <typename T>
class IdCollection;
template <typename ESXRecordT>
struct IdAccessor;
/// \brief Wrapper for Pathgrid record
///
/// \attention The mData.mX and mData.mY fields of the ESM::Pathgrid struct are not used.
@ -28,7 +25,7 @@ namespace CSMWorld
{
ESM::RefId mId;
void load(ESM::ESMReader& esm, bool& isDeleted, const IdCollection<Cell, IdAccessor<Cell>>& cells);
void load(ESM::ESMReader& esm, bool& isDeleted, const IdCollection<Cell>& cells);
void load(ESM::ESMReader& esm, bool& isDeleted);
};
}

@ -20,7 +20,7 @@
namespace CSMWorld
{
template <>
void Collection<CellRef, IdAccessor<CellRef>>::removeRows(int index, int count)
void Collection<CellRef>::removeRows(int index, int count)
{
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
@ -28,8 +28,7 @@ namespace CSMWorld
}
template <>
void Collection<CellRef, IdAccessor<CellRef>>::insertRecord(
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
void Collection<CellRef>::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
{
int size = static_cast<int>(mRecords.size());
if (index < 0 || index > size)
@ -257,7 +256,7 @@ int CSMWorld::RefCollection::searchId(unsigned int id) const
void CSMWorld::RefCollection::removeRows(int index, int count)
{
Collection<CellRef, IdAccessor<CellRef>>::removeRows(index, count); // erase records only
Collection<CellRef>::removeRows(index, count); // erase records only
std::map<unsigned int, int>::iterator iter = mRefIndex.begin();
while (iter != mRefIndex.end())
@ -287,7 +286,7 @@ void CSMWorld::RefCollection::appendBlankRecord(const std::string& id, Universal
record->get().mId = ESM::RefId::stringRefId(id);
record->get().mIdNum = extractIdNum(id);
Collection<CellRef, IdAccessor<CellRef>>::appendRecord(std::move(record));
Collection<CellRef>::appendRecord(std::move(record));
}
void CSMWorld::RefCollection::appendBlankRecord(const ESM::RefId& id, UniversalId::Type type)
@ -300,7 +299,7 @@ void CSMWorld::RefCollection::appendBlankRecord(const ESM::RefId& id, UniversalI
record->get().mId = id;
record->get().mIdNum = extractIdNum(id.getRefIdString());
Collection<CellRef, IdAccessor<CellRef>>::appendRecord(std::move(record));
Collection<CellRef>::appendRecord(std::move(record));
}
void CSMWorld::RefCollection::cloneRecord(
@ -333,7 +332,7 @@ void CSMWorld::RefCollection::appendRecord(std::unique_ptr<RecordBase> record, U
mRefIndex.insert(std::make_pair(static_cast<Record<CellRef>*>(record.get())->get().mIdNum, index));
Collection<CellRef, IdAccessor<CellRef>>::insertRecord(std::move(record), index, type); // add records only
Collection<CellRef>::insertRecord(std::move(record), index, type); // add records only
}
void CSMWorld::RefCollection::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
@ -341,7 +340,7 @@ void CSMWorld::RefCollection::insertRecord(std::unique_ptr<RecordBase> record, i
int size = getAppendIndex(/*id*/ ESM::RefId(), type); // for CellRef records id is ignored
unsigned int idNum = static_cast<Record<CellRef>*>(record.get())->get().mIdNum;
Collection<CellRef, IdAccessor<CellRef>>::insertRecord(std::move(record), index, type); // add records only
Collection<CellRef>::insertRecord(std::move(record), index, type); // add records only
if (index < size - 1)
{

@ -28,11 +28,10 @@ namespace CSMWorld
struct Cell;
template <>
void Collection<CellRef, IdAccessor<CellRef>>::removeRows(int index, int count);
void Collection<CellRef>::removeRows(int index, int count);
template <>
void Collection<CellRef, IdAccessor<CellRef>>::insertRecord(
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type);
void Collection<CellRef>::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type);
/// \brief References in cells
class RefCollection : public Collection<CellRef>

@ -13,26 +13,25 @@ namespace CSMWorld
struct Cell;
/// \brief Single type collection of top level records that are associated with cells
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
class SubCellCollection : public NestedIdCollection<ESXRecordT, IdAccessorT>
template <typename ESXRecordT>
class SubCellCollection : public NestedIdCollection<ESXRecordT>
{
const IdCollection<Cell, IdAccessor<Cell>>& mCells;
const IdCollection<Cell>& mCells;
void loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted) override;
public:
SubCellCollection(const IdCollection<Cell, IdAccessor<Cell>>& cells);
SubCellCollection(const IdCollection<Cell>& cells);
};
template <typename ESXRecordT, typename IdAccessorT>
void SubCellCollection<ESXRecordT, IdAccessorT>::loadRecord(
ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
template <typename ESXRecordT>
void SubCellCollection<ESXRecordT>::loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
{
record.load(reader, isDeleted, mCells);
}
template <typename ESXRecordT, typename IdAccessorT>
SubCellCollection<ESXRecordT, IdAccessorT>::SubCellCollection(const IdCollection<Cell, IdAccessor<Cell>>& cells)
template <typename ESXRecordT>
SubCellCollection<ESXRecordT>::SubCellCollection(const IdCollection<Cell>& cells)
: mCells(cells)
{
}

Loading…
Cancel
Save