From cdb3d0de54d73468b1b1fd492114f3e9c39eaa4f Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 12 Jul 2021 23:05:18 +0700 Subject: [PATCH] explicit make_info function --- headers/meta.hpp/meta_class.hpp | 25 ++++-- headers/meta.hpp/meta_data.hpp | 5 +- headers/meta.hpp/meta_field.hpp | 5 +- headers/meta.hpp/meta_function.hpp | 5 +- headers/meta.hpp/meta_method.hpp | 5 +- headers/meta.hpp/meta_namespace.hpp | 20 +++-- headers/meta.hpp/meta_registry.hpp | 19 +++++ headers/meta.hpp/meta_variable.hpp | 5 +- untests/meta_class_tests.cpp | 120 +++++++++++++++------------- untests/meta_data_tests.cpp | 51 +++++++----- untests/meta_examples.cpp | 2 +- untests/meta_family_tests.cpp | 36 ++++----- untests/meta_field_tests.cpp | 4 +- untests/meta_function_tests.cpp | 12 +-- untests/meta_method_tests.cpp | 24 +++--- untests/meta_namespace_tests.cpp | 69 +++++++++------- untests/meta_registry_tests.cpp | 4 +- untests/meta_type_tests.cpp | 16 ++-- untests/meta_variable_tests.cpp | 8 +- 19 files changed, 252 insertions(+), 183 deletions(-) diff --git a/headers/meta.hpp/meta_class.hpp b/headers/meta.hpp/meta_class.hpp index 31a510a..2912fb1 100644 --- a/headers/meta.hpp/meta_class.hpp +++ b/headers/meta.hpp/meta_class.hpp @@ -24,7 +24,7 @@ namespace meta_hpp explicit class_(std::string id) : info_{detail::typename_arg, std::move(id)} {} - operator const class_info&() const noexcept { + const class_info& make_info() const { return info_; } @@ -34,27 +34,38 @@ namespace meta_hpp return *this; } private: - void add_(const class_info& info) { + template < typename InternalClass > + void add_(class_ internal) { + class_info info = std::move(internal).make_info(); detail::merge_with(info_.classes_, info.id(), info, &class_info::merge); } - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } - void add_(const field_info& info) { + template < typename FieldType > + void add_(field_ internal) { + field_info info = std::move(internal).make_info(); detail::merge_with(info_.fields_, info.id(), info, &field_info::merge); } - void add_(const function_info& info) { + template < typename FunctionType > + void add_(function_ internal) { + function_info info = std::move(internal).make_info(); detail::merge_with(info_.functions_, info.id(), info, &function_info::merge); } - void add_(const method_info& info) { + template < typename MethodType > + void add_(method_ internal) { + method_info info = std::move(internal).make_info(); detail::merge_with(info_.methods_, info.id(), info, &method_info::merge); } - void add_(const variable_info& info) { + template < typename VariableType > + void add_(variable_ internal) { + variable_info info = std::move(internal).make_info(); detail::merge_with(info_.variables_, info.id(), info, &variable_info::merge); } private: diff --git a/headers/meta.hpp/meta_data.hpp b/headers/meta.hpp/meta_data.hpp index f68a9b3..3ce39f8 100644 --- a/headers/meta.hpp/meta_data.hpp +++ b/headers/meta.hpp/meta_data.hpp @@ -17,7 +17,7 @@ namespace meta_hpp explicit data_(std::string id, value value) : info_{std::move(id), std::move(value)} {} - operator const data_info&() const noexcept { + const data_info& make_info() const { return info_; } @@ -27,7 +27,8 @@ namespace meta_hpp return *this; } private: - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } private: diff --git a/headers/meta.hpp/meta_field.hpp b/headers/meta.hpp/meta_field.hpp index ceb758e..0b5481b 100644 --- a/headers/meta.hpp/meta_field.hpp +++ b/headers/meta.hpp/meta_field.hpp @@ -22,7 +22,7 @@ namespace meta_hpp explicit field_(std::string id, FieldType field_ptr) : info_{std::move(id), field_ptr} {} - operator const field_info&() const noexcept { + const field_info& make_info() const { return info_; } @@ -32,7 +32,8 @@ namespace meta_hpp return *this; } private: - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } private: diff --git a/headers/meta.hpp/meta_function.hpp b/headers/meta.hpp/meta_function.hpp index 6fb5d41..c1ab125 100644 --- a/headers/meta.hpp/meta_function.hpp +++ b/headers/meta.hpp/meta_function.hpp @@ -22,7 +22,7 @@ namespace meta_hpp explicit function_(std::string id, FunctionType function_ptr) : info_{std::move(id), function_ptr} {} - operator const function_info&() const noexcept { + const function_info& make_info() const { return info_; } @@ -32,7 +32,8 @@ namespace meta_hpp return *this; } private: - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } private: diff --git a/headers/meta.hpp/meta_method.hpp b/headers/meta.hpp/meta_method.hpp index a89393d..f01a5bc 100644 --- a/headers/meta.hpp/meta_method.hpp +++ b/headers/meta.hpp/meta_method.hpp @@ -22,7 +22,7 @@ namespace meta_hpp explicit method_(std::string id, MethodType method_ptr) : info_{std::move(id), method_ptr} {} - operator const method_info&() const { + const method_info& make_info() const { return info_; } @@ -32,7 +32,8 @@ namespace meta_hpp return *this; } private: - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } private: diff --git a/headers/meta.hpp/meta_namespace.hpp b/headers/meta.hpp/meta_namespace.hpp index 9a05806..6fe4ce2 100644 --- a/headers/meta.hpp/meta_namespace.hpp +++ b/headers/meta.hpp/meta_namespace.hpp @@ -22,7 +22,7 @@ namespace meta_hpp explicit namespace_(std::string id) : info_{std::move(id)} {} - operator const namespace_info&() const noexcept { + const namespace_info& make_info() const { return info_; } @@ -32,23 +32,31 @@ namespace meta_hpp return *this; } private: - void add_(const class_info& info) { + template < typename InternalClass > + void add_(class_ internal) { + class_info info = std::move(internal).make_info(); detail::merge_with(info_.classes_, info.id(), info, &class_info::merge); } - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } - void add_(const function_info& info) { + template < typename FunctionType > + void add_(function_ internal) { + function_info info = std::move(internal).make_info(); detail::merge_with(info_.functions_, info.id(), info, &function_info::merge); } - void add_(const namespace_info& info) { + void add_(namespace_ internal) { + namespace_info info = std::move(internal).make_info(); detail::merge_with(info_.namespaces_, info.id(), info, &namespace_info::merge); } - void add_(const variable_info& info) { + template < typename VariableType > + void add_(variable_ internal) { + variable_info info = std::move(internal).make_info(); detail::merge_with(info_.variables_, info.id(), info, &variable_info::merge); } private: diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp index c371aec..5b9f41b 100644 --- a/headers/meta.hpp/meta_registry.hpp +++ b/headers/meta.hpp/meta_registry.hpp @@ -121,6 +121,25 @@ namespace meta_hpp (add_(std::string{}, std::forward(internals)), ...); return *this; } + private: + template < typename InternalClass > + void add_(const std::string& prefix, class_ internal) { + add_(prefix, std::move(internal).make_info()); + } + + template < typename FunctionType > + void add_(const std::string& prefix, function_ internal) { + add_(prefix, std::move(internal).make_info()); + } + + void add_(const std::string& prefix, namespace_ internal) { + add_(prefix, std::move(internal).make_info()); + } + + template < typename VariableType > + void add_(const std::string& prefix, variable_ internal) { + add_(prefix, std::move(internal).make_info()); + } private: void add_(const std::string& prefix, const class_info& info) { const std::string name = prefix.empty() diff --git a/headers/meta.hpp/meta_variable.hpp b/headers/meta.hpp/meta_variable.hpp index 33059eb..e8a8e49 100644 --- a/headers/meta.hpp/meta_variable.hpp +++ b/headers/meta.hpp/meta_variable.hpp @@ -22,7 +22,7 @@ namespace meta_hpp explicit variable_(std::string id, VariableType variable_ptr) : info_{std::move(id), variable_ptr} {} - operator const variable_info&() const noexcept { + const variable_info& make_info() const { return info_; } @@ -32,7 +32,8 @@ namespace meta_hpp return *this; } private: - void add_(const data_info& info) { + void add_(data_ internal) { + data_info info = std::move(internal).make_info(); detail::merge_with(info_.datas_, info.id(), info, &data_info::merge); } private: diff --git a/untests/meta_class_tests.cpp b/untests/meta_class_tests.cpp index fd61813..109126e 100644 --- a/untests/meta_class_tests.cpp +++ b/untests/meta_class_tests.cpp @@ -48,16 +48,18 @@ TEST_CASE("meta/class") { namespace meta = meta_hpp; meta::class_ class_{"clazz"}; - const meta::class_info& clazz_info = class_; - CHECK_FALSE(clazz_info.get_class("clazz2")); - CHECK_FALSE(clazz_info.get_field("field")); - CHECK_FALSE(clazz_info.get_field("cfield")); - CHECK_FALSE(clazz_info.get_function("func")); - CHECK_FALSE(clazz_info.get_method("method")); - CHECK_FALSE(clazz_info.get_method("cmethod")); - CHECK_FALSE(clazz_info.get_variable("variable")); - CHECK_FALSE(clazz_info.get_variable("cvariable")); + { + const meta::class_info info = class_.make_info(); + CHECK_FALSE(info.get_class("clazz2")); + CHECK_FALSE(info.get_field("field")); + CHECK_FALSE(info.get_field("cfield")); + CHECK_FALSE(info.get_function("func")); + CHECK_FALSE(info.get_method("method")); + CHECK_FALSE(info.get_method("cmethod")); + CHECK_FALSE(info.get_variable("variable")); + CHECK_FALSE(info.get_variable("cvariable")); + } class_( meta::class_("clazz2"), @@ -69,53 +71,56 @@ TEST_CASE("meta/class") { meta::variable_("variable", &clazz::variable), meta::variable_("cvariable", &clazz::cvariable)); - CHECK(clazz_info.get_class("clazz2")); - CHECK(clazz_info.get_field("field")); - CHECK(clazz_info.get_field("cfield")); - CHECK(clazz_info.get_function("func")); - CHECK(clazz_info.get_method("method")); - CHECK(clazz_info.get_method("cmethod")); - CHECK(clazz_info.get_variable("variable")); - CHECK(clazz_info.get_variable("cvariable")); - { - meta::class_info clazz2_info = clazz_info.get_class("clazz2").value(); - CHECK(clazz2_info.id() == "clazz2"); - } + const meta::class_info info = class_.make_info(); + CHECK(info.get_class("clazz2")); + CHECK(info.get_field("field")); + CHECK(info.get_field("cfield")); + CHECK(info.get_function("func")); + CHECK(info.get_method("method")); + CHECK(info.get_method("cmethod")); + CHECK(info.get_variable("variable")); + CHECK(info.get_variable("cvariable")); - { - meta::field_info field_info = clazz_info.get_field("field").value(); - CHECK(field_info.id() == "field"); - } + { + meta::class_info clazz2_info = info.get_class("clazz2").value(); + CHECK(clazz2_info.id() == "clazz2"); + } - { - meta::field_info cfield_info = clazz_info.get_field("cfield").value(); - CHECK(cfield_info.id() == "cfield"); - } + { + meta::field_info field_info = info.get_field("field").value(); + CHECK(field_info.id() == "field"); + } - { - meta::function_info function_info = clazz_info.get_function("func").value(); - CHECK(function_info.id() == "func"); - } + { + meta::field_info cfield_info = info.get_field("cfield").value(); + CHECK(cfield_info.id() == "cfield"); + } - { - meta::method_info method_info = clazz_info.get_method("method").value(); - CHECK(method_info.id() == "method"); - } + { + meta::function_info function_info = info.get_function("func").value(); + CHECK(function_info.id() == "func"); + } - { - meta::method_info cmethod_info = clazz_info.get_method("cmethod").value(); - CHECK(cmethod_info.id() == "cmethod"); - } + { + meta::method_info method_info = info.get_method("method").value(); + CHECK(method_info.id() == "method"); + } - { - meta::variable_info variable_info = clazz_info.get_variable("variable").value(); - CHECK(variable_info.id() == "variable"); - } + { + meta::method_info cmethod_info = info.get_method("cmethod").value(); + CHECK(cmethod_info.id() == "cmethod"); + } - { - meta::variable_info cvariable_info = clazz_info.get_variable("cvariable").value(); - CHECK(cvariable_info.id() == "cvariable"); + { + meta::variable_info variable_info = info.get_variable("variable").value(); + CHECK(variable_info.id() == "variable"); + } + + { + meta::variable_info cvariable_info = info.get_variable("cvariable").value(); + CHECK(cvariable_info.id() == "cvariable"); + } } } @@ -123,7 +128,6 @@ TEST_CASE("meta/class/merge") { namespace meta = meta_hpp; meta::class_ clazz_{"clazz"}; - const meta::class_info& clazz_info = clazz_; SUBCASE("merge") { CHECK_NOTHROW(clazz_( @@ -144,14 +148,18 @@ TEST_CASE("meta/class/merge") { ) ), std::logic_error); - CHECK(clazz_info.get_class("child")); - CHECK(clazz_info.get_class("child")->get_field("field")); - CHECK(clazz_info.get_class("child")->get_field("cfield")); - { - clazz::clazz2 instance{}; - CHECK(clazz_info.get_class("child")->get_field("field")->get(instance).to_int() == 21); - CHECK(clazz_info.get_class("child")->get_field("cfield")->get(instance).to_int() == 22); + const meta::class_info info = clazz_.make_info(); + + CHECK(info.get_class("child")); + CHECK(info.get_class("child")->get_field("field")); + CHECK(info.get_class("child")->get_field("cfield")); + + { + clazz::clazz2 instance{}; + CHECK(info.get_class("child")->get_field("field")->get(instance).to_int() == 21); + CHECK(info.get_class("child")->get_field("cfield")->get(instance).to_int() == 22); + } } } } diff --git a/untests/meta_data_tests.cpp b/untests/meta_data_tests.cpp index b1cb5af..7dd63aa 100644 --- a/untests/meta_data_tests.cpp +++ b/untests/meta_data_tests.cpp @@ -31,10 +31,13 @@ TEST_CASE("meta/data") { using namespace std::string_literals; meta::data_ data_("key"s, "value"s); - const meta::data_info& data_info = data_; - CHECK(data_info.id() == "key"); - CHECK(data_info.get().to_string() == "value"); + { + const meta::data_info info = data_.make_info(); + + CHECK(info.id() == "key"); + CHECK(info.get().to_string() == "value"); + } { data_( @@ -43,11 +46,15 @@ TEST_CASE("meta/data") { ) ); - CHECK(data_info.get_data("key2")); - CHECK(data_info.get_data("key2")->get().to_string() == "value2"); + { + const meta::data_info info = data_.make_info(); - CHECK(data_info.get_data("key2")->get_data("key3")); - CHECK(data_info.get_data("key2")->get_data("key3")->get().to_string() == "value3"); + CHECK(info.get_data("key2")); + CHECK(info.get_data("key2")->get().to_string() == "value2"); + + CHECK(info.get_data("key2")->get_data("key3")); + CHECK(info.get_data("key2")->get_data("key3")->get().to_string() == "value3"); + } } { @@ -57,14 +64,18 @@ TEST_CASE("meta/data") { ) ); - CHECK(data_info.get_data("key2")); - CHECK(data_info.get_data("key2")->get().to_string() == "value2"); + { + const meta::data_info info = data_.make_info(); - CHECK(data_info.get_data("key2")->get_data("key3")); - CHECK(data_info.get_data("key2")->get_data("key3")->get().to_string() == "value3"); + CHECK(info.get_data("key2")); + CHECK(info.get_data("key2")->get().to_string() == "value2"); - CHECK(data_info.get_data("key2")->get_data("key4")); - CHECK(data_info.get_data("key2")->get_data("key4")->get().to_string() == "value4"); + CHECK(info.get_data("key2")->get_data("key3")); + CHECK(info.get_data("key2")->get_data("key3")->get().to_string() == "value3"); + + CHECK(info.get_data("key2")->get_data("key4")); + CHECK(info.get_data("key2")->get_data("key4")->get().to_string() == "value4"); + } } } @@ -74,7 +85,7 @@ TEST_CASE("meta/data/class") { const meta::class_info clazz_info = meta::class_("clazz")( meta::data_("hello"s, "world"s) - ); + ).make_info(); CHECK(clazz_info.get_data("hello")); CHECK(clazz_info.get_data("hello")->get().to_string() == "world"); @@ -88,7 +99,7 @@ TEST_CASE("meta/data/data") { meta::data_("hello"s, "world"s)( meta::data_("hello2"s, "world2"s) ) - ); + ).make_info(); CHECK(clazz_info.get_data("hello")); CHECK(clazz_info.get_data("hello")->get_data("hello2")); @@ -103,7 +114,7 @@ TEST_CASE("meta/data/field") { meta::field_("field", &clazz::field)( meta::data_("hello"s, "world"s) ) - ); + ).make_info(); CHECK(clazz_info.get_field("field")); CHECK(clazz_info.get_field("field")->get_data("hello")); @@ -118,7 +129,7 @@ TEST_CASE("meta/data/function") { meta::function_("function", &clazz::function)( meta::data_("hello"s, "world"s) ) - ); + ).make_info(); CHECK(clazz_info.get_function("function")); CHECK(clazz_info.get_function("function")->get_data("hello")); @@ -133,7 +144,7 @@ TEST_CASE("meta/data/method") { meta::method_("method", &clazz::method)( meta::data_("hello"s, "world"s) ) - ); + ).make_info(); CHECK(clazz_info.get_method("method")); CHECK(clazz_info.get_method("method")->get_data("hello")); @@ -146,7 +157,7 @@ TEST_CASE("meta/data/namespace") { const meta::namespace_info ns_info = meta::namespace_("ns")( meta::data_("hello"s, "world"s) - ); + ).make_info(); CHECK(ns_info.get_data("hello")); CHECK(ns_info.get_data("hello")->get().to_string() == "world"); @@ -160,7 +171,7 @@ TEST_CASE("meta/data/variable") { meta::variable_("variable", &clazz::variable)( meta::data_("hello"s, "world"s) ) - ); + ).make_info(); CHECK(clazz_info.get_variable("variable")); CHECK(clazz_info.get_variable("variable")->get_data("hello")); diff --git a/untests/meta_examples.cpp b/untests/meta_examples.cpp index e7af521..0aa3a4a 100644 --- a/untests/meta_examples.cpp +++ b/untests/meta_examples.cpp @@ -113,7 +113,7 @@ TEST_CASE("meta/examples/simple") { ), function_("iadd2", select(&add)), function_("iadd3", select(&add)) - ); + ).make_info(); class_info ivec2_info = vmath_info.get_class("ivec2").value(); diff --git a/untests/meta_family_tests.cpp b/untests/meta_family_tests.cpp index bc27408..f491e12 100644 --- a/untests/meta_family_tests.cpp +++ b/untests/meta_family_tests.cpp @@ -85,17 +85,17 @@ TEST_CASE("meta/family") { using namespace std::string_literals; SUBCASE("class") { - meta::class_info ivec2_info = meta::class_("ivec2"); - meta::class_info ivec3_info = meta::class_("ivec3"); + meta::class_info ivec2_info = meta::class_("ivec2").make_info(); + meta::class_info ivec3_info = meta::class_("ivec3").make_info(); CHECK(ivec2_info.family() != ivec3_info.family()); } SUBCASE("field") { - meta::field_info ivec2_x_info = meta::field_("x", &ivec2::x); - meta::field_info ivec2_y_info = meta::field_("y", &ivec2::y); + meta::field_info ivec2_x_info = meta::field_("x", &ivec2::x).make_info(); + meta::field_info ivec2_y_info = meta::field_("y", &ivec2::y).make_info(); - meta::field_info ivec3_x_info = meta::field_("x", &ivec3::x); - meta::field_info ivec3_y_info = meta::field_("y", &ivec3::y); + meta::field_info ivec3_x_info = meta::field_("x", &ivec3::x).make_info(); + meta::field_info ivec3_y_info = meta::field_("y", &ivec3::y).make_info(); CHECK(ivec2_x_info.family() == ivec2_y_info.family()); @@ -104,11 +104,11 @@ TEST_CASE("meta/family") { } SUBCASE("function") { - meta::function_info iadd2_info = meta::function_("iadd2", &iadd2); - meta::function_info isub2_info = meta::function_("isub2", &isub2); + meta::function_info iadd2_info = meta::function_("iadd2", &iadd2).make_info(); + meta::function_info isub2_info = meta::function_("isub2", &isub2).make_info(); - meta::function_info iadd3_info = meta::function_("iadd3", &iadd3); - meta::function_info isub3_info = meta::function_("isub3", &isub3); + meta::function_info iadd3_info = meta::function_("iadd3", &iadd3).make_info(); + meta::function_info isub3_info = meta::function_("isub3", &isub3).make_info(); CHECK(iadd2_info.family() == isub2_info.family()); CHECK(iadd3_info.family() == isub3_info.family()); @@ -118,11 +118,11 @@ TEST_CASE("meta/family") { } SUBCASE("method") { - meta::method_info add2_info = meta::method_("add", &ivec2::add); - meta::method_info sub2_info = meta::method_("sub", &ivec2::sub); + meta::method_info add2_info = meta::method_("add", &ivec2::add).make_info(); + meta::method_info sub2_info = meta::method_("sub", &ivec2::sub).make_info(); - meta::method_info add3_info = meta::method_("add", &ivec3::add); - meta::method_info sub3_info = meta::method_("sub", &ivec3::sub); + meta::method_info add3_info = meta::method_("add", &ivec3::add).make_info(); + meta::method_info sub3_info = meta::method_("sub", &ivec3::sub).make_info(); CHECK(add2_info.family() == sub2_info.family()); CHECK(add3_info.family() == sub3_info.family()); @@ -132,11 +132,11 @@ TEST_CASE("meta/family") { } SUBCASE("variable") { - meta::variable_info zero2_info = meta::variable_("zero", &ivec2::zero); - meta::variable_info unit2_info = meta::variable_("unit", &ivec2::unit); + meta::variable_info zero2_info = meta::variable_("zero", &ivec2::zero).make_info(); + meta::variable_info unit2_info = meta::variable_("unit", &ivec2::unit).make_info(); - meta::variable_info zero3_info = meta::variable_("zero", &ivec3::zero); - meta::variable_info unit3_info = meta::variable_("unit", &ivec3::unit); + meta::variable_info zero3_info = meta::variable_("zero", &ivec3::zero).make_info(); + meta::variable_info unit3_info = meta::variable_("unit", &ivec3::unit).make_info(); CHECK(zero2_info.family() == unit2_info.family()); CHECK(zero3_info.family() == unit3_info.family()); diff --git a/untests/meta_field_tests.cpp b/untests/meta_field_tests.cpp index 3efcd57..759276a 100644 --- a/untests/meta_field_tests.cpp +++ b/untests/meta_field_tests.cpp @@ -22,8 +22,8 @@ TEST_CASE("meta/field") { meta::field_ field_{"field", &clazz::field}; meta::field_ cfield_{"cfield", &clazz::cfield}; - const meta::field_info& field_info = field_; - const meta::field_info& cfield_info = cfield_; + const meta::field_info field_info = field_.make_info(); + const meta::field_info cfield_info = cfield_.make_info(); { CHECK(field_info.value_type() == meta::get_family_id()); diff --git a/untests/meta_function_tests.cpp b/untests/meta_function_tests.cpp index c26a3ff..f5c508a 100644 --- a/untests/meta_function_tests.cpp +++ b/untests/meta_function_tests.cpp @@ -29,13 +29,13 @@ TEST_CASE("meta/function") { meta::function_ int_f_int_function_("int_f_int", &int_f_int); meta::function_ int_f_int2_function_("int_f_int2", &int_f_int2); - const meta::function_info& void_f_void_info = void_f_void_function_; - const meta::function_info& void_f_int_info = void_f_int_function_; - const meta::function_info& void_f_int2_info = void_f_int2_function_; + const meta::function_info& void_f_void_info = void_f_void_function_.make_info(); + const meta::function_info& void_f_int_info = void_f_int_function_.make_info(); + const meta::function_info& void_f_int2_info = void_f_int2_function_.make_info(); - const meta::function_info& int_f_void_info = int_f_void_function_; - const meta::function_info& int_f_int_info = int_f_int_function_; - const meta::function_info& int_f_int2_info = int_f_int2_function_; + const meta::function_info& int_f_void_info = int_f_void_function_.make_info(); + const meta::function_info& int_f_int_info = int_f_int_function_.make_info(); + const meta::function_info& int_f_int2_info = int_f_int2_function_.make_info(); SUBCASE("arity") { CHECK(void_f_void_info.arity() == 0); diff --git a/untests/meta_method_tests.cpp b/untests/meta_method_tests.cpp index af89930..dcd0881 100644 --- a/untests/meta_method_tests.cpp +++ b/untests/meta_method_tests.cpp @@ -42,13 +42,13 @@ TEST_CASE("meta/non_const_method") { meta::method_ int_f_int_method_("int_f_int", &clazz::int_f_int); meta::method_ int_f_int2_method_("int_f_int2", &clazz::int_f_int2); - const meta::method_info& void_f_void_info = void_f_void_method_; - const meta::method_info& void_f_int_info = void_f_int_method_; - const meta::method_info& void_f_int2_info = void_f_int2_method_; + const meta::method_info& void_f_void_info = void_f_void_method_.make_info(); + const meta::method_info& void_f_int_info = void_f_int_method_.make_info(); + const meta::method_info& void_f_int2_info = void_f_int2_method_.make_info(); - const meta::method_info& int_f_void_info = int_f_void_method_; - const meta::method_info& int_f_int_info = int_f_int_method_; - const meta::method_info& int_f_int2_info = int_f_int2_method_; + const meta::method_info& int_f_void_info = int_f_void_method_.make_info(); + const meta::method_info& int_f_int_info = int_f_int_method_.make_info(); + const meta::method_info& int_f_int2_info = int_f_int2_method_.make_info(); SUBCASE("arity") { CHECK(void_f_void_info.arity() == 0); @@ -155,13 +155,13 @@ TEST_CASE("meta/const_method") { meta::method_ int_f_int_method_("int_f_int", &clazz::const_int_f_int); meta::method_ int_f_int2_method_("int_f_int2", &clazz::const_int_f_int2); - const meta::method_info& void_f_void_info = void_f_void_method_; - const meta::method_info& void_f_int_info = void_f_int_method_; - const meta::method_info& void_f_int2_info = void_f_int2_method_; + const meta::method_info& void_f_void_info = void_f_void_method_.make_info(); + const meta::method_info& void_f_int_info = void_f_int_method_.make_info(); + const meta::method_info& void_f_int2_info = void_f_int2_method_.make_info(); - const meta::method_info& int_f_void_info = int_f_void_method_; - const meta::method_info& int_f_int_info = int_f_int_method_; - const meta::method_info& int_f_int2_info = int_f_int2_method_; + const meta::method_info& int_f_void_info = int_f_void_method_.make_info(); + const meta::method_info& int_f_int_info = int_f_int_method_.make_info(); + const meta::method_info& int_f_int2_info = int_f_int2_method_.make_info(); SUBCASE("instance_type") { CHECK(void_f_void_info.instance_type() == meta::get_family_id()); diff --git a/untests/meta_namespace_tests.cpp b/untests/meta_namespace_tests.cpp index 24c8346..4cef931 100644 --- a/untests/meta_namespace_tests.cpp +++ b/untests/meta_namespace_tests.cpp @@ -24,13 +24,16 @@ TEST_CASE("meta/namespace") { meta::namespace_ namespace_{"ns"}; const meta::namespace_& cnamespace_ = namespace_; - const meta::namespace_info& ns_info = cnamespace_; - CHECK_FALSE(ns_info.get_class("clazz")); - CHECK_FALSE(ns_info.get_function("func")); - CHECK_FALSE(ns_info.get_namespace("ns")); - CHECK_FALSE(ns_info.get_variable("variable")); - CHECK_FALSE(ns_info.get_variable("cvariable")); + { + const meta::namespace_info& ns_info = cnamespace_.make_info(); + + CHECK_FALSE(ns_info.get_class("clazz")); + CHECK_FALSE(ns_info.get_function("func")); + CHECK_FALSE(ns_info.get_namespace("ns")); + CHECK_FALSE(ns_info.get_variable("variable")); + CHECK_FALSE(ns_info.get_variable("cvariable")); + } namespace_( meta::class_("clazz"), @@ -39,35 +42,39 @@ TEST_CASE("meta/namespace") { meta::variable_("variable", &variable), meta::variable_("cvariable", &cvariable)); - CHECK(ns_info.get_class("clazz")); - CHECK(ns_info.get_function("func")); - CHECK(ns_info.get_namespace("ns2")); - CHECK(ns_info.get_variable("variable")); - CHECK(ns_info.get_variable("cvariable")); - { - meta::class_info clazz_info = ns_info.get_class("clazz").value(); - CHECK(clazz_info.id() == "clazz"); - } + const meta::namespace_info& ns_info = cnamespace_.make_info(); - { - meta::function_info clazz_info = ns_info.get_function("func").value(); - CHECK(clazz_info.id() == "func"); - } + CHECK(ns_info.get_class("clazz")); + CHECK(ns_info.get_function("func")); + CHECK(ns_info.get_namespace("ns2")); + CHECK(ns_info.get_variable("variable")); + CHECK(ns_info.get_variable("cvariable")); - { - meta::namespace_info namespace_info = ns_info.get_namespace("ns2").value(); - CHECK(namespace_info.id() == "ns2"); - } + { + meta::class_info clazz_info = ns_info.get_class("clazz").value(); + CHECK(clazz_info.id() == "clazz"); + } - { - meta::variable_info variable_info = ns_info.get_variable("variable").value(); - CHECK(variable_info.id() == "variable"); - } + { + meta::function_info clazz_info = ns_info.get_function("func").value(); + CHECK(clazz_info.id() == "func"); + } - { - meta::variable_info cvariable_info = ns_info.get_variable("cvariable").value(); - CHECK(cvariable_info.id() == "cvariable"); + { + meta::namespace_info namespace_info = ns_info.get_namespace("ns2").value(); + CHECK(namespace_info.id() == "ns2"); + } + + { + meta::variable_info variable_info = ns_info.get_variable("variable").value(); + CHECK(variable_info.id() == "variable"); + } + + { + meta::variable_info cvariable_info = ns_info.get_variable("cvariable").value(); + CHECK(cvariable_info.id() == "cvariable"); + } } } @@ -75,7 +82,6 @@ TEST_CASE("meta/namespace/merge") { namespace meta = meta_hpp; meta::namespace_ namespace_{"ns"}; - const meta::namespace_info& ns_info = namespace_; namespace_( meta::namespace_{"ns2"}( @@ -97,6 +103,7 @@ TEST_CASE("meta/namespace/merge") { ) ); + const meta::namespace_info ns_info = namespace_.make_info(); const meta::namespace_info ns2_info = ns_info.get_namespace("ns2").value(); const meta::namespace_info ns3_info = ns2_info.get_namespace("ns3").value(); diff --git a/untests/meta_registry_tests.cpp b/untests/meta_registry_tests.cpp index a4990e5..8112fce 100644 --- a/untests/meta_registry_tests.cpp +++ b/untests/meta_registry_tests.cpp @@ -103,8 +103,8 @@ TEST_CASE("meta/registry") { REQUIRE(registry.resolve(std::as_const(v3))); REQUIRE(registry.resolve(static_cast(v3))); - const meta::class_info v2_info = meta::class_("ivec2"); - const meta::class_info v3_info = meta::class_("ivec3"); + const meta::class_info v2_info = meta::class_("ivec2").make_info(); + const meta::class_info v3_info = meta::class_("ivec3").make_info(); CHECK(v2_info.family() != v3_info.family()); CHECK(v2_info.family() == registry.resolve()->family()); diff --git a/untests/meta_type_tests.cpp b/untests/meta_type_tests.cpp index d90d4df..13953f5 100644 --- a/untests/meta_type_tests.cpp +++ b/untests/meta_type_tests.cpp @@ -31,27 +31,27 @@ TEST_CASE("meta/type") { namespace meta = meta_hpp; using namespace std::string_literals; - meta::type class_type = meta::class_("clazz"); + meta::type class_type = meta::class_("clazz").make_info(); CHECK(class_type.is_class()); CHECK(class_type.get_class()->id() == "clazz"); - meta::type field_type = meta::field_("field", &clazz::field); + meta::type field_type = meta::field_("field", &clazz::field).make_info(); CHECK(field_type.is_field()); CHECK(field_type.get_field()->id() == "field"); - meta::type function_type = meta::function_("function", &clazz::function); + meta::type function_type = meta::function_("function", &clazz::function).make_info(); CHECK(function_type.is_function()); CHECK(function_type.get_function()->id() == "function"); - meta::type method_type = meta::method_("method", &clazz::method); + meta::type method_type = meta::method_("method", &clazz::method).make_info(); CHECK(method_type.is_method()); CHECK(method_type.get_method()->id() == "method"); - meta::type namespace_type = meta::namespace_("ns"); + meta::type namespace_type = meta::namespace_("ns").make_info(); CHECK(namespace_type.is_namespace()); CHECK(namespace_type.get_namespace()->id() == "ns"); - meta::type variable_type = meta::variable_("variable", &clazz::variable); + meta::type variable_type = meta::variable_("variable", &clazz::variable).make_info(); CHECK(variable_type.is_variable()); CHECK(variable_type.get_variable()->id() == "variable"); } @@ -63,11 +63,11 @@ TEST_CASE("meta/type/merge") { { meta::type clazz_type = meta::class_("clazz")( meta::field_("field", &clazz::field) - ); + ).make_info(); clazz_type.merge(meta::class_("clazz")( meta::function_("function", &clazz::function) - )); + ).make_info()); REQUIRE(clazz_type.is_class()); CHECK(clazz_type.get_class()->get_field("field")); diff --git a/untests/meta_variable_tests.cpp b/untests/meta_variable_tests.cpp index 1ddf254..69318bc 100644 --- a/untests/meta_variable_tests.cpp +++ b/untests/meta_variable_tests.cpp @@ -29,8 +29,8 @@ TEST_CASE("meta/variable") { meta::variable_ variable_{"variable", &variable}; meta::variable_ cvariable_{"cvariable", &cvariable}; - const meta::variable_info& variable_info = variable_; - const meta::variable_info& cvariable_info = cvariable_; + const meta::variable_info& variable_info = variable_.make_info(); + const meta::variable_info& cvariable_info = cvariable_.make_info(); { CHECK(variable_info.value_type() == meta::get_family_id()); @@ -68,8 +68,8 @@ TEST_CASE("meta/variable") { meta::variable_ variable_{"variable", &clazz::variable}; meta::variable_ cvariable_{"cvariable", &clazz::cvariable}; - const meta::variable_info& variable_info = variable_; - const meta::variable_info& cvariable_info = cvariable_; + const meta::variable_info& variable_info = variable_.make_info(); + const meta::variable_info& cvariable_info = cvariable_.make_info(); { CHECK(variable_info.value_type() == meta::get_family_id());