1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 15:39:02 +00:00
OpenMW/apps/opencs/model/world/refidadapter.hpp
florent.teppe 65cdd489fb create a specific esm reader function for RefID to avoid allocation for string and then again for RefId
Fixed some types

removed useless header

applied clang format

fixed compile tests

fixed clang tidy, and closer to logic before this MR

Removed hardcoded refids

unless there is a returned value we don't use static RefIds
can use == between RefId and hardcoded string

Fix clang format

Fixed a few instances where std::string was used, when only const std::string& was needed

removed unused variable
2022-12-27 19:15:57 +01:00

78 lines
2.8 KiB
C++

#ifndef CSM_WOLRD_REFIDADAPTER_H
#define CSM_WOLRD_REFIDADAPTER_H
#include <components/esm/refid.hpp>
#include <string>
#include <vector>
/*! \brief
* Adapters acts as indirection layer, abstracting details of the record types (in the wrappers) from the higher levels
* of model. Please notice that nested adaptor uses helper classes for actually performing any actions. Different record
* types require different helpers (needs to be created in the subclass and then fetched via member function).
*
* Important point: don't forget to make sure that getData on the nestedColumn returns true (otherwise code will not
* treat the index pointing to the column as having children!
*/
class QVariant;
namespace CSMWorld
{
class RefIdColumn;
class RefIdData;
struct RecordBase;
struct NestedTableWrapperBase;
class RefIdAdapter
{
// not implemented
RefIdAdapter(const RefIdAdapter&);
RefIdAdapter& operator=(const RefIdAdapter&);
public:
RefIdAdapter();
virtual ~RefIdAdapter();
virtual QVariant getData(const RefIdColumn* column, const RefIdData& data, int idnex) const = 0;
///< If called on the nest column, should return QVariant(true).
virtual void setData(const RefIdColumn* column, RefIdData& data, int index, const QVariant& value) const = 0;
///< If the data type does not match an exception is thrown.
virtual ESM::RefId getId(const RecordBase& record) const = 0;
virtual void setId(RecordBase& record, const std::string& id) = 0; // used by RefIdCollection::cloneRecord()
};
class NestedRefIdAdapterBase
{
public:
NestedRefIdAdapterBase();
virtual ~NestedRefIdAdapterBase();
virtual void setNestedData(const RefIdColumn* column, RefIdData& data, int row, const QVariant& value,
int subRowIndex, int subColIndex) const = 0;
virtual QVariant getNestedData(
const RefIdColumn* column, const RefIdData& data, int index, int subRowIndex, int subColIndex) const = 0;
virtual int getNestedColumnsCount(const RefIdColumn* column, const RefIdData& data) const = 0;
virtual int getNestedRowsCount(const RefIdColumn* column, const RefIdData& data, int index) const = 0;
virtual void removeNestedRow(const RefIdColumn* column, RefIdData& data, int index, int rowToRemove) const = 0;
virtual void addNestedRow(const RefIdColumn* column, RefIdData& data, int index, int position) const = 0;
virtual void setNestedTable(
const RefIdColumn* column, RefIdData& data, int index, const NestedTableWrapperBase& nestedTable) const = 0;
virtual NestedTableWrapperBase* nestedTable(
const RefIdColumn* column, const RefIdData& data, int index) const = 0;
};
}
#endif