|
@@ -10,6 +10,7 @@
|
|
|
#pragma once
|
|
|
|
|
|
#include "NumericConstants.h"
|
|
|
+#include "IdentifierBase.h"
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
@@ -35,62 +36,6 @@ class CNonConstInfoCallback;
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-class IdentifierBase
|
|
|
-{
|
|
|
-protected:
|
|
|
- constexpr IdentifierBase():
|
|
|
- num(-1)
|
|
|
- {}
|
|
|
-
|
|
|
- explicit constexpr IdentifierBase(int32_t value):
|
|
|
- num(value)
|
|
|
- {}
|
|
|
-
|
|
|
- ~IdentifierBase() = default;
|
|
|
-public:
|
|
|
- int32_t num;
|
|
|
-
|
|
|
- constexpr int32_t getNum() const
|
|
|
- {
|
|
|
- return num;
|
|
|
- }
|
|
|
-
|
|
|
- constexpr void setNum(int32_t value)
|
|
|
- {
|
|
|
- num = value;
|
|
|
- }
|
|
|
-
|
|
|
- struct hash
|
|
|
- {
|
|
|
- size_t operator()(const IdentifierBase & id) const
|
|
|
- {
|
|
|
- return std::hash<int>()(id.num);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
- {
|
|
|
- h & num;
|
|
|
- }
|
|
|
-
|
|
|
- constexpr void advance(int change)
|
|
|
- {
|
|
|
- num += change;
|
|
|
- }
|
|
|
-
|
|
|
- constexpr operator int32_t () const
|
|
|
- {
|
|
|
- return num;
|
|
|
- }
|
|
|
-
|
|
|
- friend std::ostream& operator<<(std::ostream& os, const IdentifierBase& dt)
|
|
|
- {
|
|
|
- return os << dt.num;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
-
|
|
|
// Note: use template to force different type, blocking any Identifier<A> <=> Identifier<B> comparisons
|
|
|
template<typename FinalClass>
|
|
|
class Identifier : public IdentifierBase
|
|
@@ -739,18 +684,18 @@ public:
|
|
|
DLL_LINKAGE const Creature * toCreature(const CreatureService * creatures) const;
|
|
|
};
|
|
|
|
|
|
-class CreatureID : public IdentifierWithEnum<CreatureID, CreatureIDBase>
|
|
|
+class DLL_LINKAGE CreatureID : public IdentifierWithEnum<CreatureID, CreatureIDBase>
|
|
|
{
|
|
|
public:
|
|
|
using IdentifierWithEnum<CreatureID, CreatureIDBase>::IdentifierWithEnum;
|
|
|
|
|
|
///json serialization helpers
|
|
|
- DLL_LINKAGE static si32 decode(const std::string & identifier);
|
|
|
- DLL_LINKAGE static std::string encode(const si32 index);
|
|
|
+ static si32 decode(const std::string & identifier);
|
|
|
+ static std::string encode(const si32 index);
|
|
|
static std::string entityType();
|
|
|
};
|
|
|
|
|
|
-class SpellIDBase : public IdentifierBase
|
|
|
+class DLL_LINKAGE SpellIDBase : public IdentifierBase
|
|
|
{
|
|
|
public:
|
|
|
enum Type
|
|
@@ -853,18 +798,18 @@ public:
|
|
|
AFTER_LAST = 82
|
|
|
};
|
|
|
|
|
|
- DLL_LINKAGE const CSpell * toSpell() const; //deprecated
|
|
|
- DLL_LINKAGE const spells::Spell * toSpell(const spells::Service * service) const;
|
|
|
+ const CSpell * toSpell() const; //deprecated
|
|
|
+ const spells::Spell * toSpell(const spells::Service * service) const;
|
|
|
};
|
|
|
|
|
|
-class SpellID : public IdentifierWithEnum<SpellID, SpellIDBase>
|
|
|
+class DLL_LINKAGE SpellID : public IdentifierWithEnum<SpellID, SpellIDBase>
|
|
|
{
|
|
|
public:
|
|
|
using IdentifierWithEnum<SpellID, SpellIDBase>::IdentifierWithEnum;
|
|
|
|
|
|
///json serialization helpers
|
|
|
- DLL_LINKAGE static si32 decode(const std::string & identifier);
|
|
|
- DLL_LINKAGE static std::string encode(const si32 index);
|
|
|
+ static si32 decode(const std::string & identifier);
|
|
|
+ static std::string encode(const si32 index);
|
|
|
static std::string entityType();
|
|
|
};
|
|
|
|
|
@@ -941,8 +886,8 @@ public:
|
|
|
static const SpellSchool WATER;
|
|
|
static const SpellSchool EARTH;
|
|
|
|
|
|
- DLL_LINKAGE static si32 decode(const std::string & identifier);
|
|
|
- DLL_LINKAGE static std::string encode(const si32 index);
|
|
|
+ static si32 decode(const std::string & identifier);
|
|
|
+ static std::string encode(const si32 index);
|
|
|
static std::string entityType();
|
|
|
};
|
|
|
|
|
@@ -966,13 +911,13 @@ public:
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-class GameResID : public IdentifierWithEnum<GameResID, GameResIDBase>
|
|
|
+class DLL_LINKAGE GameResID : public IdentifierWithEnum<GameResID, GameResIDBase>
|
|
|
{
|
|
|
public:
|
|
|
using IdentifierWithEnum<GameResID, GameResIDBase>::IdentifierWithEnum;
|
|
|
|
|
|
- DLL_LINKAGE static si32 decode(const std::string & identifier);
|
|
|
- DLL_LINKAGE static std::string encode(const si32 index);
|
|
|
+ static si32 decode(const std::string & identifier);
|
|
|
+ static std::string encode(const si32 index);
|
|
|
static std::string entityType();
|
|
|
};
|
|
|
|
|
@@ -984,85 +929,4 @@ using River = RiverId;
|
|
|
using Road = RoadId;
|
|
|
using ETerrainId = TerrainId;
|
|
|
|
|
|
-/// This class represents field that may contain value of multiple different identifer types
|
|
|
-class MetaIdentifier
|
|
|
-{
|
|
|
- std::string entityType;
|
|
|
- std::string stringForm;
|
|
|
- int32_t integerForm;
|
|
|
-
|
|
|
- void onDeserialized();
|
|
|
-public:
|
|
|
-
|
|
|
- static const MetaIdentifier NONE;
|
|
|
-
|
|
|
- MetaIdentifier():
|
|
|
- integerForm(-1)
|
|
|
- {}
|
|
|
-
|
|
|
- explicit MetaIdentifier(const std::string & entityType, const std::string & identifier)
|
|
|
- : entityType(entityType)
|
|
|
- , stringForm(identifier)
|
|
|
- , integerForm(-1)
|
|
|
- {
|
|
|
- onDeserialized();
|
|
|
- }
|
|
|
-
|
|
|
- explicit MetaIdentifier(const std::string & entityType, const std::string & identifier, int32_t value)
|
|
|
- : entityType(entityType)
|
|
|
- , stringForm(identifier)
|
|
|
- , integerForm(value)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- template<typename IdentifierType>
|
|
|
- explicit MetaIdentifier(const IdentifierType & identifier )
|
|
|
- : entityType(IdentifierType::entityType())
|
|
|
- , integerForm(identifier.getNum())
|
|
|
- , stringForm(IdentifierType::encode(identifier.getNum()))
|
|
|
- {
|
|
|
- static_assert(std::is_base_of<IdentifierBase, IdentifierType>::value, "MetaIdentifier can only be constructed from Identifer class");
|
|
|
- }
|
|
|
-
|
|
|
- int32_t getNum() const
|
|
|
- {
|
|
|
- return integerForm;
|
|
|
- }
|
|
|
-
|
|
|
- std::string toString() const
|
|
|
- {
|
|
|
- return stringForm;
|
|
|
- }
|
|
|
-
|
|
|
- template<typename IdentifierType>
|
|
|
- IdentifierType as() const
|
|
|
- {
|
|
|
- IdentifierType result(integerForm);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
- {
|
|
|
- h & stringForm;
|
|
|
-
|
|
|
- if (!h.saving)
|
|
|
- onDeserialized();
|
|
|
- }
|
|
|
-
|
|
|
- bool operator == (const MetaIdentifier & other) const
|
|
|
- {
|
|
|
- assert( (stringForm == other.stringForm) ? (integerForm == other.integerForm) : true );
|
|
|
-
|
|
|
- return stringForm == other.stringForm;
|
|
|
- }
|
|
|
-
|
|
|
- bool operator != (const MetaIdentifier & other) const
|
|
|
- {
|
|
|
- return !(*this == other);
|
|
|
- }
|
|
|
-
|
|
|
- bool operator < (const MetaIdentifier & other) const;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
VCMI_LIB_NAMESPACE_END
|