meta:
* props no longer depend on the value type * more tests for meta_prop
This commit is contained in:
@@ -104,23 +104,20 @@ private:
|
||||
template<std::size_t>
|
||||
void unroll(choice_t<0>) {}
|
||||
|
||||
template<std::size_t = 0, typename Key, typename... Value>
|
||||
void assign(Key &&key, Value &&... value) {
|
||||
static meta_any property[1u + sizeof...(Value)]{};
|
||||
template<std::size_t = 0, typename Key>
|
||||
void assign(Key &&key, meta_any value = {}) {
|
||||
static meta_any property[2u]{};
|
||||
|
||||
static internal::meta_prop_node node{
|
||||
nullptr,
|
||||
property,
|
||||
sizeof...(Value) ? property + 1u : nullptr
|
||||
property + 1u
|
||||
};
|
||||
|
||||
entt::meta_any instance{std::forward<Key>(key)};
|
||||
ENTT_ASSERT(!internal::find_if_not(&instance, *curr, &node));
|
||||
property[0u] = std::move(instance);
|
||||
|
||||
if constexpr(sizeof...(Value) > 0) {
|
||||
property[1u] = (std::forward<Value>(value), ...);
|
||||
}
|
||||
property[1u] = std::move(value);
|
||||
|
||||
if(!internal::find_if(&node, *curr)) {
|
||||
node.next = *curr;
|
||||
|
||||
@@ -659,7 +659,7 @@ struct meta_prop {
|
||||
* @return A meta any containing the value stored with the property.
|
||||
*/
|
||||
[[nodiscard]] meta_any value() const {
|
||||
return node->value ? *node->value : meta_any{};
|
||||
return *node->value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -62,10 +62,25 @@ TEST_F(MetaProp, FromBase) {
|
||||
}
|
||||
|
||||
TEST_F(MetaProp, ReRegistration) {
|
||||
using namespace entt::literals;
|
||||
|
||||
MetaProp::StaticSetUp();
|
||||
|
||||
auto *node = entt::internal::meta_info<base_2_t>::resolve();
|
||||
auto *node = entt::internal::meta_info<base_1_t>::resolve();
|
||||
auto type = entt::resolve<base_1_t>();
|
||||
|
||||
ASSERT_NE(node->prop, nullptr);
|
||||
ASSERT_EQ(node->prop->next, nullptr);
|
||||
|
||||
ASSERT_TRUE(type.prop("int"_hs));
|
||||
ASSERT_EQ(type.prop("int"_hs).value().cast<int>(), 42);
|
||||
|
||||
entt::meta<base_1_t>().prop("double"_hs, 3.);
|
||||
|
||||
ASSERT_NE(node->prop, nullptr);
|
||||
ASSERT_EQ(node->prop->next, nullptr);
|
||||
|
||||
ASSERT_FALSE(type.prop("int"_hs));
|
||||
ASSERT_TRUE(type.prop("double"_hs));
|
||||
ASSERT_EQ(type.prop("double"_hs).value().cast<double>(), 3.);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user