added overloaded start/endRecord functions to ESMWriter

This commit is contained in:
Marc Zinnschlag 2013-12-01 13:32:11 +01:00
parent eec9821cd8
commit 16e2d67b1f
5 changed files with 30 additions and 24 deletions

View file

@ -133,16 +133,10 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, std::vector<std::
state==CSMWorld::RecordBase::State_ModifiedOnly || state==CSMWorld::RecordBase::State_ModifiedOnly ||
infoModified) infoModified)
{ {
// always write the topic record mState.getWriter().startRecord (topic.mModified.sRecordId);
std::string type;
for (int i=0; i<4; ++i)
/// \todo make endianess agnostic (change ESMWriter interface?)
type += reinterpret_cast<const char *> (&topic.mModified.sRecordId)[i];
mState.getWriter().startRecord (type);
mState.getWriter().writeHNCString ("NAME", topic.mModified.mId); mState.getWriter().writeHNCString ("NAME", topic.mModified.mId);
topic.mModified.save (mState.getWriter()); topic.mModified.save (mState.getWriter());
mState.getWriter().endRecord (type); mState.getWriter().endRecord (topic.mModified.sRecordId);
// write modified selected info records // write modified selected info records
for (CSMWorld::InfoCollection::RecordConstIterator iter (range.first); iter!=range.second; for (CSMWorld::InfoCollection::RecordConstIterator iter (range.first); iter!=range.second;
@ -178,15 +172,10 @@ void CSMDoc::WriteDialogueCollectionStage::perform (int stage, std::vector<std::
next->mModified.mId.substr (next->mModified.mId.find_last_of ('#')+1); next->mModified.mId.substr (next->mModified.mId.find_last_of ('#')+1);
} }
std::string type; mState.getWriter().startRecord (info.sRecordId);
for (int i=0; i<4; ++i)
/// \todo make endianess agnostic (change ESMWriter interface?)
type += reinterpret_cast<const char *> (&info.sRecordId)[i];
mState.getWriter().startRecord (type);
mState.getWriter().writeHNCString ("INAM", info.mId); mState.getWriter().writeHNCString ("INAM", info.mId);
info.save (mState.getWriter()); info.save (mState.getWriter());
mState.getWriter().endRecord (type); mState.getWriter().endRecord (info.sRecordId);
} }
} }
} }

View file

@ -104,10 +104,10 @@ namespace CSMDoc
/// \todo make endianess agnostic (change ESMWriter interface?) /// \todo make endianess agnostic (change ESMWriter interface?)
type += reinterpret_cast<const char *> (&mCollection.getRecord (stage).mModified.sRecordId)[i]; type += reinterpret_cast<const char *> (&mCollection.getRecord (stage).mModified.sRecordId)[i];
mState.getWriter().startRecord (type); mState.getWriter().startRecord (mCollection.getRecord (stage).mModified.sRecordId);
mState.getWriter().writeHNCString ("NAME", mCollection.getId (stage)); mState.getWriter().writeHNCString ("NAME", mCollection.getId (stage));
mCollection.getRecord (stage).mModified.save (mState.getWriter()); mCollection.getRecord (stage).mModified.save (mState.getWriter());
mState.getWriter().endRecord (type); mState.getWriter().endRecord (mCollection.getRecord (stage).mModified.sRecordId);
} }
else if (state==CSMWorld::RecordBase::State_Deleted) else if (state==CSMWorld::RecordBase::State_Deleted)
{ {

View file

@ -136,15 +136,10 @@ namespace CSMWorld
if (state==CSMWorld::RecordBase::State_Modified || if (state==CSMWorld::RecordBase::State_Modified ||
state==CSMWorld::RecordBase::State_ModifiedOnly) state==CSMWorld::RecordBase::State_ModifiedOnly)
{ {
std::string type; writer.startRecord (mContainer.at (index).mModified.sRecordId);
for (int i=0; i<4; ++i)
/// \todo make endianess agnostic (change ESMWriter interface?)
type += reinterpret_cast<const char *> (&mContainer.at (index).mModified.sRecordId)[i];
writer.startRecord (type);
writer.writeHNCString ("NAME", getId (index)); writer.writeHNCString ("NAME", getId (index));
mContainer.at (index).mModified.save (writer); mContainer.at (index).mModified.save (writer);
writer.endRecord (type); writer.endRecord (mContainer.at (index).mModified.sRecordId);
} }
else if (state==CSMWorld::RecordBase::State_Deleted) else if (state==CSMWorld::RecordBase::State_Deleted)
{ {

View file

@ -88,6 +88,16 @@ namespace ESM
assert(mRecords.back().size == 0); assert(mRecords.back().size == 0);
} }
void ESMWriter::startRecord (uint32_t name, uint32_t flags)
{
std::string type;
for (int i=0; i<4; ++i)
/// \todo make endianess agnostic
type += reinterpret_cast<const char *> (&name)[i];
startRecord (type, flags);
}
void ESMWriter::startSubRecord(const std::string& name) void ESMWriter::startSubRecord(const std::string& name)
{ {
writeName(name); writeName(name);
@ -117,6 +127,16 @@ namespace ESM
} }
void ESMWriter::endRecord (uint32_t name)
{
std::string type;
for (int i=0; i<4; ++i)
/// \todo make endianess agnostic
type += reinterpret_cast<const char *> (&name)[i];
endRecord (type);
}
void ESMWriter::writeHNString(const std::string& name, const std::string& data) void ESMWriter::writeHNString(const std::string& name, const std::string& data)
{ {
startSubRecord(name); startSubRecord(name);

View file

@ -90,8 +90,10 @@ class ESMWriter
} }
void startRecord(const std::string& name, uint32_t flags = 0); void startRecord(const std::string& name, uint32_t flags = 0);
void startRecord(uint32_t name, uint32_t flags = 0);
void startSubRecord(const std::string& name); void startSubRecord(const std::string& name);
void endRecord(const std::string& name); void endRecord(const std::string& name);
void endRecord(uint32_t name);
void writeHString(const std::string& data); void writeHString(const std::string& data);
void writeHCString(const std::string& data); void writeHCString(const std::string& data);
void writeName(const std::string& data); void writeName(const std::string& data);