2012-11-26 11:29:22 +00:00
|
|
|
#ifndef CSM_WOLRD_IDCOLLECTION_H
|
|
|
|
#define CSM_WOLRD_IDCOLLECTION_H
|
|
|
|
|
2013-02-07 11:52:01 +00:00
|
|
|
#include <components/esm/esmreader.hpp>
|
|
|
|
|
2013-06-17 12:28:09 +00:00
|
|
|
#include "collection.hpp"
|
2013-02-07 11:52:01 +00:00
|
|
|
|
2012-11-26 11:29:22 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
2013-06-17 11:49:32 +00:00
|
|
|
|
2013-06-17 12:16:26 +00:00
|
|
|
/// \brief Single type collection of top level records
|
|
|
|
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
|
|
|
|
class IdCollection : public Collection<ESXRecordT, IdAccessorT>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
void load (ESM::ESMReader& reader, bool base,
|
|
|
|
UniversalId::Type type = UniversalId::Type_None);
|
|
|
|
///< \param type Will be ignored, unless the collection supports multiple record types
|
|
|
|
};
|
|
|
|
|
2013-04-16 10:12:04 +00:00
|
|
|
template<typename ESXRecordT, typename IdAccessorT>
|
2013-04-23 09:22:07 +00:00
|
|
|
void IdCollection<ESXRecordT, IdAccessorT>::load (ESM::ESMReader& reader, bool base,
|
|
|
|
UniversalId::Type type)
|
2013-02-07 11:52:01 +00:00
|
|
|
{
|
|
|
|
std::string id = reader.getHNOString ("NAME");
|
|
|
|
|
2013-02-07 12:26:00 +00:00
|
|
|
if (reader.isNextSub ("DELE"))
|
2013-02-07 11:52:01 +00:00
|
|
|
{
|
2013-06-17 12:16:26 +00:00
|
|
|
int index = Collection<ESXRecordT, IdAccessorT>::searchId (id);
|
2013-04-14 15:04:55 +00:00
|
|
|
|
2013-02-07 12:26:00 +00:00
|
|
|
reader.skipRecord();
|
2013-02-07 11:52:01 +00:00
|
|
|
|
2013-02-07 12:26:00 +00:00
|
|
|
if (index==-1)
|
|
|
|
{
|
|
|
|
// deleting a record that does not exist
|
|
|
|
|
|
|
|
// ignore it for now
|
|
|
|
|
|
|
|
/// \todo report the problem to the user
|
|
|
|
}
|
|
|
|
else if (base)
|
|
|
|
{
|
2013-06-17 12:16:26 +00:00
|
|
|
Collection<ESXRecordT, IdAccessorT>::removeRows (index, 1);
|
2013-02-07 12:26:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-17 12:16:26 +00:00
|
|
|
Record<ESXRecordT> record = Collection<ESXRecordT, IdAccessorT>::getRecord (index);
|
2013-06-17 11:49:32 +00:00
|
|
|
record.mState = RecordBase::State_Deleted;
|
2013-07-12 04:33:02 +00:00
|
|
|
this->setRecord (index, record);
|
2013-02-07 12:26:00 +00:00
|
|
|
}
|
2013-02-07 11:52:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-07 12:26:00 +00:00
|
|
|
ESXRecordT record;
|
2013-04-16 10:12:04 +00:00
|
|
|
IdAccessorT().getId (record) = id;
|
2013-02-07 12:26:00 +00:00
|
|
|
record.load (reader);
|
|
|
|
|
2013-07-12 04:33:02 +00:00
|
|
|
int index = this->searchId (IdAccessorT().getId (record));
|
2013-04-14 15:04:55 +00:00
|
|
|
|
2013-02-07 12:26:00 +00:00
|
|
|
if (index==-1)
|
|
|
|
{
|
|
|
|
// new record
|
|
|
|
Record<ESXRecordT> record2;
|
|
|
|
record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
|
|
|
(base ? record2.mBase : record2.mModified) = record;
|
2013-02-07 11:52:01 +00:00
|
|
|
|
2013-07-12 04:33:02 +00:00
|
|
|
this->appendRecord (record2);
|
2013-02-07 12:26:00 +00:00
|
|
|
}
|
2013-02-07 11:52:01 +00:00
|
|
|
else
|
2013-02-07 12:26:00 +00:00
|
|
|
{
|
|
|
|
// old record
|
2013-06-17 12:16:26 +00:00
|
|
|
Record<ESXRecordT> record2 = Collection<ESXRecordT, IdAccessorT>::getRecord (index);
|
2013-02-07 12:26:00 +00:00
|
|
|
|
|
|
|
if (base)
|
|
|
|
record2.mBase = record;
|
|
|
|
else
|
|
|
|
record2.setModified (record);
|
2013-06-17 11:49:32 +00:00
|
|
|
|
2013-07-12 04:33:02 +00:00
|
|
|
this->setRecord (index, record2);
|
2013-02-07 12:26:00 +00:00
|
|
|
}
|
2013-02-07 11:52:01 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|