TypeID.hpp

TypeID provides an easy way to convert types to strings.

TypeID provides an easy way to compare types, analyze them, and convert to strings. All TypeID objects are consistent within a type, and are ordinal and hashable.

To get the unique type information for type T use: TypeID t = GetTypeID<T>();

To make TypeID work more effectively with your custom class, implement the static member function EMPGetTypeName() which returns a string with its full name (including namespace). static std::string EMPGetTypeName() { return “myns::MyClass”; }

MEMBER FUNCTIONS:

std::string GetName() - Return a human readable (ideally) version of type’s name. void SetName(in_name) - Set the name that should be used henceforth for this type. size_t GetSize() - Return number of bytes used by this type.

&#8212; TYPE TESTS &#8212; bool IsAbstract() - Is this type a pure-virtual class? bool IsArithmetic() - Is this type numeric? bool IsArray() - Does this type represent a sequence of objects in memory? bool IsClass() - Is this type a non-union class? bool IsConst() - Is this contents of this type prevented from changing? bool IsEmpty() - Does type type have no contents? bool IsObject() - Is this type ANY object type? bool IsPointer() - Is this type a pointer? bool IsReference() - Is this type a reference? bool IsTrivial() - Is this type trivial? bool IsVoid() - Is this the type “void”? bool IsVolatile() - Is this type volatile qualified? bool IsTypePack() - Is this type an TypePack?

&#8212; COMPARISON TESTS &#8212; bool IsType<T>() - Is this type the specified type T? bool IsTypeIn<T1,T2,…>() - Is this type one of the listed types?

&#8212; TYPE CONVERSIONS &#8212; TypeID GetDecayTypeID() - Remove all qualifications (const, reference, etc.) TypeID GetElementTypeID() - Return type that makes up this type (i.e. for arrays) TypeID GetRemoveConstTypeID() - Remove const-ness of this type, if any. TypeID GetRemoveCVTypeID() - Remove constness and volatility of this type. TypeID GetRemoveExtentTypeID() - Flatten one level of a multi-dimensional array. TypeID GetRemoveAllExtentsTypeID() - Flatten multi-dimensional arrays. TypeID GetRemovePointerTypeID() - If this is a pointer, change to type pointed to. TypeID GetRemoveReferenceTypeID() - If this is a reference, change to type referred to. TypeID GetRemoveVolatileTypeID() - Remove volatility of this type, if any

&#8212; VALUE CONVERSIONS &#8212; double ToDouble(pointer) - Convert pointed-to object (of this type) to a double. std::string ToString(pointer) - Convert pointed-to object (of this type) to a std::string. bool FromDouble(value, pointer) - Use double value to set pointed-to object (of this type) bool FromString(string, pointer) - Use string value to set pointed-to object (of this type)

Developer notes:

  • Fill out defaults for remaining standard library classes (as possible)

  • If a type is a template, give access to parameter types.

  • If a type is a function, give access to parameter types.

Functions

template<typename T>
static TypeID GetTypeID()

Retrieve the correct TypeID for a given type.

inline void SetupTypeNames()

Setup a bunch of standard type names to be more readable.

template<typename T>
static Ptr<TypeID::Info> BuildInfo()

Build the information for a single TypeID.

template<typename ...Ts>
vector<TypeID> GetTypeIDs()

Retrieve a vector of TypeIDs for a pack of types passed in.

template<typename T>
vector<TypeID> GetTypePackIDs()

Retrieve a vector of TypeIDs for a TypePack of types passed in.

struct TypeID
#include <TypeID.hpp>

Basic TypeID data structure.

Public Types

using info_t = Ptr<TypeID::Info>

Public Functions

inline TypeID()
inline TypeID(info_t _info)
inline TypeID(size_t id)
TypeID(const TypeID&) = default
inline ~TypeID()
TypeID &operator=(const TypeID&) = default
inline operator size_t() const noexcept
inline operator bool() const noexcept
inline bool operator==(TypeID in) const
inline bool operator!=(TypeID in) const
inline bool operator<(TypeID in) const
inline bool operator<=(TypeID in) const
inline bool operator>(TypeID in) const
inline bool operator>=(TypeID in) const
inline size_t GetID() const

Get a unique numerical ID for this TypeID object.

inline const std::string &GetName() const

Get the name generated for this TypeID (ideally unique)

inline void SetName(const std::string &in_name)

Update the name for ALL instances of this TypeID.

inline bool IsInitialized() const
inline void SetInitialized(bool _in = true)
inline bool IsAbstract() const
inline bool IsArithmetic() const
inline bool IsArray() const
inline bool IsClass() const
inline bool IsConst() const
inline bool IsEmpty() const
inline bool IsObject() const
inline bool IsPointer() const
inline bool IsReference() const
inline bool IsTrivial() const
inline bool IsVoid() const
inline bool IsVolatile() const
inline bool IsTypePack() const
template<typename T>
inline bool IsType() const
template<typename T, typename ...Ts>
inline bool IsTypeIn() const
inline TypeID GetDecayTypeID() const
inline TypeID GetElementTypeID() const
inline TypeID GetRemoveConstTypeID() const
inline TypeID GetRemoveCVTypeID() const
inline TypeID GetRemoveExtentTypeID() const
inline TypeID GetRemoveAllExtentsTypeID() const
inline TypeID GetRemovePointerTypeID() const
inline TypeID GetRemoveReferenceTypeID() const
inline TypeID GetRemoveVolatileTypeID() const
inline size_t GetSize() const
inline double ToDouble(const Ptr<const void> ptr) const
inline std::string ToString(const Ptr<const void> ptr) const
inline bool FromDouble(double value, const Ptr<void> ptr)
inline bool FromString(const std::string &value, const Ptr<void> ptr)

