1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-20 09:53:51 +00:00

moved IdCollection base into its own source file pair and renamed it to Collection

This commit is contained in:
Marc Zinnschlag 2013-06-17 11:42:02 +02:00
parent 97f421df8a
commit f4e7916ec4
11 changed files with 109 additions and 87 deletions

View file

@ -24,7 +24,7 @@ opencs_units (model/world
opencs_units_noqt (model/world opencs_units_noqt (model/world
universalid data record idcollection commands columnbase scriptcontext cell refidcollection universalid data record idcollection commands columnbase scriptcontext cell refidcollection
refidadapter refiddata refidadapterimp ref refidadapter refiddata refidadapterimp ref collectionbase
) )
opencs_hdrs_noqt (model/world opencs_hdrs_noqt (model/world

View file

@ -1,9 +1,11 @@
#include "mandatoryid.hpp" #include "mandatoryid.hpp"
#include "../world/idcollection.hpp" #include "../world/collectionbase.hpp"
CSMTools::MandatoryIdStage::MandatoryIdStage (const CSMWorld::IdCollectionBase& idCollection, #include "../world/record.hpp"
CSMTools::MandatoryIdStage::MandatoryIdStage (const CSMWorld::CollectionBase& idCollection,
const CSMWorld::UniversalId& collectionId, const std::vector<std::string>& ids) const CSMWorld::UniversalId& collectionId, const std::vector<std::string>& ids)
: mIdCollection (idCollection), mCollectionId (collectionId), mIds (ids) : mIdCollection (idCollection), mCollectionId (collectionId), mIds (ids)
{} {}

View file

@ -10,7 +10,7 @@
namespace CSMWorld namespace CSMWorld
{ {
class IdCollectionBase; class CollectionBase;
} }
namespace CSMTools namespace CSMTools
@ -18,13 +18,13 @@ namespace CSMTools
/// \brief Verify stage: make sure that records with specific IDs exist. /// \brief Verify stage: make sure that records with specific IDs exist.
class MandatoryIdStage : public Stage class MandatoryIdStage : public Stage
{ {
const CSMWorld::IdCollectionBase& mIdCollection; const CSMWorld::CollectionBase& mIdCollection;
CSMWorld::UniversalId mCollectionId; CSMWorld::UniversalId mCollectionId;
std::vector<std::string> mIds; std::vector<std::string> mIds;
public: public:
MandatoryIdStage (const CSMWorld::IdCollectionBase& idCollection, const CSMWorld::UniversalId& collectionId, MandatoryIdStage (const CSMWorld::CollectionBase& idCollection, const CSMWorld::UniversalId& collectionId,
const std::vector<std::string>& ids); const std::vector<std::string>& ids);
virtual int setup(); virtual int setup();

View file

@ -0,0 +1,6 @@
#include "collectionbase.hpp"
CSMWorld::CollectionBase::CollectionBase() {}
CSMWorld::CollectionBase::~CollectionBase() {}

View file

@ -0,0 +1,80 @@
#ifndef CSM_WOLRD_COLLECTIONBASE_H
#define CSM_WOLRD_COLLECTIONBASE_H
#include <string>
#include "universalid.hpp"
class QVariant;
namespace CSMWorld
{
struct ColumnBase;
struct RecordBase;
/// \brief Base class for record collections
class CollectionBase
{
// not implemented
CollectionBase (const CollectionBase&);
CollectionBase& operator= (const CollectionBase&);
public:
CollectionBase();
virtual ~CollectionBase();
virtual int getSize() const = 0;
virtual std::string getId (int index) const = 0;
virtual int getIndex (const std::string& id) const = 0;
virtual int getColumns() const = 0;
virtual const ColumnBase& getColumn (int column) const = 0;
virtual QVariant getData (int index, int column) const = 0;
virtual void setData (int index, int column, const QVariant& data) = 0;
// Not in use. Temporarily removed so that the implementation of RefIdCollection can continue without
// these functions for now.
// virtual void merge() = 0;
///< Merge modified into base.
// virtual void purge() = 0;
///< Remove records that are flagged as erased.
virtual void removeRows (int index, int count) = 0;
virtual void appendBlankRecord (const std::string& id,
UniversalId::Type type = UniversalId::Type_None) = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
virtual int searchId (const std::string& id) const = 0;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
virtual void replace (int index, const RecordBase& record) = 0;
///< If the record type does not match, an exception is thrown.
///
/// \attention \a record must not change the ID.
///< \param type Will be ignored, unless the collection supports multiple record types
virtual void appendRecord (const RecordBase& record,
UniversalId::Type type = UniversalId::Type_None) = 0;
///< If the record type does not match, an exception is thrown.
virtual const RecordBase& getRecord (const std::string& id) const = 0;
virtual const RecordBase& getRecord (int index) const = 0;
virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
};
}
#endif

View file

@ -1,6 +1,3 @@
#include "idcollection.hpp" #include "idcollection.hpp"
CSMWorld::IdCollectionBase::IdCollectionBase() {}
CSMWorld::IdCollectionBase::~IdCollectionBase() {}

View file

@ -3,7 +3,6 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <string>
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
#include <stdexcept> #include <stdexcept>
@ -16,77 +15,12 @@
#include <components/misc/stringops.hpp> #include <components/misc/stringops.hpp>
#include "columnbase.hpp" #include "columnbase.hpp"
#include "universalid.hpp"
#include "collectionbase.hpp"
namespace CSMWorld namespace CSMWorld
{ {
class IdCollectionBase /// \brief Access to ID field in records
{
// not implemented
IdCollectionBase (const IdCollectionBase&);
IdCollectionBase& operator= (const IdCollectionBase&);
public:
IdCollectionBase();
virtual ~IdCollectionBase();
virtual int getSize() const = 0;
virtual std::string getId (int index) const = 0;
virtual int getIndex (const std::string& id) const = 0;
virtual int getColumns() const = 0;
virtual const ColumnBase& getColumn (int column) const = 0;
virtual QVariant getData (int index, int column) const = 0;
virtual void setData (int index, int column, const QVariant& data) = 0;
// Not in use. Temporarily removed so that the implementation of RefIdCollection can continue without
// these functions for now.
// virtual void merge() = 0;
///< Merge modified into base.
// virtual void purge() = 0;
///< Remove records that are flagged as erased.
virtual void removeRows (int index, int count) = 0;
virtual void appendBlankRecord (const std::string& id,
UniversalId::Type type = UniversalId::Type_None) = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
virtual int searchId (const std::string& id) const = 0;
////< Search record with \a id.
/// \return index of record (if found) or -1 (not found)
virtual void replace (int index, const RecordBase& record) = 0;
///< If the record type does not match, an exception is thrown.
///
/// \attention \a record must not change the ID.
///< \param type Will be ignored, unless the collection supports multiple record types
virtual void appendRecord (const RecordBase& record,
UniversalId::Type type = UniversalId::Type_None) = 0;
///< If the record type does not match, an exception is thrown.
virtual const RecordBase& getRecord (const std::string& id) const = 0;
virtual const RecordBase& getRecord (int index) const = 0;
virtual void load (ESM::ESMReader& reader, bool base,
UniversalId::Type type = UniversalId::Type_None) = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
virtual int getAppendIndex (UniversalId::Type type = UniversalId::Type_None) const = 0;
///< \param type Will be ignored, unless the collection supports multiple record types
};
///< \brief Access to ID field in records
template<typename ESXRecordT> template<typename ESXRecordT>
struct IdAccessor struct IdAccessor
{ {
@ -109,7 +43,7 @@ namespace CSMWorld
///< \brief Collection of ID-based records ///< \brief Collection of ID-based records
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> > template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class IdCollection : public IdCollectionBase class IdCollection : public CollectionBase
{ {
std::vector<Record<ESXRecordT> > mRecords; std::vector<Record<ESXRecordT> > mRecords;
std::map<std::string, int> mIndex; std::map<std::string, int> mIndex;

View file

@ -1,9 +1,10 @@
#include "idtable.hpp" #include "idtable.hpp"
#include "idcollection.hpp" #include "collectionbase.hpp"
#include "columnbase.hpp"
CSMWorld::IdTable::IdTable (IdCollectionBase *idCollection) : mIdCollection (idCollection) CSMWorld::IdTable::IdTable (CollectionBase *idCollection) : mIdCollection (idCollection)
{ {
} }

View file

@ -5,14 +5,14 @@
namespace CSMWorld namespace CSMWorld
{ {
class IdCollectionBase; class CollectionBase;
class RecordBase; class RecordBase;
class IdTable : public QAbstractItemModel class IdTable : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
IdCollectionBase *mIdCollection; CollectionBase *mIdCollection;
// not implemented // not implemented
IdTable (const IdTable&); IdTable (const IdTable&);
@ -20,7 +20,7 @@ namespace CSMWorld
public: public:
IdTable (IdCollectionBase *idCollection); IdTable (CollectionBase *idCollection);
///< The ownership of \a idCollection is not transferred. ///< The ownership of \a idCollection is not transferred.
virtual ~IdTable(); virtual ~IdTable();

View file

@ -3,6 +3,8 @@
#include <stdexcept> #include <stdexcept>
#include <components/esm/esmreader.hpp>
#include "refidadapter.hpp" #include "refidadapter.hpp"
#include "refidadapterimp.hpp" #include "refidadapterimp.hpp"

View file

@ -6,7 +6,7 @@
#include <deque> #include <deque>
#include "columnbase.hpp" #include "columnbase.hpp"
#include "idcollection.hpp" #include "collectionbase.hpp"
#include "refiddata.hpp" #include "refiddata.hpp"
namespace CSMWorld namespace CSMWorld
@ -29,7 +29,7 @@ namespace CSMWorld
virtual bool isUserEditable() const; virtual bool isUserEditable() const;
}; };
class RefIdCollection : public IdCollectionBase class RefIdCollection : public CollectionBase
{ {
private: private:
@ -85,7 +85,7 @@ namespace CSMWorld
virtual const RecordBase& getRecord (int index) const; virtual const RecordBase& getRecord (int index) const;
virtual void load (ESM::ESMReader& reader, bool base, UniversalId::Type type); void load (ESM::ESMReader& reader, bool base, UniversalId::Type type);
virtual int getAppendIndex (UniversalId::Type type) const; virtual int getAppendIndex (UniversalId::Type type) const;
///< \param type Will be ignored, unless the collection supports multiple record types ///< \param type Will be ignored, unless the collection supports multiple record types