From 17d57ee49aecdac4085abb6cdf0574b8f9df594d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 9 Oct 2018 17:18:01 +0200 Subject: [PATCH] value types and meta objects --- TODO | 1 + docs/meta.md | 67 ++-- src/entt/meta/factory.hpp | 54 +-- src/entt/meta/meta.hpp | 765 +++++++++++++++++++++++++------------- test/entt/meta/meta.cpp | 719 ++++++++++++++++++----------------- 5 files changed, 921 insertions(+), 685 deletions(-) diff --git a/TODO b/TODO index 5beca14a4..e6053d808 100644 --- a/TODO +++ b/TODO @@ -14,6 +14,7 @@ * work stealing job system (see #100) * composable looper so as to pack erased systems, compose runners at different rates and run them at once in the loop * meta: sort of meta view based on meta stuff to iterate entities, void * and meta info objects +* meta: move to head elements and forms LRU lists * registry::probe(entt) (returns a component * if entt has the component, nullptr otherwise) * hashed string: add implicit check on construction for uniqueness (optional) * add a note about multithreading support to the README file diff --git a/docs/meta.md b/docs/meta.md index 077ed8e4a..880c29776 100644 --- a/docs/meta.md +++ b/docs/meta.md @@ -162,11 +162,11 @@ entt::meta_any empty{}; It can be constructed or assigned by copy and move and it takes the burden of destroying the contained object when required.
-A meta any object has a `type` member function that returns a pointer to the -meta type of the contained value, if any. The member functions `can_cast` and -`can_convert` are used to know if the underlying object has a given type as a -base or if it can be converted implicitly to it. Similarly, `cast` and `convert` -do what they promise and return the expected value. +A meta any object has a `type` member function that returns the meta type of the +contained value, if any. The member functions `can_cast` and `can_convert` are +used to know if the underlying object has a given type as a base or if it can be +converted implicitly to it. Similarly, `cast` and `convert` do what they promise +and return the expected value. # Enjoy the runtime @@ -181,25 +181,25 @@ both cases, the search can be done by means of the `resolve` function: ```cpp // search for a reflected type by type -auto *by_type = entt::resolve(); +auto by_type = entt::resolve(); // search for a reflected type by name -auto *by_name = entt::resolve("reflected_type"); +auto by_name = entt::resolve("reflected_type"); ``` There exits also a third overload of the `resolve` function to use to iterate all the reflected types at once: ```cpp -resolve([](auto *type) { +resolve([](auto type) { // ... }); ``` -In all cases, the returned value is a pointer to a `meta_type` object. This type -of objects offer an API to know the _runtime name_ of the type, to iterate all -the meta objects associated with them and even to build or destroy instances of -the underlying type.
+In all cases, the returned value is an instance of `meta_type`. This type of +objects offer an API to know the _runtime name_ of the type, to iterate all the +meta objects associated with them and even to build or destroy instances of the +underlying type.
Refer to the inline documentation for all the details. The meta objects that compose a meta type are accessed in the following ways: @@ -207,10 +207,10 @@ The meta objects that compose a meta type are accessed in the following ways: * _Meta constructors_. They are accessed by types of arguments: ```cpp - auto *ctor = entt::resolve()->ctor(); + auto ctor = entt::resolve().ctor(); ``` - The returned type is `meta_ctor *` and may be null if there is no constructor + The returned type is `meta_ctor` and may be invalid if there is no constructor that accepts the supplied arguments or at least some types from which they are derived or to which they can be converted.
A meta constructor offers an API to know the number of arguments, the expected @@ -220,21 +220,21 @@ The meta objects that compose a meta type are accessed in the following ways: * _Meta destructor_. It's returned by a dedicated function: ```cpp - auto *dtor = entt::resolve()->dtor(); + auto dtor = entt::resolve().dtor(); ``` - The returned type is `meta_dtor *` and may be null if there is no custom - destructor set for the gven meta type.
+ The returned type is `meta_dtor` and may be invalid if there is no custom + destructor set for the given meta type.
All what a meta destructor has to offer is a way to invoke it on a given instance. Be aware that the result may not be what is expected. * _Meta data_. They are accessed by name: ```cpp - auto *data = entt::resolve()->data("member"); + auto data = entt::resolve().data("member"); ``` - The returned type is `meta_data *` and may be null if there is no meta data + The returned type is `meta_data` and may be invalid if there is no meta data object associated with the given name.
A meta data object offers an API to query the underlying type (ie to know if it's a const or a static one), to get the meta type of the variable and to set @@ -243,10 +243,10 @@ The meta objects that compose a meta type are accessed in the following ways: * _Meta functions_. They are accessed by name: ```cpp - auto *func = entt::resolve()->func("member"); + auto func = entt::resolve().func("member"); ``` - The returned type is `meta_func *` and may be null if there is no meta + The returned type is `meta_func` and may be invalid if there is no meta function object associated with the given name.
A meta function object offers an API to query the underlying type (ie to know if it's a const or a static function), to know the number of arguments, the @@ -258,10 +258,10 @@ The meta objects that compose a meta type are accessed in the following ways: * _Meta bases_. They are accessed through the name of the base types: ```cpp - auto *base = entt::resolve()->base("base"); + auto base = entt::resolve().base("base"); ``` - The returned type is `meta_base *` and may be null if there is no meta base + The returned type is `meta_base` and may be invalid if there is no meta base object associated with the given name.
Meta bases aren't meant to be used directly, even though they are freely accessible. They expose only a few methods to use to know the meta type of the @@ -270,22 +270,33 @@ The meta objects that compose a meta type are accessed in the following ways: * _Meta conversion functions_. They are accessed by type: ```cpp - auto *conv = entt::resolve()->conv(); + auto conv = entt::resolve().conv(); ``` - The returned type is `meta_conv *` and may be null if there is no meta + The returned type is `meta_conv` and may be invalid if there is no meta conversion function associated with the given type.
The meta conversion functions are as thin as the meta bases and with a very similar interface. The sole difference is that they return a newly created instance wrapped in a meta any object when they convert between different types. +All the objects thus obtained as well as the meta types can be explicitly +converted to a boolean value to check if they are valid: + +```cpp +auto func = entt::resolve().func("member"); + +if(func) { + // ... +} +``` + Furthermore, all meta objects with the exception of meta destructors can be iterated through an overload that accepts a callback through which to return them. As an example: ```cpp -entt::resolve()->data([](auto *data) { +entt::resolve().data([](auto data) { // ... }); ``` @@ -326,12 +337,12 @@ named `prop` to iterate them at once and to search a specific property by key: ```cpp // iterate all the properties of a meta type -entt::resolve()->prop([](auto *prop) { +entt::resolve().prop([](auto prop) { // ... }); // search for a given property by name -auto *prop = entt::resolve()->prop("tooltip"_hs); +auto prop = entt::resolve().prop("tooltip"_hs); ``` Meta properties are objects having a fairly poor interface, all in all. They diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 324038605..9cb5d8ccc 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -74,10 +74,6 @@ class meta_factory { }, []() -> meta_any { return std::get<1>(prop); - }, - []() { - static meta_prop meta{&node}; - return &meta; } }; @@ -101,11 +97,7 @@ class meta_factory { std::is_member_pointer_v, std::is_arithmetic_v, std::is_compound_v, - &internal::destroy, - []() { - static meta_type meta{&node}; - return &meta; - } + &internal::destroy }; assert(!duplicate(name, node.next)); @@ -138,10 +130,6 @@ public: &internal::meta_info::resolve, [](void *instance) -> void * { return static_cast(static_cast(instance)); - }, - []() { - static meta_base meta{&node}; - return &meta; } }; @@ -172,10 +160,6 @@ public: &internal::meta_info::resolve, [](void *instance) -> meta_any { return static_cast>(*static_cast(instance)); - }, - []() { - static meta_conv meta{&node}; - return &meta; } }; @@ -214,10 +198,6 @@ public: &helper_type::arg, [](meta_any * const any) { return internal::invoke(nullptr, any, std::make_index_sequence{}); - }, - []() { - static meta_ctor meta{&node}; - return &meta; } }; @@ -253,10 +233,6 @@ public: &helper_type::arg, [](meta_any * const any) { return internal::construct(any, std::make_index_sequence{}); - }, - []() { - static meta_ctor meta{&node}; - return &meta; } }; @@ -291,13 +267,9 @@ public: static internal::meta_dtor_node node{ type, [](meta_handle handle) { - return handle.type() == internal::meta_info::resolve()->meta() + return handle.type() == internal::factory(internal::meta_info::resolve()) ? ((*Func)(*static_cast(handle.data())), true) : false; - }, - []() { - static meta_dtor meta{&node}; - return &meta; } }; @@ -336,11 +308,7 @@ public: !std::is_member_object_pointer_v, &internal::meta_info>::resolve, &internal::setter>, Type, Data>, - &internal::getter, - []() { - static meta_data meta{&node}; - return &meta; - } + &internal::getter }; assert(!duplicate(hashed_string{str}, node.next)); @@ -381,10 +349,6 @@ public: &func_type::arg, [](meta_handle handle, meta_any *any) { return internal::invoke(handle, any, std::make_index_sequence::size>{}); - }, - []() { - static meta_func meta{&node}; - return &meta; } }; @@ -444,8 +408,8 @@ inline meta_factory reflect() ENTT_NOEXCEPT { * @return The meta type associated with the given type, if any. */ template -inline meta_type * resolve() ENTT_NOEXCEPT { - return internal::meta_info::resolve()->meta(); +inline meta_type resolve() ENTT_NOEXCEPT { + return internal::factory(internal::meta_info::resolve()); } @@ -454,10 +418,10 @@ inline meta_type * resolve() ENTT_NOEXCEPT { * @param str The name to use to search for a meta type. * @return The meta type associated with the given name, if any. */ -inline meta_type * resolve(const char *str) ENTT_NOEXCEPT { - return internal::find_if([name = hashed_string{str}](auto *node) { +inline meta_type resolve(const char *str) ENTT_NOEXCEPT { + return internal::factory(internal::find_if([name = hashed_string{str}](auto *node) { return node->name == name; - }, internal::meta_info<>::type); + }, internal::meta_info<>::type)); } @@ -469,7 +433,7 @@ inline meta_type * resolve(const char *str) ENTT_NOEXCEPT { template void resolve(Op op) ENTT_NOEXCEPT { internal::iterate([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, internal::meta_info<>::type); } diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 906fdac8f..e8be27c64 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -37,16 +37,101 @@ class meta_type; namespace internal { -struct meta_prop_node; -struct meta_base_node; -struct meta_conv_node; -struct meta_ctor_node; -struct meta_dtor_node; -struct meta_data_node; -struct meta_func_node; struct meta_type_node; +struct meta_prop_node final { + meta_prop_node * const next; + meta_any(* const key)(); + meta_any(* const value)(); +}; + + +struct meta_base_node final { + meta_base_node * const next; + meta_type_node * const parent; + meta_type_node *(* const type)(); + void *(* const cast)(void *); +}; + + +struct meta_conv_node final { + meta_conv_node * const next; + meta_type_node * const parent; + meta_type_node *(* const type)(); + meta_any(* const conv)(void *); +}; + + +struct meta_ctor_node final { + using size_type = std::size_t; + meta_ctor_node * const next; + meta_type_node * const parent; + meta_prop_node * const prop; + const size_type size; + meta_type_node *(* const arg)(size_type); + meta_any(* const invoke)(meta_any * const); +}; + + +struct meta_dtor_node final { + meta_type_node * const parent; + bool(* const invoke)(meta_handle); +}; + + +struct meta_data_node final { + const hashed_string name; + meta_data_node * const next; + meta_type_node * const parent; + meta_prop_node * const prop; + const bool is_const; + const bool is_static; + meta_type_node *(* const type)(); + bool(* const set)(meta_handle, meta_any &); + meta_any(* const get)(meta_handle); +}; + + +struct meta_func_node final { + using size_type = std::size_t; + const hashed_string name; + meta_func_node * const next; + meta_type_node * const parent; + meta_prop_node * const prop; + const size_type size; + const bool is_const; + const bool is_static; + meta_type_node *(* const ret)(); + meta_type_node *(* const arg)(size_type); + meta_any(* const invoke)(meta_handle, meta_any *); +}; + + +struct meta_type_node final { + const hashed_string name; + meta_type_node * const next; + meta_prop_node * const prop; + const bool is_void; + const bool is_enum; + const bool is_class; + const bool is_pointer; + const bool is_function_pointer; + const bool is_member_object_pointer; + const bool is_member_function_pointer; + const bool is_member_pointer; + const bool is_arithmetic; + const bool is_compound; + bool(* const destroy)(meta_handle); + meta_base_node *base; + meta_conv_node *conv; + meta_ctor_node *ctor; + meta_dtor_node *dtor; + meta_data_node *data; + meta_func_node *func; +}; + + template struct meta_node { static meta_type_node *type; @@ -121,106 +206,6 @@ template struct meta_info: meta_node>...> {}; -struct meta_prop_node final { - meta_prop_node * const next; - meta_any(* const key)(); - meta_any(* const value)(); - meta_prop *(* const meta)(); -}; - - -struct meta_base_node final { - meta_base_node * const next; - meta_type_node * const parent; - meta_type_node *(* const type)(); - void *(* const cast)(void *); - meta_base *(* const meta)(); -}; - - -struct meta_conv_node final { - meta_conv_node * const next; - meta_type_node * const parent; - meta_type_node *(* const type)(); - meta_any(* const conv)(void *); - meta_conv *(* const meta)(); -}; - - -struct meta_ctor_node final { - using size_type = std::size_t; - meta_ctor_node * const next; - meta_type_node * const parent; - meta_prop_node * const prop; - const size_type size; - meta_type_node *(* const arg)(size_type); - meta_any(* const invoke)(meta_any * const); - meta_ctor *(* const meta)(); -}; - - -struct meta_dtor_node final { - meta_type_node * const parent; - bool(* const invoke)(meta_handle); - meta_dtor *(* const meta)(); -}; - - -struct meta_data_node final { - const hashed_string name; - meta_data_node * const next; - meta_type_node * const parent; - meta_prop_node * const prop; - const bool is_const; - const bool is_static; - meta_type_node *(* const type)(); - bool(* const set)(meta_handle, meta_any &); - meta_any(* const get)(meta_handle); - meta_data *(* const meta)(); -}; - - -struct meta_func_node final { - using size_type = std::size_t; - const hashed_string name; - meta_func_node * const next; - meta_type_node * const parent; - meta_prop_node * const prop; - const size_type size; - const bool is_const; - const bool is_static; - meta_type_node *(* const ret)(); - meta_type_node *(* const arg)(size_type); - meta_any(* const invoke)(meta_handle, meta_any *); - meta_func *(* const meta)(); -}; - - -struct meta_type_node final { - const hashed_string name; - meta_type_node * const next; - meta_prop_node * const prop; - const bool is_void; - const bool is_enum; - const bool is_class; - const bool is_pointer; - const bool is_function_pointer; - const bool is_member_object_pointer; - const bool is_member_function_pointer; - const bool is_member_pointer; - const bool is_arithmetic; - const bool is_compound; - bool(* const destroy)(meta_handle); - meta_type *(* const meta)(); - meta_base_node *base; - meta_conv_node *conv; - meta_ctor_node *ctor; - meta_dtor_node *dtor; - meta_data_node *data; - meta_func_node *func; -}; - - template void iterate(Op op, const Node *curr) ENTT_NOEXCEPT { while(curr) { @@ -250,7 +235,7 @@ auto find_if(Op op, const Node *curr) ENTT_NOEXCEPT { curr = curr->next; } - return curr ? curr->meta() : nullptr; + return curr; } @@ -301,6 +286,38 @@ inline bool can_cast_or_convert(const meta_type_node *from, const meta_type_node } +template +inline auto ctor(std::index_sequence, const meta_type_node *node) ENTT_NOEXCEPT { + return internal::find_if([](auto *node) { + return node->size == sizeof...(Args) && + (([](auto *from, auto *to) { + return internal::can_cast_or_convert<&internal::meta_type_node::base>(from, to) + || internal::can_cast_or_convert<&internal::meta_type_node::conv>(from, to); + }(internal::meta_info::resolve(), node->arg(Indexes))) && ...); + }, node->ctor); +} + + +template +struct factory_traits; + + +template<> struct factory_traits { using type = meta_prop; }; +template<> struct factory_traits { using type = meta_base; }; +template<> struct factory_traits { using type = meta_conv; }; +template<> struct factory_traits { using type = meta_ctor; }; +template<> struct factory_traits { using type = meta_dtor; }; +template<> struct factory_traits { using type = meta_data; }; +template<> struct factory_traits { using type = meta_func; }; +template<> struct factory_traits { using type = meta_type; }; + + +template +inline typename factory_traits::type factory(const Node *node) ENTT_NOEXCEPT { + return node; +} + + } @@ -384,8 +401,9 @@ public: }; destroy = [](storage_type &storage) { - auto *instance = reinterpret_cast(&storage); - internal::meta_info::resolve()->meta()->destroy(*instance); + auto *node = internal::meta_info::resolve(); + meta_handle handle = *reinterpret_cast(&storage); + node->dtor ? node->dtor->invoke(handle) : node->destroy(handle); }; } else { using chunk_type = std::aligned_storage_t; @@ -400,8 +418,10 @@ public: }; destroy = [](storage_type &storage) { + auto *node = internal::meta_info::resolve(); auto *chunk = *reinterpret_cast(&storage); - internal::meta_info::resolve()->meta()->destroy(*reinterpret_cast(chunk)); + meta_handle handle = *reinterpret_cast(chunk); + node->dtor ? node->dtor->invoke(handle) : node->destroy(handle); delete chunk; }; } @@ -459,9 +479,7 @@ public: * @brief Returns the meta type of the underlying object. * @return The meta type of the underlying object, if any. */ - inline meta_type * type() const ENTT_NOEXCEPT { - return node ? node->meta() : nullptr; - } + inline meta_type type() const ENTT_NOEXCEPT; /** * @brief Returns an opaque pointer to the contained instance. @@ -559,7 +577,7 @@ public: }, node); if(conv) { - any = conv->convert(instance); + any = conv->conv(instance); } } @@ -697,9 +715,7 @@ public: * @brief Returns the meta type of the underlying object. * @return The meta type of the underlying object, if any. */ - inline meta_type * type() const ENTT_NOEXCEPT { - return node ? node->meta() : nullptr; - } + inline meta_type type() const ENTT_NOEXCEPT; /** * @brief Tries to cast an instance to a given type. @@ -788,10 +804,9 @@ inline bool operator!=(const meta_any &lhs, const meta_any &rhs) ENTT_NOEXCEPT { */ class meta_prop final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_prop internal::factory(const internal::meta_prop_node *) ENTT_NOEXCEPT; - meta_prop(internal::meta_prop_node * node) ENTT_NOEXCEPT + inline meta_prop(const internal::meta_prop_node *node) ENTT_NOEXCEPT : node{node} {} @@ -812,11 +827,40 @@ public: return node->value(); } + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_prop &other) const ENTT_NOEXCEPT { + return node == other.node; + } + private: - internal::meta_prop_node *node; + const internal::meta_prop_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_prop &lhs, const meta_prop &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta base object. * @@ -825,10 +869,9 @@ private: */ class meta_base final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_base internal::factory(const internal::meta_base_node *) ENTT_NOEXCEPT; - meta_base(internal::meta_base_node * node) ENTT_NOEXCEPT + inline meta_base(const internal::meta_base_node *node) ENTT_NOEXCEPT : node{node} {} @@ -837,17 +880,13 @@ public: * @brief Returns the meta type to which a meta base belongs. * @return The meta type to which the meta base belongs. */ - inline meta_type * parent() const ENTT_NOEXCEPT { - return node->parent->meta(); - } + inline meta_type parent() const ENTT_NOEXCEPT; /** * @brief Returns the meta type of a given meta base. * @return The meta type of the meta base. */ - inline meta_type * type() const ENTT_NOEXCEPT { - return node->type()->meta(); - } + inline meta_type type() const ENTT_NOEXCEPT; /** * @brief Casts an instance from a parent type to a base type. @@ -858,11 +897,40 @@ public: return node->cast(instance); } + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_base &other) const ENTT_NOEXCEPT { + return node == other.node; + } + private: - internal::meta_base_node *node; + const internal::meta_base_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_base &lhs, const meta_base &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta conversion function object. * @@ -871,10 +939,9 @@ private: */ class meta_conv final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_conv internal::factory(const internal::meta_conv_node *) ENTT_NOEXCEPT; - meta_conv(internal::meta_conv_node * node) ENTT_NOEXCEPT + inline meta_conv(const internal::meta_conv_node *node) ENTT_NOEXCEPT : node{node} {} @@ -883,17 +950,13 @@ public: * @brief Returns the meta type to which a meta conversion function belongs. * @return The meta type to which the meta conversion function belongs. */ - inline meta_type * parent() const ENTT_NOEXCEPT { - return node->parent->meta(); - } + inline meta_type parent() const ENTT_NOEXCEPT; /** * @brief Returns the meta type of a given meta conversion function. * @return The meta type of the meta conversion function. */ - inline meta_type * type() const ENTT_NOEXCEPT { - return node->type()->meta(); - } + inline meta_type type() const ENTT_NOEXCEPT; /** * @brief Converts an instance to a given type. @@ -904,11 +967,40 @@ public: return node->conv(instance); } + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_conv &other) const ENTT_NOEXCEPT { + return node == other.node; + } + private: - internal::meta_conv_node *node; + const internal::meta_conv_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_conv &lhs, const meta_conv &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta constructor object. * @@ -917,10 +1009,9 @@ private: */ class meta_ctor final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_ctor internal::factory(const internal::meta_ctor_node *) ENTT_NOEXCEPT; - meta_ctor(internal::meta_ctor_node * node) ENTT_NOEXCEPT + inline meta_ctor(const internal::meta_ctor_node *node) ENTT_NOEXCEPT : node{node} {} @@ -932,9 +1023,7 @@ public: * @brief Returns the meta type to which a meta constructor belongs. * @return The meta type to which the meta constructor belongs. */ - inline meta_type * parent() const ENTT_NOEXCEPT { - return node->parent->meta(); - } + inline meta_type parent() const ENTT_NOEXCEPT; /** * @brief Returns the number of arguments accepted by a meta constructor. @@ -949,9 +1038,7 @@ public: * @param index The index of the argument of which to return the meta type. * @return The meta type of the i-th argument of a meta constructor, if any. */ - inline meta_type * arg(size_type index) const ENTT_NOEXCEPT { - return index < size() ? node->arg(index)->meta() : nullptr; - } + inline meta_type arg(size_type index) const ENTT_NOEXCEPT; /** * @brief Creates an instance of the underlying type, if possible. @@ -982,10 +1069,10 @@ public: * @param op A valid function object. */ template - inline std::enable_if_t, void> + inline std::enable_if_t, void> prop(Op op) const ENTT_NOEXCEPT { internal::iterate([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node->prop); } @@ -996,18 +1083,47 @@ public: * @return The property associated with the given key, if any. */ template - inline std::enable_if_t, meta_prop *> + inline std::enable_if_t, meta_prop> prop(Key &&key) const ENTT_NOEXCEPT { - return internal::find_if([key = meta_any{std::forward(key)}](auto *curr) { + return internal::factory(internal::find_if([key = meta_any{std::forward(key)}](auto *curr) { return curr->key() == key; - }, node->prop); + }, node->prop)); + } + + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_ctor &other) const ENTT_NOEXCEPT { + return node == other.node; } private: - internal::meta_ctor_node *node; + const internal::meta_ctor_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_ctor &lhs, const meta_ctor &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta destructor object. * @@ -1016,10 +1132,9 @@ private: */ class meta_dtor final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_dtor internal::factory(const internal::meta_dtor_node *) ENTT_NOEXCEPT; - meta_dtor(internal::meta_dtor_node * node) ENTT_NOEXCEPT + inline meta_dtor(const internal::meta_dtor_node *node) ENTT_NOEXCEPT : node{node} {} @@ -1028,9 +1143,7 @@ public: * @brief Returns the meta type to which a meta destructor belongs. * @return The meta type to which the meta destructor belongs. */ - inline meta_type * parent() const ENTT_NOEXCEPT { - return node->parent->meta(); - } + inline meta_type parent() const ENTT_NOEXCEPT; /** * @brief Destroys an instance of the underlying type. @@ -1046,11 +1159,40 @@ public: return node->invoke(handle); } + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_dtor &other) const ENTT_NOEXCEPT { + return node == other.node; + } + private: - internal::meta_dtor_node *node; + const internal::meta_dtor_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_dtor &lhs, const meta_dtor &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta data object. * @@ -1059,10 +1201,9 @@ private: */ class meta_data final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_data internal::factory(const internal::meta_data_node *) ENTT_NOEXCEPT; - meta_data(internal::meta_data_node * node) ENTT_NOEXCEPT + inline meta_data(const internal::meta_data_node *node) ENTT_NOEXCEPT : node{node} {} @@ -1079,9 +1220,7 @@ public: * @brief Returns the meta type to which a meta data belongs. * @return The meta type to which the meta data belongs. */ - inline meta_type * parent() const ENTT_NOEXCEPT { - return node->parent->meta(); - } + inline meta_type parent() const ENTT_NOEXCEPT; /** * @brief Indicates whether a given meta data is constant or not. @@ -1107,9 +1246,7 @@ public: * @brief Returns the meta type of a given meta data. * @return The meta type of the meta data. */ - inline meta_type * type() const ENTT_NOEXCEPT { - return node->type()->meta(); - } + inline meta_type type() const ENTT_NOEXCEPT; /** * @brief Sets the value of the variable enclosed by a given meta type. @@ -1151,10 +1288,10 @@ public: * @param op A valid function object. */ template - inline std::enable_if_t, void> + inline std::enable_if_t, void> prop(Op op) const ENTT_NOEXCEPT { internal::iterate([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node->prop); } @@ -1165,18 +1302,47 @@ public: * @return The property associated with the given key, if any. */ template - inline std::enable_if_t, meta_prop *> + inline std::enable_if_t, meta_prop> prop(Key &&key) const ENTT_NOEXCEPT { - return internal::find_if([key = meta_any{std::forward(key)}](auto *curr) { + return internal::factory(internal::find_if([key = meta_any{std::forward(key)}](auto *curr) { return curr->key() == key; - }, node->prop); + }, node->prop)); + } + + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_data &other) const ENTT_NOEXCEPT { + return node == other.node; } private: - internal::meta_data_node *node; + const internal::meta_data_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_data &lhs, const meta_data &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta function object. * @@ -1185,10 +1351,9 @@ private: */ class meta_func final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_func internal::factory(const internal::meta_func_node *) ENTT_NOEXCEPT; - meta_func(internal::meta_func_node * node) ENTT_NOEXCEPT + inline meta_func(const internal::meta_func_node *node) ENTT_NOEXCEPT : node{node} {} @@ -1208,9 +1373,7 @@ public: * @brief Returns the meta type to which a meta function belongs. * @return The meta type to which the meta function belongs. */ - inline meta_type * parent() const ENTT_NOEXCEPT { - return node->parent->meta(); - } + inline meta_type parent() const ENTT_NOEXCEPT; /** * @brief Returns the number of arguments accepted by a meta function. @@ -1244,18 +1407,14 @@ public: * @brief Returns the meta type of the return type of a meta function. * @return The meta type of the return type of the meta function. */ - inline meta_type * ret() const ENTT_NOEXCEPT { - return node->ret()->meta(); - } + inline meta_type ret() const ENTT_NOEXCEPT; /** * @brief Returns the meta type of the i-th argument of a meta function. * @param index The index of the argument of which to return the meta type. * @return The meta type of the i-th argument of a meta function, if any. */ - inline meta_type * arg(size_type index) const ENTT_NOEXCEPT { - return index < size() ? node->arg(index)->meta() : nullptr; - } + inline meta_type arg(size_type index) const ENTT_NOEXCEPT; /** * @brief Invokes the underlying function, if possible. @@ -1290,10 +1449,10 @@ public: * @param op A valid function object. */ template - inline std::enable_if_t, void> + inline std::enable_if_t, void> prop(Op op) const ENTT_NOEXCEPT { internal::iterate([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node->prop); } @@ -1304,18 +1463,47 @@ public: * @return The property associated with the given key, if any. */ template - inline std::enable_if_t, meta_prop *> + inline std::enable_if_t, meta_prop> prop(Key &&key) const ENTT_NOEXCEPT { - return internal::find_if([key = meta_any{std::forward(key)}](auto *curr) { + return internal::factory(internal::find_if([key = meta_any{std::forward(key)}](auto *curr) { return curr->key() == key; - }, node->prop); + }, node->prop)); + } + + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_func &other) const ENTT_NOEXCEPT { + return node == other.node; } private: - internal::meta_func_node *node; + const internal::meta_func_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_func &lhs, const meta_func &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + /** * @brief Meta type object. * @@ -1324,28 +1512,12 @@ private: */ class meta_type final { /*! @brief A factory is allowed to create meta objects. */ - template - friend class meta_factory; + friend meta_type internal::factory(const internal::meta_type_node *) ENTT_NOEXCEPT; - /*! @brief A meta node is allowed to create meta objects. */ - template - friend struct internal::meta_node; - - meta_type(internal::meta_type_node * node) ENTT_NOEXCEPT + inline meta_type(const internal::meta_type_node *node) ENTT_NOEXCEPT : node{node} {} - template - inline auto ctor(std::index_sequence) const ENTT_NOEXCEPT { - return internal::find_if([](auto *node) { - return node->size == sizeof...(Args) && - (([](auto *from, auto *to) { - return internal::can_cast_or_convert<&internal::meta_type_node::base>(from, to) - || internal::can_cast_or_convert<&internal::meta_type_node::conv>(from, to); - }(internal::meta_info::resolve(), node->arg(Indexes))) && ...); - }, node->ctor); - } - public: /** * @brief Returns the name assigned to a given meta type. @@ -1457,7 +1629,7 @@ public: template inline void base(Op op) const ENTT_NOEXCEPT { internal::iterate<&internal::meta_type_node::base>([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node); } @@ -1469,10 +1641,10 @@ public: * @param str The name to use to search for a meta base. * @return The meta base associated with the given name, if any. */ - inline meta_base * base(const char *str) const ENTT_NOEXCEPT { - return internal::find_if<&internal::meta_type_node::base>([name = hashed_string{str}](auto *node) { + inline meta_base base(const char *str) const ENTT_NOEXCEPT { + return internal::factory(internal::find_if<&internal::meta_type_node::base>([name = hashed_string{str}](auto *node) { return node->type()->name == name; - }, node); + }, node)); } /** @@ -1487,7 +1659,7 @@ public: template inline void conv(Op op) const ENTT_NOEXCEPT { internal::iterate<&internal::meta_type_node::conv>([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node); } @@ -1502,10 +1674,10 @@ public: * any. */ template - inline meta_conv * conv() const ENTT_NOEXCEPT { - return internal::find_if<&internal::meta_type_node::conv>([type = internal::meta_info::resolve()](auto *node) { + inline meta_conv conv() const ENTT_NOEXCEPT { + return internal::factory(internal::find_if<&internal::meta_type_node::conv>([type = internal::meta_info::resolve()](auto *node) { return node->type() == type; - }, node); + }, node)); } /** @@ -1516,7 +1688,7 @@ public: template inline void ctor(Op op) const ENTT_NOEXCEPT { internal::iterate([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node->ctor); } @@ -1526,16 +1698,16 @@ public: * @return The requested meta constructor, if any. */ template - inline meta_ctor * ctor() const ENTT_NOEXCEPT { - return ctor(std::make_index_sequence{}); + inline meta_ctor ctor() const ENTT_NOEXCEPT { + return internal::factory(internal::ctor(std::make_index_sequence{}, node)); } /** * @brief Returns the meta destructor associated with a given type. * @return The meta destructor associated with the given type, if any. */ - inline meta_dtor * dtor() const ENTT_NOEXCEPT { - return node->dtor ? node->dtor->meta() : nullptr; + inline meta_dtor dtor() const ENTT_NOEXCEPT { + return internal::factory(node->dtor); } /** @@ -1550,7 +1722,7 @@ public: template inline void data(Op op) const ENTT_NOEXCEPT { internal::iterate<&internal::meta_type_node::data>([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node); } @@ -1564,10 +1736,10 @@ public: * @param str The name to use to search for a meta data. * @return The meta data associated with the given name, if any. */ - inline meta_data * data(const char *str) const ENTT_NOEXCEPT { - return internal::find_if<&internal::meta_type_node::data>([name = hashed_string{str}](auto *node) { + inline meta_data data(const char *str) const ENTT_NOEXCEPT { + return internal::factory(internal::find_if<&internal::meta_type_node::data>([name = hashed_string{str}](auto *node) { return node->name == name; - }, node); + }, node)); } /** @@ -1583,7 +1755,7 @@ public: template inline void func(Op op) const ENTT_NOEXCEPT { internal::iterate<&internal::meta_type_node::func>([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node); } @@ -1597,10 +1769,10 @@ public: * @param str The name to use to search for a meta function. * @return The meta function associated with the given name, if any. */ - inline meta_func * func(const char *str) const ENTT_NOEXCEPT { - return internal::find_if<&internal::meta_type_node::func>([name = hashed_string{str}](auto *node) { + inline meta_func func(const char *str) const ENTT_NOEXCEPT { + return internal::factory(internal::find_if<&internal::meta_type_node::func>([name = hashed_string{str}](auto *node) { return node->name == name; - }, node); + }, node)); } /** @@ -1650,10 +1822,10 @@ public: * @param op A valid function object. */ template - inline std::enable_if_t, void> + inline std::enable_if_t, void> prop(Op op) const ENTT_NOEXCEPT { internal::iterate<&internal::meta_type_node::prop>([op = std::move(op)](auto *node) { - op(node->meta()); + op(internal::factory(node)); }, node); } @@ -1669,18 +1841,117 @@ public: * @return The property associated with the given key, if any. */ template - inline std::enable_if_t, meta_prop *> + inline std::enable_if_t, meta_prop> prop(Key &&key) const ENTT_NOEXCEPT { - return internal::find_if<&internal::meta_type_node::prop>([key = meta_any{std::forward(key)}](auto *curr) { + return internal::factory(internal::find_if<&internal::meta_type_node::prop>([key = meta_any{std::forward(key)}](auto *curr) { return curr->key() == key; - }, node); + }, node)); + } + + /** + * @brief Returns true if a meta object is valid, false otherwise. + * @return True if the meta object is valid, false otherwise. + */ + inline explicit operator bool() const ENTT_NOEXCEPT { + return node; + } + + /** + * @brief Checks if two meta objects refer to the same node. + * @param other The meta object with which to compare. + * @return True if the two meta objects refer to the same node, false + * otherwise. + */ + inline bool operator==(const meta_type &other) const ENTT_NOEXCEPT { + return node == other.node; } private: - internal::meta_type_node *node; + const internal::meta_type_node *node; }; +/** + * @brief Checks if two meta objects refer to the same node. + * @param lhs A meta object, either valid or not. + * @param rhs A meta object, either valid or not. + * @return True if the two meta objects refer to the same node, false otherwise. + */ +inline bool operator!=(const meta_type &lhs, const meta_type &rhs) ENTT_NOEXCEPT { + return !(lhs == rhs); +} + + +inline meta_type meta_any::type() const ENTT_NOEXCEPT { + return internal::factory(node); +} + + +inline meta_type meta_handle::type() const ENTT_NOEXCEPT { + return internal::factory(node); +} + + +inline meta_type meta_base::parent() const ENTT_NOEXCEPT { + return internal::factory(node->parent); +} + + +inline meta_type meta_base::type() const ENTT_NOEXCEPT { + return internal::factory(node->type()); +} + + +inline meta_type meta_conv::parent() const ENTT_NOEXCEPT { + return internal::factory(node->parent); +} + + +inline meta_type meta_conv::type() const ENTT_NOEXCEPT { + return internal::factory(node->type()); +} + + +inline meta_type meta_ctor::parent() const ENTT_NOEXCEPT { + return internal::factory(node->parent); +} + + +inline meta_type meta_ctor::arg(size_type index) const ENTT_NOEXCEPT { + return internal::factory(index < size() ? node->arg(index) : nullptr); +} + + +inline meta_type meta_dtor::parent() const ENTT_NOEXCEPT { + return internal::factory(node->parent); +} + + +inline meta_type meta_data::parent() const ENTT_NOEXCEPT { + return internal::factory(node->parent); +} + + +inline meta_type meta_data::type() const ENTT_NOEXCEPT { + return internal::factory(node->type()); +} + + +inline meta_type meta_func::parent() const ENTT_NOEXCEPT { + return internal::factory(node->parent); +} + + +inline meta_type meta_func::ret() const ENTT_NOEXCEPT { + return internal::factory(node->ret()); +} + + +inline meta_type meta_func::arg(size_type index) const ENTT_NOEXCEPT { + return internal::factory(index < size() ? node->arg(index) : nullptr); +} + + /** * @cond TURN_OFF_DOXYGEN * Internal details not to be documented. @@ -1704,7 +1975,7 @@ struct meta_function_helper { static constexpr auto size = sizeof...(Args); - inline static auto arg(typename meta_func_node::size_type index) { + inline static auto arg(typename internal::meta_func_node::size_type index) { return std::array{{meta_info::resolve()...}}[index]; } }; @@ -1742,7 +2013,7 @@ inline bool destroy([[maybe_unused]] meta_handle handle) { if constexpr(std::is_void_v) { return false; } else { - return handle.type() == meta_info::resolve()->meta() + return handle.type() == internal::factory(meta_info::resolve()) ? (static_cast(handle.data())->~Type(), true) : false; } @@ -1865,11 +2136,7 @@ meta_type_node * meta_node::resolve() ENTT_NOEXCEPT { std::is_member_pointer_v, std::is_arithmetic_v, std::is_compound_v, - &destroy, - []() { - static meta_type meta{&node}; - return &meta; - } + &destroy }; type = &node; diff --git a/test/entt/meta/meta.cpp b/test/entt/meta/meta.cpp index 0f025ddfb..2b8f14802 100644 --- a/test/entt/meta/meta.cpp +++ b/test/entt/meta/meta.cpp @@ -161,7 +161,7 @@ TEST_F(Meta, Resolve) { bool found = false; - entt::resolve([&found](auto *type) { + entt::resolve([&found](auto type) { found = found || type == entt::resolve(); }); @@ -202,7 +202,7 @@ TEST_F(Meta, MetaAnyEmpty) { entt::meta_any any{}; ASSERT_FALSE(any); - ASSERT_EQ(any.type(), nullptr); + ASSERT_FALSE(any.type()); ASSERT_FALSE(any.can_cast()); ASSERT_FALSE(any.can_cast()); ASSERT_EQ(any.data(), nullptr); @@ -506,7 +506,7 @@ TEST_F(Meta, MetaHandleEmpty) { entt::meta_handle handle{}; ASSERT_FALSE(handle); - ASSERT_EQ(handle.type(), nullptr); + ASSERT_FALSE(handle.type()); ASSERT_EQ(handle.try_cast(), nullptr); ASSERT_EQ(handle.try_cast(), nullptr); ASSERT_EQ(handle.data(), nullptr); @@ -530,32 +530,32 @@ TEST_F(Meta, MetaHandleTryCast) { } TEST_F(Meta, MetaProp) { - auto *prop = entt::resolve()->prop(properties::prop_int); + auto prop = entt::resolve().prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 42); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 42); } TEST_F(Meta, MetaBase) { - auto *base = entt::resolve()->base("base"); + auto base = entt::resolve().base("base"); derived_type derived{}; - ASSERT_NE(base, nullptr); - ASSERT_EQ(base->parent(), entt::resolve("derived")); - ASSERT_EQ(base->type(), entt::resolve()); - ASSERT_EQ(base->cast(&derived), static_cast(&derived)); + ASSERT_TRUE(base); + ASSERT_EQ(base.parent(), entt::resolve("derived")); + ASSERT_EQ(base.type(), entt::resolve()); + ASSERT_EQ(base.cast(&derived), static_cast(&derived)); } TEST_F(Meta, MetaConv) { - auto *conv = entt::resolve()->conv(); + auto conv = entt::resolve().conv(); double value = 3.; - ASSERT_NE(conv, nullptr); - ASSERT_EQ(conv->parent(), entt::resolve()); - ASSERT_EQ(conv->type(), entt::resolve()); + ASSERT_TRUE(conv); + ASSERT_EQ(conv.parent(), entt::resolve()); + ASSERT_EQ(conv.type(), entt::resolve()); - auto any = conv->convert(&value); + auto any = conv.convert(&value); ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); @@ -563,18 +563,18 @@ TEST_F(Meta, MetaConv) { } TEST_F(Meta, MetaCtor) { - auto *ctor = entt::resolve()->ctor(); + auto ctor = entt::resolve().ctor(); - ASSERT_NE(ctor, nullptr); - ASSERT_EQ(ctor->parent(), entt::resolve("derived")); - ASSERT_EQ(ctor->size(), entt::meta_ctor::size_type{3}); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{0}), entt::resolve()); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{1}), entt::resolve()); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{2}), entt::resolve()); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{3}), nullptr); + ASSERT_TRUE(ctor); + ASSERT_EQ(ctor.parent(), entt::resolve("derived")); + ASSERT_EQ(ctor.size(), entt::meta_ctor::size_type{3}); + ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{0}), entt::resolve()); + ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{1}), entt::resolve()); + ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{2}), entt::resolve()); + ASSERT_FALSE(ctor.arg(entt::meta_ctor::size_type{3})); - auto any = ctor->invoke(base_type{}, 42, 'c'); - auto empty = ctor->invoke(); + auto any = ctor.invoke(base_type{}, 42, 'c'); + auto empty = ctor.invoke(); ASSERT_FALSE(empty); ASSERT_TRUE(any); @@ -582,33 +582,33 @@ TEST_F(Meta, MetaCtor) { ASSERT_EQ(any.cast().i, 42); ASSERT_EQ(any.cast().c, 'c'); - ctor->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_EQ(prop->value(), false); + ctor.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_EQ(prop.value(), false); }); - ASSERT_EQ(ctor->prop(properties::prop_int), nullptr); + ASSERT_FALSE(ctor.prop(properties::prop_int)); - auto *prop = ctor->prop(properties::prop_bool); + auto prop = ctor.prop(properties::prop_bool); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_EQ(prop->value(), false); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_EQ(prop.value(), false); } TEST_F(Meta, MetaCtorFunc) { - auto *ctor = entt::resolve()->ctor(); + auto ctor = entt::resolve().ctor(); - ASSERT_NE(ctor, nullptr); - ASSERT_EQ(ctor->parent(), entt::resolve("derived")); - ASSERT_EQ(ctor->size(), entt::meta_ctor::size_type{2}); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{0}), entt::resolve()); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{1}), entt::resolve()); - ASSERT_EQ(ctor->arg(entt::meta_ctor::size_type{2}), nullptr); + ASSERT_TRUE(ctor); + ASSERT_EQ(ctor.parent(), entt::resolve("derived")); + ASSERT_EQ(ctor.size(), entt::meta_ctor::size_type{2}); + ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{0}), entt::resolve()); + ASSERT_EQ(ctor.arg(entt::meta_ctor::size_type{1}), entt::resolve()); + ASSERT_FALSE(ctor.arg(entt::meta_ctor::size_type{2})); - auto any = ctor->invoke(derived_type{}, 42); - auto empty = ctor->invoke(3, 'c'); + auto any = ctor.invoke(derived_type{}, 42); + auto empty = ctor.invoke(3, 'c'); ASSERT_FALSE(empty); ASSERT_TRUE(any); @@ -616,24 +616,24 @@ TEST_F(Meta, MetaCtorFunc) { ASSERT_EQ(any.cast().i, 42); ASSERT_EQ(any.cast().c, 'c'); - ctor->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 42); + ctor.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 42); }); - ASSERT_EQ(ctor->prop(properties::prop_bool), nullptr); + ASSERT_FALSE(ctor.prop(properties::prop_bool)); - auto *prop = ctor->prop(properties::prop_int); + auto prop = ctor.prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 42); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 42); } TEST_F(Meta, MetaCtorMetaAnyArgs) { - auto *ctor = entt::resolve()->ctor(); - auto any = ctor->invoke(base_type{}, entt::meta_any{42}, entt::meta_any{'c'}); + auto ctor = entt::resolve().ctor(); + auto any = ctor.invoke(base_type{}, entt::meta_any{42}, entt::meta_any{'c'}); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -642,13 +642,13 @@ TEST_F(Meta, MetaCtorMetaAnyArgs) { } TEST_F(Meta, MetaCtorInvalidArgs) { - auto *ctor = entt::resolve()->ctor(); - ASSERT_FALSE(ctor->invoke(base_type{}, entt::meta_any{'c'}, entt::meta_any{42})); + auto ctor = entt::resolve().ctor(); + ASSERT_FALSE(ctor.invoke(base_type{}, entt::meta_any{'c'}, entt::meta_any{42})); } TEST_F(Meta, MetaCtorCastAndConvert) { - auto *ctor = entt::resolve()->ctor(); - auto any = ctor->invoke(entt::meta_any{derived_type{}}, entt::meta_any{42.}, entt::meta_any{'c'}); + auto ctor = entt::resolve().ctor(); + auto any = ctor.invoke(entt::meta_any{derived_type{}}, entt::meta_any{42.}, entt::meta_any{'c'}); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -657,8 +657,8 @@ TEST_F(Meta, MetaCtorCastAndConvert) { } TEST_F(Meta, MetaCtorFuncMetaAnyArgs) { - auto *ctor = entt::resolve()->ctor(); - auto any = ctor->invoke(base_type{}, entt::meta_any{42}); + auto ctor = entt::resolve().ctor(); + auto any = ctor.invoke(base_type{}, entt::meta_any{42}); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -667,13 +667,13 @@ TEST_F(Meta, MetaCtorFuncMetaAnyArgs) { } TEST_F(Meta, MetaCtorFuncInvalidArgs) { - auto *ctor = entt::resolve()->ctor(); - ASSERT_FALSE(ctor->invoke(base_type{}, entt::meta_any{'c'})); + auto ctor = entt::resolve().ctor(); + ASSERT_FALSE(ctor.invoke(base_type{}, entt::meta_any{'c'})); } TEST_F(Meta, MetaCtorFuncCastAndConvert) { - auto *ctor = entt::resolve()->ctor(); - auto any = ctor->invoke(entt::meta_any{derived_type{}}, entt::meta_any{42.}); + auto ctor = entt::resolve().ctor(); + auto any = ctor.invoke(entt::meta_any{derived_type{}}, entt::meta_any{42.}); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -682,150 +682,149 @@ TEST_F(Meta, MetaCtorFuncCastAndConvert) { } TEST_F(Meta, MetaDtor) { - auto *dtor = entt::resolve()->dtor(); + auto dtor = entt::resolve().dtor(); empty_type empty{}; - ASSERT_NE(dtor, nullptr); - ASSERT_EQ(dtor->parent(), entt::resolve("empty")); + ASSERT_TRUE(dtor); + ASSERT_EQ(dtor.parent(), entt::resolve("empty")); ASSERT_EQ(empty_type::counter, 0); - ASSERT_TRUE(dtor->invoke(empty)); + ASSERT_TRUE(dtor.invoke(empty)); ASSERT_EQ(empty_type::counter, 1); } TEST_F(Meta, MetaDtorMetaAnyArg) { - auto *dtor = entt::resolve()->dtor(); + auto dtor = entt::resolve().dtor(); entt::meta_any any{empty_type{}}; ASSERT_EQ(empty_type::counter, 0); - ASSERT_TRUE(dtor->invoke(any)); + ASSERT_TRUE(dtor.invoke(any)); ASSERT_EQ(empty_type::counter, 1); } TEST_F(Meta, MetaDtorMetaAnyInvalidArg) { - auto *dtor = entt::resolve()->dtor(); - ASSERT_FALSE(dtor->invoke(int{})); + ASSERT_FALSE(entt::resolve().dtor().invoke(int{})); } TEST_F(Meta, MetaData) { - auto *data = entt::resolve()->data("i"); + auto data = entt::resolve().data("i"); data_type instance{}; - ASSERT_NE(data, nullptr); - ASSERT_EQ(data->parent(), entt::resolve("data")); - ASSERT_EQ(data->type(), entt::resolve()); - ASSERT_STREQ(data->name(), "i"); - ASSERT_FALSE(data->is_const()); - ASSERT_FALSE(data->is_static()); - ASSERT_EQ(data->get(instance).cast(), 0); - ASSERT_TRUE(data->set(instance, 42)); - ASSERT_EQ(data->get(instance).cast(), 42); + ASSERT_TRUE(data); + ASSERT_EQ(data.parent(), entt::resolve("data")); + ASSERT_EQ(data.type(), entt::resolve()); + ASSERT_STREQ(data.name(), "i"); + ASSERT_FALSE(data.is_const()); + ASSERT_FALSE(data.is_static()); + ASSERT_EQ(data.get(instance).cast(), 0); + ASSERT_TRUE(data.set(instance, 42)); + ASSERT_EQ(data.get(instance).cast(), 42); - data->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 0); + data.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 0); }); - ASSERT_EQ(data->prop(properties::prop_bool), nullptr); + ASSERT_FALSE(data.prop(properties::prop_bool)); - auto *prop = data->prop(properties::prop_int); + auto prop = data.prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 0); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 0); } TEST_F(Meta, MetaDataConst) { - auto *data = entt::resolve()->data("j"); + auto data = entt::resolve().data("j"); data_type instance{}; - ASSERT_NE(data, nullptr); - ASSERT_EQ(data->parent(), entt::resolve("data")); - ASSERT_EQ(data->type(), entt::resolve()); - ASSERT_STREQ(data->name(), "j"); - ASSERT_TRUE(data->is_const()); - ASSERT_FALSE(data->is_static()); - ASSERT_EQ(data->get(instance).cast(), 1); - ASSERT_FALSE(data->set(instance, 42)); - ASSERT_EQ(data->get(instance).cast(), 1); + ASSERT_TRUE(data); + ASSERT_EQ(data.parent(), entt::resolve("data")); + ASSERT_EQ(data.type(), entt::resolve()); + ASSERT_STREQ(data.name(), "j"); + ASSERT_TRUE(data.is_const()); + ASSERT_FALSE(data.is_static()); + ASSERT_EQ(data.get(instance).cast(), 1); + ASSERT_FALSE(data.set(instance, 42)); + ASSERT_EQ(data.get(instance).cast(), 1); - data->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 1); + data.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 1); }); - ASSERT_EQ(data->prop(properties::prop_bool), nullptr); + ASSERT_FALSE(data.prop(properties::prop_bool)); - auto *prop = data->prop(properties::prop_int); + auto prop = data.prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 1); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 1); } TEST_F(Meta, MetaDataStatic) { - auto *data = entt::resolve()->data("h"); + auto data = entt::resolve().data("h"); - ASSERT_NE(data, nullptr); - ASSERT_EQ(data->parent(), entt::resolve("data")); - ASSERT_EQ(data->type(), entt::resolve()); - ASSERT_STREQ(data->name(), "h"); - ASSERT_FALSE(data->is_const()); - ASSERT_TRUE(data->is_static()); - ASSERT_EQ(data->get({}).cast(), 2); - ASSERT_TRUE(data->set({}, 42)); - ASSERT_EQ(data->get({}).cast(), 42); + ASSERT_TRUE(data); + ASSERT_EQ(data.parent(), entt::resolve("data")); + ASSERT_EQ(data.type(), entt::resolve()); + ASSERT_STREQ(data.name(), "h"); + ASSERT_FALSE(data.is_const()); + ASSERT_TRUE(data.is_static()); + ASSERT_EQ(data.get({}).cast(), 2); + ASSERT_TRUE(data.set({}, 42)); + ASSERT_EQ(data.get({}).cast(), 42); - data->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 2); + data.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 2); }); - ASSERT_EQ(data->prop(properties::prop_bool), nullptr); + ASSERT_FALSE(data.prop(properties::prop_bool)); - auto *prop = data->prop(properties::prop_int); + auto prop = data.prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 2); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 2); } TEST_F(Meta, MetaDataConstStatic) { - auto *data = entt::resolve()->data("k"); + auto data = entt::resolve().data("k"); - ASSERT_NE(data, nullptr); - ASSERT_EQ(data->parent(), entt::resolve("data")); - ASSERT_EQ(data->type(), entt::resolve()); - ASSERT_STREQ(data->name(), "k"); - ASSERT_TRUE(data->is_const()); - ASSERT_TRUE(data->is_static()); - ASSERT_EQ(data->get({}).cast(), 3); - ASSERT_FALSE(data->set({}, 42)); - ASSERT_EQ(data->get({}).cast(), 3); + ASSERT_TRUE(data); + ASSERT_EQ(data.parent(), entt::resolve("data")); + ASSERT_EQ(data.type(), entt::resolve()); + ASSERT_STREQ(data.name(), "k"); + ASSERT_TRUE(data.is_const()); + ASSERT_TRUE(data.is_static()); + ASSERT_EQ(data.get({}).cast(), 3); + ASSERT_FALSE(data.set({}, 42)); + ASSERT_EQ(data.get({}).cast(), 3); - data->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 3); + data.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 3); }); - ASSERT_EQ(data->prop(properties::prop_bool), nullptr); + ASSERT_FALSE(data.prop(properties::prop_bool)); - auto *prop = data->prop(properties::prop_int); + auto prop = data.prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 3); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 3); } TEST_F(Meta, MetaDataGetMetaAnyArg) { - auto *data = entt::resolve()->data("i"); + auto data = entt::resolve().data("i"); entt::meta_any any{data_type{}}; any.cast().i = 99; - const auto value = data->get(any); + const auto value = data.get(any); ASSERT_TRUE(value); ASSERT_TRUE(value.can_cast()); @@ -833,60 +832,58 @@ TEST_F(Meta, MetaDataGetMetaAnyArg) { } TEST_F(Meta, MetaDataGetInvalidArg) { - auto *data = entt::resolve()->data("i"); - ASSERT_FALSE(data->get(0)); + ASSERT_FALSE(entt::resolve().data("i").get(0)); } TEST_F(Meta, MetaDataSetMetaAnyArg) { - auto *data = entt::resolve()->data("i"); + auto data = entt::resolve().data("i"); entt::meta_any any{data_type{}}; entt::meta_any value{42}; ASSERT_EQ(any.cast().i, 0); - ASSERT_TRUE(data->set(any, value)); + ASSERT_TRUE(data.set(any, value)); ASSERT_EQ(any.cast().i, 42); } TEST_F(Meta, MetaDataSetInvalidArg) { - auto *data = entt::resolve()->data("i"); - ASSERT_FALSE(data->set({}, 'c')); + ASSERT_FALSE(entt::resolve().data("i").set({}, 'c')); } TEST_F(Meta, MetaDataSetCast) { - auto *data = entt::resolve()->data("empty"); + auto data = entt::resolve().data("empty"); data_type instance{}; ASSERT_EQ(empty_type::counter, 0); - ASSERT_TRUE(data->set(instance, fat_type{})); + ASSERT_TRUE(data.set(instance, fat_type{})); ASSERT_EQ(empty_type::counter, 1); } TEST_F(Meta, MetaDataSetConvert) { - auto *data = entt::resolve()->data("i"); + auto data = entt::resolve().data("i"); data_type instance{}; ASSERT_EQ(instance.i, 0); - ASSERT_TRUE(data->set(instance, 3.)); + ASSERT_TRUE(data.set(instance, 3.)); ASSERT_EQ(instance.i, 3); } TEST_F(Meta, MetaFunc) { - auto *func = entt::resolve()->func("f2"); + auto func = entt::resolve().func("f2"); func_type instance{}; - ASSERT_NE(func, nullptr); - ASSERT_EQ(func->parent(), entt::resolve("func")); - ASSERT_STREQ(func->name(), "f2"); - ASSERT_EQ(func->size(), entt::meta_func::size_type{2}); - ASSERT_FALSE(func->is_const()); - ASSERT_FALSE(func->is_static()); - ASSERT_EQ(func->ret(), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{0}), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{1}), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{2}), nullptr); + ASSERT_TRUE(func); + ASSERT_EQ(func.parent(), entt::resolve("func")); + ASSERT_STREQ(func.name(), "f2"); + ASSERT_EQ(func.size(), entt::meta_func::size_type{2}); + ASSERT_FALSE(func.is_const()); + ASSERT_FALSE(func.is_static()); + ASSERT_EQ(func.ret(), entt::resolve()); + ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve()); + ASSERT_EQ(func.arg(entt::meta_func::size_type{1}), entt::resolve()); + ASSERT_FALSE(func.arg(entt::meta_func::size_type{2})); - auto any = func->invoke(instance, 3, 2); - auto empty = func->invoke(instance); + auto any = func.invoke(instance, 3, 2); + auto empty = func.invoke(instance); ASSERT_FALSE(empty); ASSERT_TRUE(any); @@ -894,164 +891,164 @@ TEST_F(Meta, MetaFunc) { ASSERT_EQ(any.cast(), 4); ASSERT_EQ(func_type::value, 3); - func->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().template cast()); + func.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().template cast()); }); - ASSERT_EQ(func->prop(properties::prop_int), nullptr); + ASSERT_FALSE(func.prop(properties::prop_int)); - auto *prop = func->prop(properties::prop_bool); + auto prop = func.prop(properties::prop_bool); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().cast()); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().cast()); } TEST_F(Meta, MetaFuncConst) { - auto *func = entt::resolve()->func("f1"); + auto func = entt::resolve().func("f1"); func_type instance{}; - ASSERT_NE(func, nullptr); - ASSERT_EQ(func->parent(), entt::resolve("func")); - ASSERT_STREQ(func->name(), "f1"); - ASSERT_EQ(func->size(), entt::meta_func::size_type{1}); - ASSERT_TRUE(func->is_const()); - ASSERT_FALSE(func->is_static()); - ASSERT_EQ(func->ret(), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{0}), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{1}), nullptr); + ASSERT_TRUE(func); + ASSERT_EQ(func.parent(), entt::resolve("func")); + ASSERT_STREQ(func.name(), "f1"); + ASSERT_EQ(func.size(), entt::meta_func::size_type{1}); + ASSERT_TRUE(func.is_const()); + ASSERT_FALSE(func.is_static()); + ASSERT_EQ(func.ret(), entt::resolve()); + ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve()); + ASSERT_FALSE(func.arg(entt::meta_func::size_type{1})); - auto any = func->invoke(instance, 4); - auto empty = func->invoke(instance, 'c'); + auto any = func.invoke(instance, 4); + auto empty = func.invoke(instance, 'c'); ASSERT_FALSE(empty); ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any.cast(), 16); - func->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().template cast()); + func.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().template cast()); }); - ASSERT_EQ(func->prop(properties::prop_int), nullptr); + ASSERT_FALSE(func.prop(properties::prop_int)); - auto *prop = func->prop(properties::prop_bool); + auto prop = func.prop(properties::prop_bool); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().cast()); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().cast()); } TEST_F(Meta, MetaFuncRetVoid) { - auto *func = entt::resolve()->func("g"); + auto func = entt::resolve().func("g"); func_type instance{}; - ASSERT_NE(func, nullptr); - ASSERT_EQ(func->parent(), entt::resolve("func")); - ASSERT_STREQ(func->name(), "g"); - ASSERT_EQ(func->size(), entt::meta_func::size_type{1}); - ASSERT_FALSE(func->is_const()); - ASSERT_FALSE(func->is_static()); - ASSERT_EQ(func->ret(), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{0}), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{1}), nullptr); + ASSERT_TRUE(func); + ASSERT_EQ(func.parent(), entt::resolve("func")); + ASSERT_STREQ(func.name(), "g"); + ASSERT_EQ(func.size(), entt::meta_func::size_type{1}); + ASSERT_FALSE(func.is_const()); + ASSERT_FALSE(func.is_static()); + ASSERT_EQ(func.ret(), entt::resolve()); + ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve()); + ASSERT_FALSE(func.arg(entt::meta_func::size_type{1})); - auto any = func->invoke(instance, 5); + auto any = func.invoke(instance, 5); ASSERT_FALSE(any); ASSERT_EQ(func_type::value, 25); - func->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().template cast()); + func.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().template cast()); }); - ASSERT_EQ(func->prop(properties::prop_int), nullptr); + ASSERT_FALSE(func.prop(properties::prop_int)); - auto *prop = func->prop(properties::prop_bool); + auto prop = func.prop(properties::prop_bool); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().cast()); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().cast()); } TEST_F(Meta, MetaFuncStatic) { - auto *func = entt::resolve()->func("h"); + auto func = entt::resolve().func("h"); - ASSERT_NE(func, nullptr); - ASSERT_EQ(func->parent(), entt::resolve("func")); - ASSERT_STREQ(func->name(), "h"); - ASSERT_EQ(func->size(), entt::meta_func::size_type{1}); - ASSERT_FALSE(func->is_const()); - ASSERT_TRUE(func->is_static()); - ASSERT_EQ(func->ret(), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{0}), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{1}), nullptr); + ASSERT_TRUE(func); + ASSERT_EQ(func.parent(), entt::resolve("func")); + ASSERT_STREQ(func.name(), "h"); + ASSERT_EQ(func.size(), entt::meta_func::size_type{1}); + ASSERT_FALSE(func.is_const()); + ASSERT_TRUE(func.is_static()); + ASSERT_EQ(func.ret(), entt::resolve()); + ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve()); + ASSERT_FALSE(func.arg(entt::meta_func::size_type{1})); - auto any = func->invoke({}, 42); - auto empty = func->invoke({}, 'c'); + auto any = func.invoke({}, 42); + auto empty = func.invoke({}, 'c'); ASSERT_FALSE(empty); ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any.cast(), 42); - func->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().template cast()); + func.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().template cast()); }); - ASSERT_EQ(func->prop(properties::prop_int), nullptr); + ASSERT_FALSE(func.prop(properties::prop_int)); - auto *prop = func->prop(properties::prop_bool); + auto prop = func.prop(properties::prop_bool); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().cast()); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().cast()); } TEST_F(Meta, MetaFuncStaticRetVoid) { - auto *func = entt::resolve()->func("k"); + auto func = entt::resolve().func("k"); - ASSERT_NE(func, nullptr); - ASSERT_EQ(func->parent(), entt::resolve("func")); - ASSERT_STREQ(func->name(), "k"); - ASSERT_EQ(func->size(), entt::meta_func::size_type{1}); - ASSERT_FALSE(func->is_const()); - ASSERT_TRUE(func->is_static()); - ASSERT_EQ(func->ret(), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{0}), entt::resolve()); - ASSERT_EQ(func->arg(entt::meta_func::size_type{1}), nullptr); + ASSERT_TRUE(func); + ASSERT_EQ(func.parent(), entt::resolve("func")); + ASSERT_STREQ(func.name(), "k"); + ASSERT_EQ(func.size(), entt::meta_func::size_type{1}); + ASSERT_FALSE(func.is_const()); + ASSERT_TRUE(func.is_static()); + ASSERT_EQ(func.ret(), entt::resolve()); + ASSERT_EQ(func.arg(entt::meta_func::size_type{0}), entt::resolve()); + ASSERT_FALSE(func.arg(entt::meta_func::size_type{1})); - auto any = func->invoke({}, 42); + auto any = func.invoke({}, 42); ASSERT_FALSE(any); ASSERT_EQ(func_type::value, 42); - func->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); + func.prop([](auto *prop) { + ASSERT_TRUE(prop); ASSERT_EQ(prop->key(), properties::prop_bool); ASSERT_FALSE(prop->value().template cast()); }); - ASSERT_EQ(func->prop(properties::prop_int), nullptr); + ASSERT_FALSE(func.prop(properties::prop_int)); - auto *prop = func->prop(properties::prop_bool); + auto prop = func.prop(properties::prop_bool); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_bool); - ASSERT_FALSE(prop->value().cast()); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_bool); + ASSERT_FALSE(prop.value().cast()); } TEST_F(Meta, MetaFuncMetaAnyArgs) { - auto *func = entt::resolve()->func("f1"); - auto any = func->invoke(func_type{}, entt::meta_any{3}); + auto func = entt::resolve().func("f1"); + auto any = func.invoke(func_type{}, entt::meta_any{3}); ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); @@ -1059,13 +1056,13 @@ TEST_F(Meta, MetaFuncMetaAnyArgs) { } TEST_F(Meta, MetaFuncInvalidArgs) { - auto *func = entt::resolve()->func("f1"); - ASSERT_FALSE(func->invoke(empty_type{}, entt::meta_any{'c'})); + auto func = entt::resolve().func("f1"); + ASSERT_FALSE(func.invoke(empty_type{}, entt::meta_any{'c'})); } TEST_F(Meta, MetaFuncCastAndConvert) { - auto *func = entt::resolve()->func("f3"); - auto any = func->invoke(func_type{}, derived_type{}, 0, 3.); + auto func = entt::resolve().func("f3"); + auto any = func.invoke(func_type{}, derived_type{}, 0, 3.); ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); @@ -1073,114 +1070,114 @@ TEST_F(Meta, MetaFuncCastAndConvert) { } TEST_F(Meta, MetaType) { - auto *type = entt::resolve(); + auto type = entt::resolve(); - ASSERT_NE(type, nullptr); - ASSERT_STREQ(type->name(), "derived"); + ASSERT_TRUE(type); + ASSERT_STREQ(type.name(), "derived"); - type->prop([](auto *prop) { - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 99); + type.prop([](auto prop) { + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 99); }); - ASSERT_EQ(type->prop(properties::prop_bool), nullptr); + ASSERT_FALSE(type.prop(properties::prop_bool)); - auto *prop = type->prop(properties::prop_int); + auto prop = type.prop(properties::prop_int); - ASSERT_NE(prop, nullptr); - ASSERT_EQ(prop->key(), properties::prop_int); - ASSERT_EQ(prop->value(), 99); + ASSERT_TRUE(prop); + ASSERT_EQ(prop.key(), properties::prop_int); + ASSERT_EQ(prop.value(), 99); } TEST_F(Meta, MetaTypeTraits) { - ASSERT_TRUE(entt::resolve()->is_void()); - ASSERT_TRUE(entt::resolve()->is_enum()); - ASSERT_TRUE(entt::resolve()->is_class()); - ASSERT_TRUE(entt::resolve()->is_pointer()); - ASSERT_TRUE(entt::resolve()->is_function_pointer()); - ASSERT_TRUE(entt::resolve()->is_member_object_pointer()); - ASSERT_TRUE(entt::resolve()->is_member_function_pointer()); - ASSERT_TRUE(entt::resolve()->is_member_pointer()); - ASSERT_TRUE(entt::resolve()->is_arithmetic()); - ASSERT_TRUE(entt::resolve()->is_compound()); + ASSERT_TRUE(entt::resolve().is_void()); + ASSERT_TRUE(entt::resolve().is_enum()); + ASSERT_TRUE(entt::resolve().is_class()); + ASSERT_TRUE(entt::resolve().is_pointer()); + ASSERT_TRUE(entt::resolve().is_function_pointer()); + ASSERT_TRUE(entt::resolve().is_member_object_pointer()); + ASSERT_TRUE(entt::resolve().is_member_function_pointer()); + ASSERT_TRUE(entt::resolve().is_member_pointer()); + ASSERT_TRUE(entt::resolve().is_arithmetic()); + ASSERT_TRUE(entt::resolve().is_compound()); } TEST_F(Meta, MetaTypeBase) { - auto *type = entt::resolve(); + auto type = entt::resolve(); bool iterate = false; - type->base([&iterate](auto *base) { - ASSERT_EQ(base->type(), entt::resolve()); + type.base([&iterate](auto base) { + ASSERT_EQ(base.type(), entt::resolve()); iterate = true; }); ASSERT_TRUE(iterate); - ASSERT_EQ(type->base("base")->type(), entt::resolve()); + ASSERT_EQ(type.base("base").type(), entt::resolve()); } TEST_F(Meta, MetaTypeConv) { - auto *type = entt::resolve(); + auto type = entt::resolve(); bool iterate = false; - type->conv([&iterate](auto *conv) { - ASSERT_EQ(conv->type(), entt::resolve()); + type.conv([&iterate](auto conv) { + ASSERT_EQ(conv.type(), entt::resolve()); iterate = true; }); ASSERT_TRUE(iterate); - auto *conv = type->conv(); + auto conv = type.conv(); - ASSERT_EQ(conv->type(), entt::resolve()); - ASSERT_EQ(type->conv(), nullptr); + ASSERT_EQ(conv.type(), entt::resolve()); + ASSERT_FALSE(type.conv()); } TEST_F(Meta, MetaTypeCtor) { - auto *type = entt::resolve(); + auto type = entt::resolve(); int counter{}; - type->ctor([&counter](auto *) { + type.ctor([&counter](auto) { ++counter; }); ASSERT_EQ(counter, 2); - ASSERT_NE((type->ctor()), nullptr); - ASSERT_NE((type->ctor()), nullptr); + ASSERT_TRUE((type.ctor())); + ASSERT_TRUE((type.ctor())); } TEST_F(Meta, MetaTypeDtor) { - ASSERT_NE(entt::resolve()->dtor(), nullptr); - ASSERT_EQ(entt::resolve()->dtor(), nullptr); + ASSERT_TRUE(entt::resolve().dtor()); + ASSERT_FALSE(entt::resolve().dtor()); } TEST_F(Meta, MetaTypeData) { - auto *type = entt::resolve(); + auto type = entt::resolve(); int counter{}; - type->data([&counter](auto *) { + type.data([&counter](auto) { ++counter; }); ASSERT_EQ(counter, 5); - ASSERT_NE(type->data("i"), nullptr); + ASSERT_TRUE(type.data("i")); } TEST_F(Meta, MetaTypeFunc) { - auto *type = entt::resolve(); + auto type = entt::resolve(); int counter{}; - type->func([&counter](auto *) { + type.func([&counter](auto) { ++counter; }); ASSERT_EQ(counter, 6); - ASSERT_NE(type->func("f1"), nullptr); + ASSERT_TRUE(type.func("f1")); } TEST_F(Meta, MetaTypeConstruct) { - auto *type = entt::resolve(); - auto any = type->construct(base_type{}, 42, 'c'); + auto type = entt::resolve(); + auto any = type.construct(base_type{}, 42, 'c'); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -1189,8 +1186,8 @@ TEST_F(Meta, MetaTypeConstruct) { } TEST_F(Meta, MetaTypeConstructMetaAnyArgs) { - auto *type = entt::resolve(); - auto any = type->construct(entt::meta_any{base_type{}}, entt::meta_any{42}, entt::meta_any{'c'}); + auto type = entt::resolve(); + auto any = type.construct(entt::meta_any{base_type{}}, entt::meta_any{42}, entt::meta_any{'c'}); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -1200,15 +1197,15 @@ TEST_F(Meta, MetaTypeConstructMetaAnyArgs) { TEST_F(Meta, MetaTypeConstructInvalidArgs) { - auto *type = entt::resolve(); - auto any = type->construct(entt::meta_any{base_type{}}, entt::meta_any{'c'}, entt::meta_any{42}); + auto type = entt::resolve(); + auto any = type.construct(entt::meta_any{base_type{}}, entt::meta_any{'c'}, entt::meta_any{42}); ASSERT_FALSE(any); } TEST_F(Meta, MetaTypeConstructCastAndConvert) { - auto *type = entt::resolve(); - auto any = type->construct(entt::meta_any{derived_type{}}, entt::meta_any{42.}, entt::meta_any{'c'}); + auto type = entt::resolve(); + auto any = type.construct(entt::meta_any{derived_type{}}, entt::meta_any{42.}, entt::meta_any{'c'}); ASSERT_TRUE(any); ASSERT_TRUE(any.can_cast()); @@ -1218,115 +1215,111 @@ TEST_F(Meta, MetaTypeConstructCastAndConvert) { TEST_F(Meta, MetaTypeDestroyDtor) { - auto *type = entt::resolve(); + auto type = entt::resolve(); ASSERT_EQ(empty_type::counter, 0); - ASSERT_TRUE(type->destroy(empty_type{})); + ASSERT_TRUE(type.destroy(empty_type{})); ASSERT_EQ(empty_type::counter, 1); } TEST_F(Meta, MetaTypeDestroyDtorInvalidArg) { - auto *type = entt::resolve(); + auto type = entt::resolve(); ASSERT_EQ(empty_type::counter, 0); - ASSERT_FALSE(type->destroy('c')); + ASSERT_FALSE(type.destroy('c')); ASSERT_EQ(empty_type::counter, 0); } TEST_F(Meta, MetaTypeDestroyDtorCastAndConvert) { - auto *type = entt::resolve(); + auto type = entt::resolve(); ASSERT_EQ(empty_type::counter, 0); - ASSERT_FALSE(type->destroy(fat_type{})); + ASSERT_FALSE(type.destroy(fat_type{})); ASSERT_EQ(empty_type::counter, 0); - ASSERT_FALSE(entt::resolve()->destroy(42.)); + ASSERT_FALSE(entt::resolve().destroy(42.)); } TEST_F(Meta, MetaTypeDestroyNoDtor) { - auto *type = entt::resolve(); - ASSERT_TRUE(type->destroy('c')); + ASSERT_TRUE(entt::resolve().destroy('c')); } TEST_F(Meta, MetaTypeDestroyNoDtorInvalidArg) { - auto *type = entt::resolve(); - ASSERT_FALSE(type->destroy(42)); + ASSERT_FALSE(entt::resolve().destroy(42)); } TEST_F(Meta, MetaTypeDestroyNoDtorVoid) { - auto *type = entt::resolve(); - ASSERT_FALSE(type->destroy({})); + ASSERT_FALSE(entt::resolve().destroy({})); } TEST_F(Meta, MetaTypeDestroyNoDtorCastAndConvert) { - auto *type = entt::resolve(); - ASSERT_FALSE(type->destroy(42.)); + ASSERT_FALSE(entt::resolve().destroy(42.)); } TEST_F(Meta, MetaDataFromBase) { - auto *type = entt::resolve(); + auto type = entt::resolve(); concrete_type instance; - ASSERT_NE(type->data("i"), nullptr); - ASSERT_NE(type->data("j"), nullptr); + ASSERT_TRUE(type.data("i")); + ASSERT_TRUE(type.data("j")); ASSERT_EQ(instance.i, 0); ASSERT_EQ(instance.j, char{}); - ASSERT_TRUE(type->data("i")->set(instance, 3)); - ASSERT_TRUE(type->data("j")->set(instance, 'c')); + ASSERT_TRUE(type.data("i").set(instance, 3)); + ASSERT_TRUE(type.data("j").set(instance, 'c')); ASSERT_EQ(instance.i, 3); ASSERT_EQ(instance.j, 'c'); } TEST_F(Meta, MetaFuncFromBase) { - auto *type = entt::resolve(); - auto *base = entt::resolve(); + auto type = entt::resolve(); + auto base = entt::resolve(); concrete_type instance; - ASSERT_NE(type->func("f"), nullptr); - ASSERT_NE(type->func("g"), nullptr); - ASSERT_NE(type->func("h"), nullptr); + ASSERT_TRUE(type.func("f")); + ASSERT_TRUE(type.func("g")); + ASSERT_TRUE(type.func("h")); - ASSERT_EQ(type->func("f")->parent(), entt::resolve()); - ASSERT_EQ(type->func("g")->parent(), entt::resolve()); - ASSERT_EQ(type->func("h")->parent(), entt::resolve()); + ASSERT_EQ(type.func("f").parent(), entt::resolve()); + ASSERT_EQ(type.func("g").parent(), entt::resolve()); + ASSERT_EQ(type.func("h").parent(), entt::resolve()); ASSERT_EQ(instance.i, 0); ASSERT_EQ(instance.j, char{}); - type->func("f")->invoke(instance, 3); - type->func("h")->invoke(instance, 'c'); + type.func("f").invoke(instance, 3); + type.func("h").invoke(instance, 'c'); ASSERT_EQ(instance.i, 9); ASSERT_EQ(instance.j, 'c'); - base->func("g")->invoke(instance, 3); + base.func("g").invoke(instance, 3); ASSERT_EQ(instance.i, -3); } TEST_F(Meta, MetaPropFromBase) { - auto *type = entt::resolve(); - auto *prop_bool = type->prop(properties::prop_bool); - auto *prop_int = type->prop(properties::prop_int); + auto type = entt::resolve(); + auto prop_bool = type.prop(properties::prop_bool); + auto prop_int = type.prop(properties::prop_int); - ASSERT_NE(prop_bool, nullptr); - ASSERT_NE(prop_int, nullptr); + ASSERT_TRUE(prop_bool); + ASSERT_TRUE(prop_int); - ASSERT_FALSE(prop_bool->value().cast()); - ASSERT_EQ(prop_int->value().cast(), 42); + ASSERT_FALSE(prop_bool.value().cast()); + ASSERT_EQ(prop_int.value().cast(), 42); } TEST_F(Meta, AbstractClass) { - auto *type = entt::resolve(); + auto type = entt::resolve(); concrete_type instance; ASSERT_EQ(instance.i, 0); - type->func("f")->invoke(instance, 3); + type.func("f").invoke(instance, 3); ASSERT_EQ(instance.i, 3); - type->func("g")->invoke(instance, 3); + type.func("g").invoke(instance, 3); ASSERT_EQ(instance.i, -3); }