meta: allow updating values on meta properties

This commit is contained in:
Michele Caini
2023-03-17 08:45:58 +01:00
parent e0684f6348
commit f41b914197
2 changed files with 20 additions and 1 deletions

View File

@@ -763,6 +763,14 @@ struct meta_prop {
return node->value ? node->type(internal::meta_context::from(*ctx)).from_void(*ctx, nullptr, node->value.get()) : meta_any{meta_ctx_arg, *ctx};
}
/**
* @brief Returns the stored value by reference.
* @return A wrapper containing the value stored with the property.
*/
[[nodiscard]] meta_any value() {
return node->value ? node->type(internal::meta_context::from(*ctx)).from_void(*ctx, node->value.get(), nullptr) : meta_any{meta_ctx_arg, *ctx};
}
/**
* @brief Returns true if an object is valid, false otherwise.
* @return True if the object is valid, false otherwise.

View File

@@ -49,7 +49,18 @@ TEST_F(MetaProp, Functionalities) {
auto prop = entt::resolve<base_1_t>().prop("int"_hs);
ASSERT_TRUE(prop);
ASSERT_EQ(prop.value(), 42);
auto value = prop.value();
auto cvalue = std::as_const(prop).value();
ASSERT_NE(value.try_cast<int>(), nullptr);
ASSERT_EQ(cvalue.try_cast<int>(), nullptr);
ASSERT_NE(value.try_cast<const int>(), nullptr);
ASSERT_NE(cvalue.try_cast<const int>(), nullptr);
ASSERT_EQ(value, 42);
ASSERT_EQ(cvalue, 42);
}
TEST_F(MetaProp, FromBase) {