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

pull/16/head
Marc Zinnschlag 12 years ago
parent 97f421df8a
commit f4e7916ec4

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

@ -1,9 +1,11 @@
#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)
: mIdCollection (idCollection), mCollectionId (collectionId), mIds (ids)
{}

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

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

@ -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

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

@ -3,7 +3,6 @@
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <cctype>
#include <stdexcept>
@ -16,77 +15,12 @@
#include <components/misc/stringops.hpp>
#include "columnbase.hpp"
#include "universalid.hpp"
#include "collectionbase.hpp"
namespace CSMWorld
{
class IdCollectionBase
{
// 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
/// \brief Access to ID field in records
template<typename ESXRecordT>
struct IdAccessor
{
@ -109,7 +43,7 @@ namespace CSMWorld
///< \brief Collection of ID-based records
template<typename ESXRecordT, typename IdAccessorT = IdAccessor<ESXRecordT> >
class IdCollection : public IdCollectionBase
class IdCollection : public CollectionBase
{
std::vector<Record<ESXRecordT> > mRecords;
std::map<std::string, int> mIndex;

@ -1,9 +1,10 @@
#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)
{
}

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

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

@ -6,7 +6,7 @@
#include <deque>
#include "columnbase.hpp"
#include "idcollection.hpp"
#include "collectionbase.hpp"
#include "refiddata.hpp"
namespace CSMWorld
@ -29,7 +29,7 @@ namespace CSMWorld
virtual bool isUserEditable() const;
};
class RefIdCollection : public IdCollectionBase
class RefIdCollection : public CollectionBase
{
private:
@ -85,7 +85,7 @@ namespace CSMWorld
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;
///< \param type Will be ignored, unless the collection supports multiple record types

Loading…
Cancel
Save