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.
— TYPE TESTS — 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?
— COMPARISON TESTS — bool IsType<T>() - Is this type the specified type T? bool IsTypeIn<T1,T2,…>() - Is this type one of the listed types?
— TYPE CONVERSIONS — 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
— VALUE CONVERSIONS — 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
-
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.
-
struct TypeID
- #include <TypeID.hpp>
Basic TypeID data structure.
Public Functions
-
inline TypeID()
-
inline TypeID(size_t id)
-
inline ~TypeID()
-
inline operator size_t() const noexcept
-
inline operator bool() const noexcept
-
inline size_t GetID() const
Get a unique numerical ID for this TypeID object.
-
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 size_t GetSize() const
-
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 virtual ~Info()
-
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 virtual bool IsAbstract() const override
-
inline TypeID()