TypeMeta

class TypeMeta

The meta class for all types.

TypeMeta is commonly used for type identification:

auto meta1 = dragon::TypeMeta::Make<float>();
auto meta2 = dragon::TypeMeta::Make<float>();
std::cout << (meta1 == meta2) << std::endl; // 1
std::cout << (meta1.id() == meta2.id()) << std::endl; // 1
std::cout << meta1.Match<float>() << std::endl; // 1
std::cout << (meta1.id() == dragon::TypeMeta::Id<float>()) << std::endl; // 1

Default constructor and destructor are available for non-fundamental types:

auto meta = dragon::TypeMeta::Make<std::string>();
auto* raw_string_data = malloc(1 * meta.itemsize());
meta.ctor()(raw_string_data, 1);
auto* string_data = reinterpret_cast<std::string*>(raw_string_data);
std::cout << string_data[0].size();
meta.dtor()(raw_string_data, 1);

Constructors

inline dragon::TypeMeta::TypeMeta()

Default constructor.

inline dragon::TypeMeta::TypeMeta(const TypeMeta &src)

Constructor with the other type meta.

Public Properties

copy

inline TypedCopy dragon::TypeMeta::copy() const

Return the type copy constructor.

ctor

inline PlacementNew dragon::TypeMeta::ctor() const

Return the type constructor.

dtor

inline TypedDestructor dragon::TypeMeta::dtor() const

Return the type destructor.

id

inline const TypeId &dragon::TypeMeta::id() const

Return the type identification.

itemsize

inline const size_t &dragon::TypeMeta::itemsize() const

Return the item size.

Public Functions

Copy

template<typename T>
static inline void dragon::TypeMeta::Copy(
  const void *src,
  void *dst,
  size_t n)

Call the copy constructor for each element.

Ctor

template<typename T>
static inline void dragon::TypeMeta::Ctor(
  void *ptr,
  size_t n)

Call the constructor for each element.

Dtor

template<typename T>
static inline void dragon::TypeMeta::Dtor(
  void *ptr,
  size_t n)

Call the destructor for each element.

Id

template<typename T>
static inline TypeId dragon::TypeMeta::Id()

Return the identification of given type.

Itemsize

template<typename T>
static inline size_t dragon::TypeMeta::Itemsize()

Return the item size of given type.

Make

template<typename T>
static inline FundamentalTypeMeta dragon::TypeMeta::Make()

Return a type meta of given type.

Match

template<typename T>
inline bool dragon::TypeMeta::Match() const

Return whether the meta is matched with given type.