1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 02:53:54 +00:00
openmw/apps/opencs/model/world/refcollection.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

82 lines
2.3 KiB
C++

#ifndef CSM_WOLRD_REFCOLLECTION_H
#define CSM_WOLRD_REFCOLLECTION_H
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <apps/opencs/model/world/universalid.hpp>
#include "collection.hpp"
#include "record.hpp"
#include "ref.hpp"
namespace ESM
{
class ESMReader;
}
namespace CSMDoc
{
class Messages;
}
namespace CSMWorld
{
struct Cell;
template <>
void Collection<CellRef, IdAccessor<CellRef>>::removeRows(int index, int count);
template <>
void Collection<CellRef, IdAccessor<CellRef>>::insertRecord(
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type);
/// \brief References in cells
class RefCollection : public Collection<CellRef>
{
Collection<Cell>& mCells;
std::map<unsigned int, int> mRefIndex; // CellRef index keyed by CSMWorld::CellRef::mIdNum
int mNextId;
unsigned int extractIdNum(std::string_view id) const;
int getIntIndex(unsigned int id) const;
int searchId(unsigned int id) const;
public:
// MSVC needs the constructor for a class inheriting a template to be defined in header
RefCollection(Collection<Cell>& cells)
: mCells(cells)
, mNextId(0)
{
}
void load(ESM::ESMReader& reader, int cellIndex, bool base, std::map<unsigned int, unsigned int>& cache,
CSMDoc::Messages& messages);
///< Load a sequence of references.
std::string getNewId();
virtual void removeRows(int index, int count);
virtual void appendBlankRecord(const std::string& id, UniversalId::Type type = UniversalId::Type_None);
virtual void appendBlankRecord(const ESM::RefId& id, UniversalId::Type type = UniversalId::Type_None);
virtual void cloneRecord(const ESM::RefId& origin, const ESM::RefId& destination, const UniversalId::Type type);
virtual int searchId(std::string_view id) const;
virtual int searchId(const ESM::RefId& id) const;
virtual void appendRecord(std::unique_ptr<RecordBase> record, UniversalId::Type type = UniversalId::Type_None);
virtual void insertRecord(
std::unique_ptr<RecordBase> record, int index, UniversalId::Type type = UniversalId::Type_None);
};
}
#endif