rename "uvalue::get_as" to "uvalue::as"

This commit is contained in:
BlackMATov
2023-02-18 01:29:47 +07:00
parent 8730e11d3c
commit e3b82ca382
35 changed files with 702 additions and 720 deletions

View File

@@ -87,5 +87,5 @@ TEST_CASE("meta/meta_manuals/class/usage") {
const meta::uvalue rectangle_v = rectangle_type.create(10, 20);
// calls the method with the dynamic rectangle instance 'rectangle_v'
CHECK(rectangle_area.invoke(rectangle_v).get_as<int>() == 200);
CHECK(rectangle_area.invoke(rectangle_v).as<int>() == 200);
}

View File

@@ -41,7 +41,7 @@ TEST_CASE("meta/meta_manuals/enum/type") {
for ( const meta::evalue& evalue : align_type.get_evalues() ) {
fmt::print(" - {}/{}\n",
evalue.get_name(),
evalue.get_underlying_value().get_as<int>());
evalue.get_underlying_value().as<int>());
}
// Output:
@@ -63,5 +63,5 @@ TEST_CASE("meta/meta_manuals/enum/usage") {
CHECK(align_type.value_to_name(e) == "center");
// ... and back again
CHECK(align_type.name_to_value("center").get_as<align>() == e);
CHECK(align_type.name_to_value("center").as<align>() == e);
}

View File

@@ -68,7 +68,7 @@ TEST_CASE("meta/meta_manuals/function/usage") {
CHECK(sub_result_value.get_type() == meta::resolve_type<int>());
// casts the dynamic returned value to the typed value
const int sub_function_typed_result = sub_result_value.get_as<int>();
const int sub_function_typed_result = sub_result_value.as<int>();
// here is our typed result
CHECK(sub_function_typed_result == 42);

View File

@@ -60,9 +60,9 @@ TEST_CASE("meta/meta_manuals/inplace") {
CHECK(ivec2_ptr.get_type() == meta::resolve_type<ivec2*>());
// interacts with the created object as usual
CHECK(ivec2_x.get(ivec2_ptr).get_as<int>() == 2);
CHECK(ivec2_y.get(ivec2_ptr).get_as<int>() == 3);
CHECK(ivec2_length2(ivec2_ptr).get_as<int>() == 13);
CHECK(ivec2_x.get(ivec2_ptr).as<int>() == 2);
CHECK(ivec2_y.get(ivec2_ptr).as<int>() == 3);
CHECK(ivec2_length2(ivec2_ptr).as<int>() == 13);
// you must manually call the object's destructor
CHECK(ivec2_type.destroy_at(ivec2_buffer.get_data()));

View File

@@ -59,7 +59,7 @@ TEST_CASE("meta/meta_manuals/member/usage") {
CHECK(ivec2_x_value.get_type() == meta::resolve_type<int>());
// casts the dynamic value to the typed value
const int ivec2_x_typed_value = ivec2_x_value.get_as<int>();
const int ivec2_x_typed_value = ivec2_x_value.as<int>();
// here is our member typed value
CHECK(ivec2_x_typed_value == 42);

View File

@@ -71,14 +71,14 @@ TEST_CASE("meta/meta_manuals/metadata") {
fmt::print("{} ({})\n",
type_name,
class_metadata.at("tooltip").get_as<std::string>());
class_metadata.at("tooltip").as<std::string>());
for ( const meta::member& member : class_type.get_members() ) {
const meta::metadata_map& member_metadata = member.get_metadata();
fmt::print(" - {} ({})\n",
member.get_name(),
member_metadata.at("tooltip").get_as<std::string>());
member_metadata.at("tooltip").as<std::string>());
}
}
@@ -88,7 +88,7 @@ TEST_CASE("meta/meta_manuals/metadata") {
fmt::print(" + {}/{} ({})\n",
function.get_name(),
function.get_type().get_arity(),
function_metadata.at("tooltip").get_as<std::string>());
function_metadata.at("tooltip").as<std::string>());
for ( const meta::argument& argument : function.get_arguments() ) {
fmt::print(" ({}) : {}\n",

View File

@@ -76,7 +76,7 @@ TEST_CASE("meta/meta_manuals/method/usage") {
// checks the type and value of the result
CHECK(ivec2_add_result_value.get_type() == meta::resolve_type<ivec2>());
CHECK(ivec2_add_result_value.get_as<ivec2>() == ivec2{42, 21});
CHECK(ivec2_add_result_value.as<ivec2>() == ivec2{42, 21});
// checks the result of our manipulations
CHECK(v == ivec2{42, 21});

View File

@@ -71,18 +71,18 @@ TEST_CASE("meta/meta_manuals/scopes/local") {
const meta::function dot3_function = math_scope.get_function("dot3");
// calls and checks found functions
CHECK(dot2_function(ivec2{3,4}, ivec2{5,6}).get_as<int>() == 39);
CHECK(dot3_function(ivec3{3,4,5}, ivec3{6,7,8}).get_as<int>() == 86);
CHECK(dot2_function(ivec2{3,4}, ivec2{5,6}).as<int>() == 39);
CHECK(dot3_function(ivec3{3,4,5}, ivec3{6,7,8}).as<int>() == 86);
// and free variables, of course
const meta::variable unit2_variable = math_scope.get_variable("unit2");
const meta::variable unit3_variable = math_scope.get_variable("unit3");
// checks and uses found variables with functions
CHECK(unit2_variable.get().get_as<ivec2>() == ivec2{1,1});
CHECK(unit3_variable.get().get_as<ivec3>() == ivec3{1,1,1});
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).get_as<int>() == 2);
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).get_as<int>() == 3);
CHECK(unit2_variable.get().as<ivec2>() == ivec2{1,1});
CHECK(unit3_variable.get().as<ivec3>() == ivec3{1,1,1});
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).as<int>() == 2);
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).as<int>() == 3);
}
TEST_CASE("meta/meta_manuals/scopes/global") {
@@ -105,6 +105,6 @@ TEST_CASE("meta/meta_manuals/scopes/global") {
const meta::variable unit3_variable = math_scope.get_variable("unit3");
// everything works as expected
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).get_as<int>() == 2);
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).get_as<int>() == 3);
CHECK(dot2_function(unit2_variable.get(), unit2_variable.get()).as<int>() == 2);
CHECK(dot3_function(unit3_variable.get(), unit3_variable.get()).as<int>() == 3);
}

