Use ESM::RefId as key for SavingState::mSubRecords

depth-refraction
elsid 2 years ago
parent 0d25656d81
commit 3c9dbb11cc
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -236,7 +236,7 @@ CSMDoc::CollectionReferencesStage::CollectionReferencesStage(Document& document,
int CSMDoc::CollectionReferencesStage::setup()
{
mState.getSubRecords().clear();
mState.clearSubRecords();
int size = mDocument.getData().getReferences().getSize();
@ -260,7 +260,7 @@ void CSMDoc::CollectionReferencesStage::perform(int stage, Messages& messages)
const ESM::RefId& cellId
= record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell;
std::deque<int>& indices = mState.getSubRecords()[cellId.getRefIdString()];
std::deque<int>& indices = mState.getOrInsertSubRecord(cellId);
// collect moved references at the end of the container
const bool interior = !cellId.startsWith("#");
@ -360,11 +360,9 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages)
std::deque<int> tempRefs;
std::deque<int> persistentRefs;
std::map<std::string, std::deque<int>>::const_iterator references
= mState.getSubRecords().find(cell.get().mId.getRefIdString());
const std::deque<int>* references = mState.findSubRecord(cell.get().mId);
if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted
|| references != mState.getSubRecords().end())
if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted || references != nullptr)
{
CSMWorld::Cell cellRecord = cell.get();
const bool interior = !cellRecord.mId.startsWith("#");
@ -372,10 +370,9 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages)
// count new references and adjust RefNumCount accordingsly
unsigned int newRefNum = cellRecord.mRefNumCounter;
if (references != mState.getSubRecords().end())
if (references != nullptr)
{
for (std::deque<int>::const_iterator iter(references->second.begin()); iter != references->second.end();
++iter)
for (std::deque<int>::const_iterator iter(references->begin()); iter != references->end(); ++iter)
{
const CSMWorld::Record<CSMWorld::CellRef>& ref = mDocument.getData().getReferences().getRecord(*iter);
@ -421,10 +418,10 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages)
cellRecord.save(writer, cell.mState == CSMWorld::RecordBase::State_Deleted);
// write references
if (references != mState.getSubRecords().end())
if (references != nullptr)
{
writeReferences(persistentRefs, interior, newRefNum);
cellRecord.saveTempMarker(writer, int(references->second.size()) - persistentRefs.size());
cellRecord.saveTempMarker(writer, static_cast<int>(references->size()) - persistentRefs.size());
writeReferences(tempRefs, interior, newRefNum);
}

@ -68,7 +68,20 @@ bool CSMDoc::SavingState::isProjectFile() const
return mProjectFile;
}
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp>& CSMDoc::SavingState::getSubRecords()
const std::deque<int>* CSMDoc::SavingState::findSubRecord(const ESM::RefId& refId) const
{
return mSubRecords;
const auto it = mSubRecords.find(refId);
if (it == mSubRecords.end())
return nullptr;
return &it->second;
}
std::deque<int>& CSMDoc::SavingState::getOrInsertSubRecord(const ESM::RefId& refId)
{
return mSubRecords[refId];
}
void CSMDoc::SavingState::clearSubRecords()
{
mSubRecords.clear();
}

@ -8,9 +8,9 @@
#include <string>
#include <components/esm3/esmwriter.hpp>
#include <components/misc/algorithm.hpp>
#include <components/to_utf8/to_utf8.hpp>
namespace CSMDoc
{
class Operation;
@ -26,7 +26,7 @@ namespace CSMDoc
ESM::ESMWriter mWriter;
std::filesystem::path mProjectPath;
bool mProjectFile;
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp> mSubRecords; // record ID, list of subrecords
std::map<ESM::RefId, std::deque<int>> mSubRecords; // record ID, list of subrecords
public:
SavingState(Operation& operation, std::filesystem::path projectPath, ToUTF8::FromType encoding);
@ -47,7 +47,11 @@ namespace CSMDoc
bool isProjectFile() const;
///< Currently saving project file? (instead of content file)
std::map<std::string, std::deque<int>, Misc::StringUtils::CiComp>& getSubRecords();
const std::deque<int>* findSubRecord(const ESM::RefId& refId) const;
std::deque<int>& getOrInsertSubRecord(const ESM::RefId& refId);
void clearSubRecords();
};
}

Loading…
Cancel
Save