* props no longer depend on the value type
* more tests for meta_prop
This commit is contained in:
Michele Caini
2021-03-09 10:25:12 +01:00
parent 4f93995bd7
commit 80e73c1089
3 changed files with 22 additions and 10 deletions

View File

@@ -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;

View File

@@ -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;
}
/**

View File

@@ -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.);
}