View File

@@ -68,34 +68,34 @@ TEST_CASE("meta/meta_manuals/uvalue/usage") {
CHECK(val.get_type() == meta::resolve_type<int>());
// we can get a reference to the stored data and even change it
val.get_as<int>() = 21;
CHECK(val.get_as<int>() == 21);
val.as<int>() = 21;
CHECK(val.as<int>() == 21);
// uvalue can be copied, assigned, and moved
val = rectangle{10, 20};
CHECK(val.get_type() == meta::resolve_type<rectangle>());
// also, it supports upcasting for registered types
CHECK(val.get_as<shape>().get_area() == 200);
CHECK(val.as<shape>().get_area() == 200);
// an exception will be thrown if we try to get a wrong type
CHECK_THROWS(std::ignore = val.get_as<int>());
CHECK_THROWS(std::ignore = val.as<int>());
// but we can use try_get_as for safe access
CHECK(val.try_get_as<shape>());
if ( shape* s = val.try_get_as<shape>() ) {
// but we can use try_as for safe access
CHECK(val.try_as<shape>());
if ( shape* s = val.try_as<shape>() ) {
CHECK(s->get_area() == 200);
}
// also, upcasting is supported for pointers
rectangle rect{3, 5};
val = &rect;
CHECK(val.get_as<shape*>()->get_area() == 15);
CHECK(val.as<shape*>()->get_area() == 15);
CHECK(val.get_type() == meta::resolve_type<rectangle*>());
// and we can use try_get_as for pointers too
CHECK(val.try_get_as<shape*>());
if ( shape* s = val.try_get_as<shape*>() ) {
// and we can use try_as for pointers too
CHECK(val.try_as<shape*>());
if ( shape* s = val.try_as<shape*>() ) {
CHECK(s->get_area() == 15);
}
}

View File

@@ -37,7 +37,7 @@ TEST_CASE("meta/meta_manuals/variable/usage") {
CHECK(pi_variable_value.get_type() == meta::resolve_type<double>());
// checks the typed variable value
CHECK(pi_variable_value.get_as<double>() == doctest::Approx(3.14).epsilon(0.01));
CHECK(pi_variable_value.as<double>() == doctest::Approx(3.14).epsilon(0.01));
// we can change variable values, but only non-const
CHECK_FALSE(pi_variable.try_set(6.0));
@@ -47,7 +47,7 @@ TEST_CASE("meta/meta_manuals/variable/usage") {
for ( const meta::variable& variable : constants_scope.get_variables() ) {
fmt::print(" - {} : {}\n",
variable.get_name(),
variable.get().get_as<double>());
variable.get().as<double>());
}
// Output: