Nebula
Loading...
Searching...
No Matches
id.h File Reference
#include <cstdint>
#include "core/types.h"

Go to the source code of this file.

Classes

class  Ids::Id
 This class implements some static helper functions to set high and low 32-bit integers, as well as a function to create a complete id from two of them. More...
 

Namespaces

namespace  Ids
 This simple Id pool implements a set of free and used consecutive integers.
 

Macros

#define ID_32_TYPE(x)
 
#define ID_16_TYPE(x)
 
#define ID_32_24_8_NAMED_TYPE(x, id32_name, id24_name, id8_name, combined_name)
 
#define ID_32_24_8_TYPE(x)
 
#define ID_24_8_24_8_NAMED_TYPE(x, id24_0_name, id8_0_name, id24_1_name, id8_1_name, combined0_name, combined1_name)
 
#define ID_24_8_24_8_TYPE(x)
 
#define ID_24_8_NAMED_TYPE(x, id24_name, id8_name, combined_name)
 
#define ID_24_8_TYPE(x)
 

Typedefs

typedef uint64_t Ids::Id64
 
typedef uint32_t Ids::Id32
 
typedef uint32_t Ids::Id24
 
typedef uint16_t Ids::Id16
 
typedef uint8_t Ids::Id8
 

Variables

static constexpr Id64 Ids::InvalidId64 = 0xFFFFFFFFFFFFFFFF
 
static constexpr Id32 Ids::InvalidId32 = 0xFFFFFFFF
 
static constexpr Id24 Ids::InvalidId24 = 0x00FFFFFF
 
static constexpr Id16 Ids::InvalidId16 = 0xFFFF
 
static constexpr Id8 Ids::InvalidId8 = 0xFF
 

Macro Definition Documentation

◆ ID_16_TYPE

#define ID_16_TYPE ( x)
Value:
struct x { \
Ids::Id16 id; \
constexpr x() : id(Ids::InvalidId16) {}; \
constexpr x(const Ids::Id16 id) : id(id) {}; \
constexpr explicit operator Ids::Id16() const { return id; } \
static constexpr x Invalid() { return Ids::InvalidId16; } \
constexpr uint32_t HashCode() const { return (uint32_t)(id); } \
const bool operator==(const x& rhs) const { return id == rhs.id; } \
const bool operator!=(const x& rhs) const { return id != rhs.id; } \
const bool operator<(const x& rhs) const { return HashCode() < rhs.HashCode(); } \
const bool operator>(const x& rhs) const { return HashCode() > rhs.HashCode(); } \
template <typename T> constexpr T As() const { static_assert(sizeof(T) == sizeof(x), "Can only convert between ID types of equal size"); T ret; memcpy((void*)&ret, this, sizeof(T)); return ret; }; \
}; \
static constexpr x Invalid##x = Ids::InvalidId16;
This simple Id pool implements a set of free and used consecutive integers.
Definition id.h:135
uint16_t Id16
Definition id.h:140
static constexpr Id16 InvalidId16
Definition id.h:145
id
Definition resourceid.h:37
bool operator>(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:283
bool operator<(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:277
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:272
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:282

◆ ID_24_8_24_8_NAMED_TYPE

#define ID_24_8_24_8_NAMED_TYPE ( x,
id24_0_name,
id8_0_name,
id24_1_name,
id8_1_name,
combined0_name,
combined1_name )

◆ ID_24_8_24_8_TYPE

#define ID_24_8_24_8_TYPE ( x)
Value:
ID_24_8_24_8_NAMED_TYPE(x, index0, generation0, index1, generation1, id0, id1)
#define ID_24_8_24_8_NAMED_TYPE(x, id24_0_name, id8_0_name, id24_1_name, id8_1_name, combined0_name, combined1_name)
Definition id.h:73

◆ ID_24_8_NAMED_TYPE

#define ID_24_8_NAMED_TYPE ( x,
id24_name,
id8_name,
combined_name )
Value:
struct x { \
union \
{\
struct\
{\
Ids::Id32 id24_name : 24; \
Ids::Id32 id8_name : 8; \
};\
Ids::Id32 combined_name;\
}; \
constexpr x() : id24_name(Ids::InvalidId24), id8_name(Ids::InvalidId8) {} \
constexpr x(const Ids::Id24 id0, const Ids::Id8 id1) : id24_name(id0), id8_name(id1) {} \
constexpr x(const Ids::Id32 id) : combined_name(id) {};\
explicit constexpr operator Ids::Id32() const { return combined_name; }\
static constexpr x Invalid() { return Ids::InvalidId32; }\
constexpr uint32_t HashCode() const { return (uint32_t)combined_name; }\
const bool operator==(const x& rhs) const { return id24_name == rhs.id24_name && id8_name == rhs.id8_name; }\
const bool operator!=(const x& rhs) const { return id24_name != rhs.id24_name || id8_name != rhs.id8_name; }\
const bool operator<(const x& rhs) const { return HashCode() < rhs.HashCode(); }\
const bool operator>(const x& rhs) const { return HashCode() > rhs.HashCode(); }\
template <typename T> constexpr T As() const { static_assert(sizeof(T) == sizeof(x), "Can only convert between ID types of equal size"); T ret; memcpy((void*)&ret, this, sizeof(T)); return ret; }; \
}; \
static constexpr Id24 InvalidId24
Definition id.h:144
static constexpr Id8 InvalidId8
Definition id.h:146
uint32_t Id24
Definition id.h:139
uint8_t Id8
Definition id.h:141
uint32_t Id32
Definition id.h:138
static constexpr Id32 InvalidId32
Definition id.h:143
static constexpr Id32 MakeId24_8(const Id24 big, const Id8 tiny)
set 24-8 bits in integer
Definition id.h:280

◆ ID_24_8_TYPE

#define ID_24_8_TYPE ( x)
Value:
ID_24_8_NAMED_TYPE(x, index, generation, id)
#define ID_24_8_NAMED_TYPE(x, id24_name, id8_name, combined_name)
Definition id.h:109

◆ ID_32_24_8_NAMED_TYPE

#define ID_32_24_8_NAMED_TYPE ( x,
id32_name,
id24_name,
id8_name,
combined_name )
Value:
struct x { \
Ids::Id32 id32_name : 32;\
union\
{\
struct\
{\
Ids::Id32 id24_name : 24;\
Ids::Id32 id8_name: 8;\
};\
Ids::Id32 combined_name;\
};\
constexpr x() : id32_name(Ids::InvalidId32), id24_name(Ids::InvalidId24), id8_name(Ids::InvalidId8) {};\
constexpr x(const Ids::Id32 id32, const Ids::Id24 id24, const Ids::Id8 id8) : id32_name(id32), id24_name(id24), id8_name(id8){} \
constexpr x(const Ids::Id64 id) : id32_name(Ids::Id::GetHigh(id)), id24_name(Ids::Index(Ids::Id::GetLow(id))), id8_name(Ids::Generation(Ids::Id::GetLow(id))) {};\
explicit constexpr operator Ids::Id64() const { return Ids::Id::MakeId32_24_8(id32_name, id24_name, id8_name); }\
constexpr uint32_t HashCode() const { return (uint32_t)combined_name; }\
constexpr Ids::Id64 HashCode64() const { return Ids::Id::MakeId32_24_8(id32_name, id24_name, id8_name); }\
const bool operator==(const x& rhs) const { return id32_name == rhs.id32_name && id24_name == rhs.id24_name && id8_name == rhs.id8_name; }\
const bool operator!=(const x& rhs) const { return id32_name != rhs.id32_name || id24_name != rhs.id24_name || id8_name != rhs.id8_name; }\
const bool operator<(const x& rhs) const { return HashCode64() < rhs.HashCode64(); }\
const bool operator>(const x& rhs) const { return HashCode64() > rhs.HashCode64(); }\
template <typename T> constexpr T As() const { static_assert(sizeof(T) == sizeof(x), "Can only convert between ID types of equal size"); T ret; memcpy((void*)&ret, this, sizeof(T)); return ret; }; \
}; \
uint64_t Id64
Definition id.h:137
U32 Id
Definition im3d.h:37
static constexpr Id64 MakeId32_24_8(const Id32 upper, const Id24 big, const Id8 tiny)
set 32-24-8 bits 64 bit integer
Definition id.h:289

◆ ID_32_24_8_TYPE

#define ID_32_24_8_TYPE ( x)
Value:
ID_32_24_8_NAMED_TYPE(x, parent, index, generation, id)
#define ID_32_24_8_NAMED_TYPE(x, id32_name, id24_name, id8_name, combined_name)
Definition id.h:46

◆ ID_32_TYPE

#define ID_32_TYPE ( x)
Value:
struct x { \
Ids::Id32 id; \
constexpr x() : id(Ids::InvalidId32) {}; \
constexpr x(const Ids::Id32 id) : id(id) {}; \
constexpr explicit operator Ids::Id32() const { return id; } \
static constexpr x Invalid() { return Ids::InvalidId32; } \
constexpr uint32_t HashCode() const { return id; } \
const bool operator==(const x& rhs) const { return id == rhs.id; } \
const bool operator!=(const x& rhs) const { return id != rhs.id; } \
const bool operator<(const x& rhs) const { return HashCode() < rhs.HashCode(); } \
const bool operator>(const x& rhs) const { return HashCode() > rhs.HashCode(); } \
template <typename T> constexpr T As() const { static_assert(sizeof(T) == sizeof(x), "Can only convert between ID types of equal size"); T ret; memcpy((void*)&ret, this, sizeof(T)); return ret; }; \
}; \
static constexpr x Invalid##x = Ids::InvalidId32;