Public Members

info_t info_ptr

Public Static Functions

static inline info_t GetUnknownInfoPtr()
struct Info
#include <TypeID.hpp>

Subclassed by TypeID::InfoData< T >

Public Functions

inline virtual ~Info()
inline virtual bool IsAbstract() const
inline virtual bool IsArithmetic() const
inline virtual bool IsArray() const
inline virtual bool IsClass() const
inline virtual bool IsConst() const
inline virtual bool IsEmpty() const
inline virtual bool IsObject() const
inline virtual bool IsPointer() const
inline virtual bool IsReference() const
inline virtual bool IsTrivial() const
inline virtual bool IsVoid() const
inline virtual bool IsVolatile() const
inline virtual bool IsFunction() const
inline virtual bool IsTypePack() const
inline virtual size_t GetDecayID() const
inline virtual size_t GetElementID() const
inline virtual size_t GetRemoveConstID() const
inline virtual size_t GetRemoveCVID() const
inline virtual size_t GetRemoveExtentID() const
inline virtual size_t GetRemoveAllExtentsID() const
inline virtual size_t GetRemovePtrID() const
inline virtual size_t GetRemoveRefID() const
inline virtual size_t GetRemoveVolatileID() const
inline virtual size_t GetSize() const

Return the size (in bytes) of objects of this type.

inline virtual double ToDouble(const Ptr<const void>) const

Treat the memory referred to by a void pointer as the current type, convert it to a double, and return that value. (Default to nan if no such conversion is possible.)

inline virtual std::string ToString(const Ptr<const void>) const

Treat the memory referred to by a void pointer as the current type, convert it to a string, and return that value. (Default to empty if no such conversion is possible.)

inline virtual bool FromDouble(double, const Ptr<void>) const

Take a double and a void pointer, treat the pointer as the correct type, and assign the double to it (if possible). Returns success.

inline virtual bool FromString(const std::string&, const Ptr<void>) const

Take a string and a void pointer, treat the pointer as the correct type, and assign the string to it (if possible). Returns success.

inline Info()
inline Info(const std::string &in_name)
Info(const Info&) = default

Public Members

bool init = false

Has this info been initialized yet?

std::string name = "[unknown type]"

Unique (ideally human-readable) type name.

template<typename T>
struct InfoData : public TypeID::Info
#include <TypeID.hpp>

Public Functions

inline virtual bool IsAbstract() const override
inline virtual bool IsArithmetic() const override
inline virtual bool IsArray() const override
inline virtual bool IsClass() const override
inline virtual bool IsConst() const override
inline virtual bool IsEmpty() const override
inline virtual bool IsObject() const override
inline virtual bool IsPointer() const override
inline virtual bool IsReference() const override
inline virtual bool IsTrivial() const override
inline virtual bool IsVoid() const override
inline virtual bool IsVolatile() const override
inline virtual bool IsFunction() const override
inline virtual bool IsTypePack() const override
inline virtual size_t GetDecayID() const override
inline virtual size_t GetElementID() const override
inline virtual size_t GetRemoveConstID() const override
inline virtual size_t GetRemoveCVID() const override
inline virtual size_t GetRemoveExtentID() const override
inline virtual size_t GetRemoveAllExtentsID() const override
inline virtual size_t GetRemovePtrID() const override
inline virtual size_t GetRemoveRefID() const override
inline virtual size_t GetRemoveVolatileID() const override
inline virtual size_t GetSize() const override

Return the size (in bytes) of objects of this type.

inline virtual double ToDouble(const Ptr<const void> ptr) const override

Treat the memory referred to by a void pointer as the current type, convert it to a double, and return that value. (Default to nan if no such conversion is possible.)

inline virtual std::string ToString(const Ptr<const void> ptr) const override

Treat the memory referred to by a void pointer as the current type, convert it to a string, and return that value. (Default to empty if no such conversion is possible.)

inline bool FromDouble([[maybe_unused]] double value, [[maybe_unused]] const Ptr<void> ptr) const override
inline virtual bool FromString(const std::string &value, const Ptr<void> ptr) const override

Take a string and a void pointer, treat the pointer as the correct type, and assign the string to it (if possible). Returns success.

template<typename T, typename = void>
struct HasEMPGetTypeName : public std::false_type
#include <TypeID.hpp>
template<typename T>
struct HasEMPGetTypeName<decoy_t<T, decltype(T::EMPGetTypeName())>> : public std::true_type
#include <TypeID.hpp>