mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 08:53:52 +00:00
Merge branch 'rm_id_accessor' into 'master'
Remove redundant IdAccessor type See merge request OpenMW/openmw!2764
This commit is contained in:
commit
99acfdccb8
12 changed files with 200 additions and 231 deletions
|
@ -14,10 +14,8 @@ namespace CSMDoc
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
struct Pathgrid;
|
struct Pathgrid;
|
||||||
template <typename T, typename AT>
|
template <typename T>
|
||||||
class SubCellCollection;
|
class SubCellCollection;
|
||||||
template <typename ESXRecordT>
|
|
||||||
struct IdAccessor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CSMTools
|
namespace CSMTools
|
||||||
|
@ -35,12 +33,11 @@ namespace CSMTools
|
||||||
|
|
||||||
class PathgridCheckStage : public CSMDoc::Stage
|
class PathgridCheckStage : public CSMDoc::Stage
|
||||||
{
|
{
|
||||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid, CSMWorld::IdAccessor<CSMWorld::Pathgrid>>& mPathgrids;
|
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& mPathgrids;
|
||||||
bool mIgnoreBaseRecords;
|
bool mIgnoreBaseRecords;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PathgridCheckStage(
|
explicit PathgridCheckStage(const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids);
|
||||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid, CSMWorld::IdAccessor<CSMWorld::Pathgrid>>& pathgrids);
|
|
||||||
|
|
||||||
int setup() override;
|
int setup() override;
|
||||||
|
|
||||||
|
|
|
@ -24,38 +24,34 @@
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
/// \brief Access to ID field in records
|
template <typename T>
|
||||||
template <typename ESXRecordT>
|
void setRecordId(const decltype(T::mId)& id, T& record)
|
||||||
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
|
|
||||||
{
|
{
|
||||||
record.mId = id;
|
record.mId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename T>
|
||||||
const ESM::RefId IdAccessor<ESXRecordT>::getId(const ESXRecordT& record) const
|
auto getRecordId(const T& record)
|
||||||
{
|
{
|
||||||
return record.mId;
|
return record.mId;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
inline void setRecordId(const ESM::RefId& id, Land& record)
|
||||||
inline void IdAccessor<Land>::setId(Land& record, const ESM::RefId& id) const
|
|
||||||
{
|
{
|
||||||
int x = 0, y = 0;
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
Land::parseUniqueRecordId(id.getRefIdString(), x, y);
|
Land::parseUniqueRecordId(id.getRefIdString(), x, y);
|
||||||
record.mX = x;
|
record.mX = x;
|
||||||
record.mY = y;
|
record.mY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
inline ESM::RefId getRecordId(const Land& record)
|
||||||
inline void IdAccessor<LandTexture>::setId(LandTexture& record, const ESM::RefId& id) const
|
{
|
||||||
|
return ESM::RefId::stringRefId(Land::createUniqueRecordId(record.mX, record.mY));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setRecordId(LandTexture& record, const ESM::RefId& id)
|
||||||
{
|
{
|
||||||
int plugin = 0;
|
int plugin = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -65,20 +61,13 @@ namespace CSMWorld
|
||||||
record.mIndex = index;
|
record.mIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
inline ESM::RefId getRecordId(const LandTexture& record)
|
||||||
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
|
|
||||||
{
|
{
|
||||||
return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex));
|
return ESM::RefId::stringRefId(LandTexture::createUniqueRecordId(record.mPluginIndex, record.mIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \brief Single-type record collection
|
/// \brief Single-type record collection
|
||||||
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
|
template <typename ESXRecordT>
|
||||||
class Collection : public CollectionBase
|
class Collection : public CollectionBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -196,14 +185,14 @@ namespace CSMWorld
|
||||||
NestableColumn* getNestableColumn(int column) const;
|
NestableColumn* getNestableColumn(int column) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
const std::vector<std::unique_ptr<Record<ESXRecordT>>>& Collection<ESXRecordT, IdAccessorT>::getRecords() const
|
const std::vector<std::unique_ptr<Record<ESXRecordT>>>& Collection<ESXRecordT>::getRecords() const
|
||||||
{
|
{
|
||||||
return mRecords;
|
return mRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
bool Collection<ESXRecordT, IdAccessorT>::reorderRowsImp(int baseIndex, const std::vector<int>& newOrder)
|
bool Collection<ESXRecordT>::reorderRowsImp(int baseIndex, const std::vector<int>& newOrder)
|
||||||
{
|
{
|
||||||
if (!newOrder.empty())
|
if (!newOrder.empty())
|
||||||
{
|
{
|
||||||
|
@ -236,14 +225,14 @@ namespace CSMWorld
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::cloneRecordImp(
|
int Collection<ESXRecordT>::cloneRecordImp(
|
||||||
const std::string& origin, const std::string& destination, UniversalId::Type type)
|
const std::string& origin, const std::string& destination, UniversalId::Type type)
|
||||||
{
|
{
|
||||||
auto copy = std::make_unique<Record<ESXRecordT>>();
|
auto copy = std::make_unique<Record<ESXRecordT>>();
|
||||||
copy->mModified = getRecord(ESM::RefId::stringRefId(origin)).get();
|
copy->mModified = getRecord(ESM::RefId::stringRefId(origin)).get();
|
||||||
copy->mState = RecordBase::State_ModifiedOnly;
|
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)
|
if (type == UniversalId::Type_Reference)
|
||||||
{
|
{
|
||||||
|
@ -257,8 +246,8 @@ namespace CSMWorld
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::touchRecordImp(const std::string& id)
|
int Collection<ESXRecordT>::touchRecordImp(const std::string& id)
|
||||||
{
|
{
|
||||||
int index = getIndex(ESM::RefId::stringRefId(id));
|
int index = getIndex(ESM::RefId::stringRefId(id));
|
||||||
Record<ESXRecordT>& record = *mRecords.at(index);
|
Record<ESXRecordT>& record = *mRecords.at(index);
|
||||||
|
@ -276,29 +265,29 @@ namespace CSMWorld
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::cloneRecord(
|
void Collection<ESXRecordT>::cloneRecord(
|
||||||
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
||||||
{
|
{
|
||||||
cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
|
cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
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)
|
const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type)
|
||||||
{
|
{
|
||||||
int index = cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
|
int index = cloneRecordImp(origin.getRefIdString(), destination.getRefIdString(), type);
|
||||||
mRecords.at(index)->get().setPlugin(0);
|
mRecords.at(index)->get().setPlugin(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
bool Collection<ESXRecordT, IdAccessorT>::touchRecord(const ESM::RefId& id)
|
bool Collection<ESXRecordT>::touchRecord(const ESM::RefId& id)
|
||||||
{
|
{
|
||||||
return touchRecordImp(id.getRefIdString()) != -1;
|
return touchRecordImp(id.getRefIdString()) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
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());
|
int index = touchRecordImp(id.getRefIdString());
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
|
@ -310,22 +299,22 @@ namespace CSMWorld
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
Collection<ESXRecordT, IdAccessorT>::Collection()
|
Collection<ESXRecordT>::Collection()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
Collection<ESXRecordT, IdAccessorT>::~Collection()
|
Collection<ESXRecordT>::~Collection()
|
||||||
{
|
{
|
||||||
for (typename std::vector<Column<ESXRecordT>*>::iterator iter(mColumns.begin()); iter != mColumns.end(); ++iter)
|
for (typename std::vector<Column<ESXRecordT>*>::iterator iter(mColumns.begin()); iter != mColumns.end(); ++iter)
|
||||||
delete *iter;
|
delete *iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::add(const ESXRecordT& record)
|
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);
|
auto iter = mIndex.find(id);
|
||||||
|
|
||||||
|
@ -343,20 +332,20 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::getSize() const
|
int Collection<ESXRecordT>::getSize() const
|
||||||
{
|
{
|
||||||
return mRecords.size();
|
return mRecords.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
ESM::RefId Collection<ESXRecordT, IdAccessorT>::getId(int index) const
|
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>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::getIndex(const ESM::RefId& id) const
|
int Collection<ESXRecordT>::getIndex(const ESM::RefId& id) const
|
||||||
{
|
{
|
||||||
int index = searchId(id);
|
int index = searchId(id);
|
||||||
|
|
||||||
|
@ -366,32 +355,32 @@ namespace CSMWorld
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::getColumns() const
|
int Collection<ESXRecordT>::getColumns() const
|
||||||
{
|
{
|
||||||
return mColumns.size();
|
return mColumns.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
QVariant Collection<ESXRecordT, IdAccessorT>::getData(int index, int column) const
|
QVariant Collection<ESXRecordT>::getData(int index, int column) const
|
||||||
{
|
{
|
||||||
return mColumns.at(column)->get(*mRecords.at(index));
|
return mColumns.at(column)->get(*mRecords.at(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::setData(int index, int column, const QVariant& data)
|
void Collection<ESXRecordT>::setData(int index, int column, const QVariant& data)
|
||||||
{
|
{
|
||||||
return mColumns.at(column)->set(*mRecords.at(index), data);
|
return mColumns.at(column)->set(*mRecords.at(index), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
const ColumnBase& Collection<ESXRecordT, IdAccessorT>::getColumn(int column) const
|
const ColumnBase& Collection<ESXRecordT>::getColumn(int column) const
|
||||||
{
|
{
|
||||||
return *mColumns.at(column);
|
return *mColumns.at(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
NestableColumn* Collection<ESXRecordT, IdAccessorT>::getNestableColumn(int column) const
|
NestableColumn* Collection<ESXRecordT>::getNestableColumn(int column) const
|
||||||
{
|
{
|
||||||
if (column < 0 || column >= static_cast<int>(mColumns.size()))
|
if (column < 0 || column >= static_cast<int>(mColumns.size()))
|
||||||
throw std::runtime_error("column index out of range");
|
throw std::runtime_error("column index out of range");
|
||||||
|
@ -399,14 +388,14 @@ namespace CSMWorld
|
||||||
return mColumns.at(column);
|
return mColumns.at(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::addColumn(Column<ESXRecordT>* column)
|
void Collection<ESXRecordT>::addColumn(Column<ESXRecordT>* column)
|
||||||
{
|
{
|
||||||
mColumns.push_back(column);
|
mColumns.push_back(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::merge()
|
void Collection<ESXRecordT>::merge()
|
||||||
{
|
{
|
||||||
for (typename std::vector<std::unique_ptr<Record<ESXRecordT>>>::iterator iter(mRecords.begin());
|
for (typename std::vector<std::unique_ptr<Record<ESXRecordT>>>::iterator iter(mRecords.begin());
|
||||||
iter != mRecords.end(); ++iter)
|
iter != mRecords.end(); ++iter)
|
||||||
|
@ -415,8 +404,8 @@ namespace CSMWorld
|
||||||
purge();
|
purge();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::purge()
|
void Collection<ESXRecordT>::purge()
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
@ -429,8 +418,8 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::removeRows(int index, int count)
|
void Collection<ESXRecordT>::removeRows(int index, int count)
|
||||||
{
|
{
|
||||||
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
|
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
|
||||||
|
|
||||||
|
@ -455,11 +444,11 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::appendBlankRecord(const ESM::RefId& id, UniversalId::Type type)
|
void Collection<ESXRecordT>::appendBlankRecord(const ESM::RefId& id, UniversalId::Type type)
|
||||||
{
|
{
|
||||||
ESXRecordT record;
|
ESXRecordT record;
|
||||||
IdAccessorT().setId(record, id);
|
setRecordId(id, record);
|
||||||
record.blank();
|
record.blank();
|
||||||
|
|
||||||
auto record2 = std::make_unique<Record<ESXRecordT>>();
|
auto record2 = std::make_unique<Record<ESXRecordT>>();
|
||||||
|
@ -469,8 +458,8 @@ namespace CSMWorld
|
||||||
insertRecord(std::move(record2), getAppendIndex(id, type), type);
|
insertRecord(std::move(record2), getAppendIndex(id, type), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::searchId(const ESM::RefId& id) const
|
int Collection<ESXRecordT>::searchId(const ESM::RefId& id) const
|
||||||
{
|
{
|
||||||
const auto iter = mIndex.find(id);
|
const auto iter = mIndex.find(id);
|
||||||
|
|
||||||
|
@ -480,63 +469,62 @@ namespace CSMWorld
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::replace(int index, std::unique_ptr<RecordBase> record)
|
void Collection<ESXRecordT>::replace(int index, std::unique_ptr<RecordBase> record)
|
||||||
{
|
{
|
||||||
std::unique_ptr<Record<ESXRecordT>> tmp(static_cast<Record<ESXRecordT>*>(record.release()));
|
std::unique_ptr<Record<ESXRecordT>> tmp(static_cast<Record<ESXRecordT>*>(record.release()));
|
||||||
mRecords.at(index) = std::move(tmp);
|
mRecords.at(index) = std::move(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::appendRecord(std::unique_ptr<RecordBase> record, UniversalId::Type type)
|
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);
|
insertRecord(std::move(record), index, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int Collection<ESXRecordT, IdAccessorT>::getAppendIndex(const ESM::RefId& id, UniversalId::Type type) const
|
int Collection<ESXRecordT>::getAppendIndex(const ESM::RefId& id, UniversalId::Type type) const
|
||||||
{
|
{
|
||||||
return static_cast<int>(mRecords.size());
|
return static_cast<int>(mRecords.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
std::vector<ESM::RefId> Collection<ESXRecordT, IdAccessorT>::getIds(bool listDeleted) const
|
std::vector<ESM::RefId> Collection<ESXRecordT>::getIds(bool listDeleted) const
|
||||||
{
|
{
|
||||||
std::vector<ESM::RefId> ids;
|
std::vector<ESM::RefId> ids;
|
||||||
|
|
||||||
for (auto iter = mIndex.begin(); iter != mIndex.end(); ++iter)
|
for (auto iter = mIndex.begin(); iter != mIndex.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (listDeleted || !mRecords[iter->second]->isDeleted())
|
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;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
const Record<ESXRecordT>& Collection<ESXRecordT, IdAccessorT>::getRecord(const ESM::RefId& id) const
|
const Record<ESXRecordT>& Collection<ESXRecordT>::getRecord(const ESM::RefId& id) const
|
||||||
{
|
{
|
||||||
int index = getIndex(id);
|
int index = getIndex(id);
|
||||||
return *mRecords.at(index);
|
return *mRecords.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
const Record<ESXRecordT>& Collection<ESXRecordT, IdAccessorT>::getRecord(int index) const
|
const Record<ESXRecordT>& Collection<ESXRecordT>::getRecord(int index) const
|
||||||
{
|
{
|
||||||
return *mRecords.at(index);
|
return *mRecords.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::insertRecord(
|
void Collection<ESXRecordT>::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
|
||||||
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
|
|
||||||
{
|
{
|
||||||
int size = static_cast<int>(mRecords.size());
|
int size = static_cast<int>(mRecords.size());
|
||||||
if (index < 0 || index > size)
|
if (index < 0 || index > size)
|
||||||
throw std::runtime_error("index out of range");
|
throw std::runtime_error("index out of range");
|
||||||
|
|
||||||
std::unique_ptr<Record<ESXRecordT>> record2(static_cast<Record<ESXRecordT>*>(record.release()));
|
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)
|
if (index == size)
|
||||||
mRecords.push_back(std::move(record2));
|
mRecords.push_back(std::move(record2));
|
||||||
|
@ -555,17 +543,17 @@ namespace CSMWorld
|
||||||
mIndex.insert(std::make_pair(id, index));
|
mIndex.insert(std::make_pair(id, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void Collection<ESXRecordT, IdAccessorT>::setRecord(int index, std::unique_ptr<Record<ESXRecordT>> record)
|
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");
|
throw std::runtime_error("attempt to change the ID of a record");
|
||||||
|
|
||||||
mRecords.at(index) = std::move(record);
|
mRecords.at(index) = std::move(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
bool Collection<ESXRecordT, IdAccessorT>::reorderRows(int baseIndex, const std::vector<int>& newOrder)
|
bool Collection<ESXRecordT>::reorderRows(int baseIndex, const std::vector<int>& newOrder)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,14 @@ namespace ESM
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
template <>
|
template <>
|
||||||
int IdCollection<Pathgrid, IdAccessor<Pathgrid>>::load(ESM::ESMReader& reader, bool base)
|
int IdCollection<Pathgrid>::load(ESM::ESMReader& reader, bool base)
|
||||||
{
|
{
|
||||||
Pathgrid record;
|
Pathgrid record;
|
||||||
bool isDeleted = false;
|
bool isDeleted = false;
|
||||||
|
|
||||||
loadRecord(record, reader, isDeleted);
|
loadRecord(record, reader, isDeleted);
|
||||||
|
|
||||||
auto id = IdAccessor<Pathgrid>().getId(record);
|
const ESM::RefId id = getRecordId(record);
|
||||||
int index = this->searchId(id);
|
int index = this->searchId(id);
|
||||||
|
|
||||||
if (record.mPoints.empty() || record.mEdges.empty())
|
if (record.mPoints.empty() || record.mEdges.empty())
|
||||||
|
|
|
@ -24,8 +24,8 @@ namespace CSMWorld
|
||||||
struct Pathgrid;
|
struct Pathgrid;
|
||||||
|
|
||||||
/// \brief Single type collection of top level records
|
/// \brief Single type collection of top level records
|
||||||
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
|
template <typename ESXRecordT>
|
||||||
class IdCollection : public Collection<ESXRecordT, IdAccessorT>
|
class IdCollection : public Collection<ESXRecordT>
|
||||||
{
|
{
|
||||||
virtual void loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted);
|
virtual void loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted);
|
||||||
|
|
||||||
|
@ -46,14 +46,14 @@ namespace CSMWorld
|
||||||
/// \return Has the ID been deleted?
|
/// \return Has the ID been deleted?
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void IdCollection<ESXRecordT, IdAccessorT>::loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
|
void IdCollection<ESXRecordT>::loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
|
||||||
{
|
{
|
||||||
record.load(reader, isDeleted);
|
record.load(reader, isDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
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);
|
record.load(reader, isDeleted);
|
||||||
|
|
||||||
|
@ -66,15 +66,15 @@ namespace CSMWorld
|
||||||
record.mContext.filename.clear();
|
record.mContext.filename.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int IdCollection<ESXRecordT, IdAccessorT>::load(ESM::ESMReader& reader, bool base)
|
int IdCollection<ESXRecordT>::load(ESM::ESMReader& reader, bool base)
|
||||||
{
|
{
|
||||||
ESXRecordT record;
|
ESXRecordT record;
|
||||||
bool isDeleted = false;
|
bool isDeleted = false;
|
||||||
|
|
||||||
loadRecord(record, reader, isDeleted);
|
loadRecord(record, reader, isDeleted);
|
||||||
|
|
||||||
ESM::RefId id = IdAccessorT().getId(record);
|
ESM::RefId id = getRecordId(record);
|
||||||
int index = this->searchId(id);
|
int index = this->searchId(id);
|
||||||
|
|
||||||
if (isDeleted)
|
if (isDeleted)
|
||||||
|
@ -102,11 +102,11 @@ namespace CSMWorld
|
||||||
return load(record, base, index);
|
return load(record, base, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int IdCollection<ESXRecordT, IdAccessorT>::load(const ESXRecordT& record, bool base, int index)
|
int IdCollection<ESXRecordT>::load(const ESXRecordT& record, bool base, int index)
|
||||||
{
|
{
|
||||||
if (index == -2) // index unknown
|
if (index == -2) // index unknown
|
||||||
index = this->searchId(IdAccessorT().getId(record));
|
index = this->searchId(getRecordId(record));
|
||||||
|
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,7 @@ namespace CSMWorld
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// old record
|
// 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)
|
if (base)
|
||||||
record2->mBase = record;
|
record2->mBase = record;
|
||||||
|
@ -134,26 +134,26 @@ namespace CSMWorld
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
bool IdCollection<ESXRecordT, IdAccessorT>::tryDelete(const ESM::RefId& id)
|
bool IdCollection<ESXRecordT>::tryDelete(const ESM::RefId& id)
|
||||||
{
|
{
|
||||||
int index = this->searchId(id);
|
int index = this->searchId(id);
|
||||||
|
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const Record<ESXRecordT>& record = Collection<ESXRecordT, IdAccessorT>::getRecord(index);
|
const Record<ESXRecordT>& record = Collection<ESXRecordT>::getRecord(index);
|
||||||
|
|
||||||
if (record.isDeleted())
|
if (record.isDeleted())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (record.mState == RecordBase::State_ModifiedOnly)
|
if (record.mState == RecordBase::State_ModifiedOnly)
|
||||||
{
|
{
|
||||||
Collection<ESXRecordT, IdAccessorT>::removeRows(index, 1);
|
Collection<ESXRecordT>::removeRows(index, 1);
|
||||||
}
|
}
|
||||||
else
|
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;
|
record2->mState = RecordBase::State_Deleted;
|
||||||
this->setRecord(index, std::move(record2));
|
this->setRecord(index, std::move(record2));
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
int IdCollection<Pathgrid, IdAccessor<Pathgrid>>::load(ESM::ESMReader& reader, bool base);
|
int IdCollection<Pathgrid>::load(ESM::ESMReader& reader, bool base);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace CSMWorld
|
||||||
using InfosByTopic = std::unordered_map<ESM::RefId, std::vector<ESM::RefId>>;
|
using InfosByTopic = std::unordered_map<ESM::RefId, std::vector<ESM::RefId>>;
|
||||||
using InfosRecordPtrByTopic = std::unordered_map<ESM::RefId, std::vector<const Record<Info>*>>;
|
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:
|
private:
|
||||||
bool load(const Info& record, bool base);
|
bool load(const Info& record, bool base);
|
||||||
|
|
|
@ -21,16 +21,13 @@ namespace CSMWorld
|
||||||
struct ColumnBase;
|
struct ColumnBase;
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
struct IdAccessor;
|
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
|
||||||
class IdCollection;
|
class IdCollection;
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
template <typename ESXRecordT>
|
||||||
class NestedColumnAdapter;
|
class NestedColumnAdapter;
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
|
template <typename ESXRecordT>
|
||||||
class NestedIdCollection : public IdCollection<ESXRecordT, IdAccessorT>, public NestedCollection
|
class NestedIdCollection : public IdCollection<ESXRecordT>, public NestedCollection
|
||||||
{
|
{
|
||||||
std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> mAdapters;
|
std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> mAdapters;
|
||||||
|
|
||||||
|
@ -62,13 +59,13 @@ namespace CSMWorld
|
||||||
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> adapter);
|
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> adapter);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
NestedIdCollection<ESXRecordT, IdAccessorT>::NestedIdCollection()
|
NestedIdCollection<ESXRecordT>::NestedIdCollection()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
NestedIdCollection<ESXRecordT, IdAccessorT>::~NestedIdCollection()
|
NestedIdCollection<ESXRecordT>::~NestedIdCollection()
|
||||||
{
|
{
|
||||||
for (typename std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*>::iterator iter(mAdapters.begin());
|
for (typename std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*>::iterator iter(mAdapters.begin());
|
||||||
iter != mAdapters.end(); ++iter)
|
iter != mAdapters.end(); ++iter)
|
||||||
|
@ -77,16 +74,15 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void NestedIdCollection<ESXRecordT, IdAccessorT>::addAdapter(
|
void NestedIdCollection<ESXRecordT>::addAdapter(
|
||||||
std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> adapter)
|
std::pair<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*> adapter)
|
||||||
{
|
{
|
||||||
mAdapters.insert(adapter);
|
mAdapters.insert(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
const NestedColumnAdapter<ESXRecordT>& NestedIdCollection<ESXRecordT, IdAccessorT>::getAdapter(
|
const NestedColumnAdapter<ESXRecordT>& NestedIdCollection<ESXRecordT>::getAdapter(const ColumnBase& column) const
|
||||||
const ColumnBase& column) const
|
|
||||||
{
|
{
|
||||||
typename std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*>::const_iterator iter
|
typename std::map<const ColumnBase*, NestedColumnAdapter<ESXRecordT>*>::const_iterator iter
|
||||||
= mAdapters.find(&column);
|
= mAdapters.find(&column);
|
||||||
|
@ -97,83 +93,80 @@ namespace CSMWorld
|
||||||
return *iter->second;
|
return *iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void NestedIdCollection<ESXRecordT, IdAccessorT>::addNestedRow(int row, int column, int position)
|
void NestedIdCollection<ESXRecordT>::addNestedRow(int row, int column, int position)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<ESXRecordT>>();
|
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>
|
template <typename ESXRecordT>
|
||||||
void NestedIdCollection<ESXRecordT, IdAccessorT>::removeNestedRows(int row, int column, int subRow)
|
void NestedIdCollection<ESXRecordT>::removeNestedRows(int row, int column, int subRow)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<ESXRecordT>>();
|
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>
|
template <typename ESXRecordT>
|
||||||
QVariant NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedData(
|
QVariant NestedIdCollection<ESXRecordT>::getNestedData(int row, int column, int subRow, int subColumn) const
|
||||||
int row, int column, int subRow, int subColumn) const
|
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))
|
return getAdapter(Collection<ESXRecordT>::getColumn(column))
|
||||||
.getData(Collection<ESXRecordT, IdAccessorT>::getRecord(row), subRow, subColumn);
|
.getData(Collection<ESXRecordT>::getRecord(row), subRow, subColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedData(
|
void NestedIdCollection<ESXRecordT>::setNestedData(
|
||||||
int row, int column, const QVariant& data, int subRow, int subColumn)
|
int row, int column, const QVariant& data, int subRow, int subColumn)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<ESXRecordT>>();
|
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>
|
template <typename ESXRecordT>
|
||||||
CSMWorld::NestedTableWrapperBase* NestedIdCollection<ESXRecordT, IdAccessorT>::nestedTable(
|
CSMWorld::NestedTableWrapperBase* NestedIdCollection<ESXRecordT>::nestedTable(int row, int column) const
|
||||||
int row, int column) const
|
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))
|
return getAdapter(Collection<ESXRecordT>::getColumn(column)).table(Collection<ESXRecordT>::getRecord(row));
|
||||||
.table(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void NestedIdCollection<ESXRecordT, IdAccessorT>::setNestedTable(
|
void NestedIdCollection<ESXRecordT>::setNestedTable(
|
||||||
int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
|
int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<ESXRecordT>>();
|
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>
|
template <typename ESXRecordT>
|
||||||
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedRowsCount(int row, int column) const
|
int NestedIdCollection<ESXRecordT>::getNestedRowsCount(int row, int column) const
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<ESXRecordT, IdAccessorT>::getColumn(column))
|
return getAdapter(Collection<ESXRecordT>::getColumn(column))
|
||||||
.getRowsCount(Collection<ESXRecordT, IdAccessorT>::getRecord(row));
|
.getRowsCount(Collection<ESXRecordT>::getRecord(row));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
int NestedIdCollection<ESXRecordT, IdAccessorT>::getNestedColumnsCount(int row, int column) const
|
int NestedIdCollection<ESXRecordT>::getNestedColumnsCount(int row, int column) const
|
||||||
{
|
{
|
||||||
const ColumnBase& nestedColumn = Collection<ESXRecordT, IdAccessorT>::getColumn(column);
|
const ColumnBase& nestedColumn = Collection<ESXRecordT>::getColumn(column);
|
||||||
int numRecords = Collection<ESXRecordT, IdAccessorT>::getSize();
|
int numRecords = Collection<ESXRecordT>::getSize();
|
||||||
if (row >= 0 && row < numRecords)
|
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);
|
return getAdapter(nestedColumn).getColumnsCount(record);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -184,10 +177,10 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
CSMWorld::NestableColumn* NestedIdCollection<ESXRecordT, IdAccessorT>::getNestableColumn(int column)
|
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)
|
void NestedInfoCollection::addNestedRow(int row, int column, int position)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<Info>>();
|
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)
|
void NestedInfoCollection::removeNestedRows(int row, int column, int subRow)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<Info>>();
|
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
|
QVariant NestedInfoCollection::getNestedData(int row, int column, int subRow, int subColumn) const
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
|
return getAdapter(Collection<Info>::getColumn(column))
|
||||||
.getData(Collection<Info, IdAccessor<Info>>::getRecord(row), subRow, subColumn);
|
.getData(Collection<Info>::getRecord(row), subRow, subColumn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NestedInfoCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn)
|
void NestedInfoCollection::setNestedData(int row, int column, const QVariant& data, int subRow, int subColumn)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<Info>>();
|
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
|
CSMWorld::NestedTableWrapperBase* NestedInfoCollection::nestedTable(int row, int column) const
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
|
return getAdapter(Collection<Info>::getColumn(column)).table(Collection<Info>::getRecord(row));
|
||||||
.table(Collection<Info, IdAccessor<Info>>::getRecord(row));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NestedInfoCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
|
void NestedInfoCollection::setNestedTable(int row, int column, const CSMWorld::NestedTableWrapperBase& nestedTable)
|
||||||
{
|
{
|
||||||
auto record = std::make_unique<Record<Info>>();
|
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
|
int NestedInfoCollection::getNestedRowsCount(int row, int column) const
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
|
return getAdapter(Collection<Info>::getColumn(column)).getRowsCount(Collection<Info>::getRecord(row));
|
||||||
.getRowsCount(Collection<Info, IdAccessor<Info>>::getRecord(row));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int NestedInfoCollection::getNestedColumnsCount(int row, int column) const
|
int NestedInfoCollection::getNestedColumnsCount(int row, int column) const
|
||||||
{
|
{
|
||||||
return getAdapter(Collection<Info, IdAccessor<Info>>::getColumn(column))
|
return getAdapter(Collection<Info>::getColumn(column)).getColumnsCount(Collection<Info>::getRecord(row));
|
||||||
.getColumnsCount(Collection<Info, IdAccessor<Info>>::getRecord(row));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMWorld::NestableColumn* NestedInfoCollection::getNestableColumn(int column)
|
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;
|
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;
|
NestableColumn* getNestableColumn(int column) override;
|
||||||
|
|
||||||
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<Info>*> adapter);
|
void addAdapter(std::pair<const ColumnBase*, NestedColumnAdapter<Info>*> adapter);
|
||||||
|
|
|
@ -14,12 +14,9 @@ namespace ESM
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
struct Cell;
|
struct Cell;
|
||||||
template <typename T, typename AT>
|
template <typename T>
|
||||||
class IdCollection;
|
class IdCollection;
|
||||||
|
|
||||||
template <typename ESXRecordT>
|
|
||||||
struct IdAccessor;
|
|
||||||
|
|
||||||
/// \brief Wrapper for Pathgrid record
|
/// \brief Wrapper for Pathgrid record
|
||||||
///
|
///
|
||||||
/// \attention The mData.mX and mData.mY fields of the ESM::Pathgrid struct are not used.
|
/// \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;
|
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);
|
void load(ESM::ESMReader& esm, bool& isDeleted);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
template <>
|
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);
|
mRecords.erase(mRecords.begin() + index, mRecords.begin() + index + count);
|
||||||
|
|
||||||
|
@ -28,8 +28,7 @@ namespace CSMWorld
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void Collection<CellRef, IdAccessor<CellRef>>::insertRecord(
|
void Collection<CellRef>::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
|
||||||
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type)
|
|
||||||
{
|
{
|
||||||
int size = static_cast<int>(mRecords.size());
|
int size = static_cast<int>(mRecords.size());
|
||||||
if (index < 0 || index > 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)
|
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();
|
std::map<unsigned int, int>::iterator iter = mRefIndex.begin();
|
||||||
while (iter != mRefIndex.end())
|
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().mId = ESM::RefId::stringRefId(id);
|
||||||
record->get().mIdNum = extractIdNum(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)
|
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().mId = id;
|
||||||
record->get().mIdNum = extractIdNum(id.getRefIdString());
|
record->get().mIdNum = extractIdNum(id.getRefIdString());
|
||||||
|
|
||||||
Collection<CellRef, IdAccessor<CellRef>>::appendRecord(std::move(record));
|
Collection<CellRef>::appendRecord(std::move(record));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::RefCollection::cloneRecord(
|
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));
|
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)
|
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
|
int size = getAppendIndex(/*id*/ ESM::RefId(), type); // for CellRef records id is ignored
|
||||||
unsigned int idNum = static_cast<Record<CellRef>*>(record.get())->get().mIdNum;
|
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)
|
if (index < size - 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,11 +28,10 @@ namespace CSMWorld
|
||||||
struct Cell;
|
struct Cell;
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void Collection<CellRef, IdAccessor<CellRef>>::removeRows(int index, int count);
|
void Collection<CellRef>::removeRows(int index, int count);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void Collection<CellRef, IdAccessor<CellRef>>::insertRecord(
|
void Collection<CellRef>::insertRecord(std::unique_ptr<RecordBase> record, int index, UniversalId::Type type);
|
||||||
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type);
|
|
||||||
|
|
||||||
/// \brief References in cells
|
/// \brief References in cells
|
||||||
class RefCollection : public Collection<CellRef>
|
class RefCollection : public Collection<CellRef>
|
||||||
|
|
|
@ -13,26 +13,25 @@ namespace CSMWorld
|
||||||
struct Cell;
|
struct Cell;
|
||||||
|
|
||||||
/// \brief Single type collection of top level records that are associated with cells
|
/// \brief Single type collection of top level records that are associated with cells
|
||||||
template <typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT>>
|
template <typename ESXRecordT>
|
||||||
class SubCellCollection : public NestedIdCollection<ESXRecordT, IdAccessorT>
|
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;
|
void loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SubCellCollection(const IdCollection<Cell, IdAccessor<Cell>>& cells);
|
SubCellCollection(const IdCollection<Cell>& cells);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
void SubCellCollection<ESXRecordT, IdAccessorT>::loadRecord(
|
void SubCellCollection<ESXRecordT>::loadRecord(ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
|
||||||
ESXRecordT& record, ESM::ESMReader& reader, bool& isDeleted)
|
|
||||||
{
|
{
|
||||||
record.load(reader, isDeleted, mCells);
|
record.load(reader, isDeleted, mCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ESXRecordT, typename IdAccessorT>
|
template <typename ESXRecordT>
|
||||||
SubCellCollection<ESXRecordT, IdAccessorT>::SubCellCollection(const IdCollection<Cell, IdAccessor<Cell>>& cells)
|
SubCellCollection<ESXRecordT>::SubCellCollection(const IdCollection<Cell>& cells)
|
||||||
: mCells(cells)
|
: mCells(cells)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue