diff --git a/TODO.md b/TODO.md index 75a811d..e792242 100644 --- a/TODO.md +++ b/TODO.md @@ -13,3 +13,5 @@ - (?) move-only value type support - (?) type names - (?) properties + +(???) Why does local scope have a name? diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 1ccebba..0ad21b2 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -39,10 +39,6 @@ namespace meta_hpp::detail namespace meta_hpp { - struct type_opts final { - metadata_map metadata{}; - }; - struct argument_opts final { std::string name{}; metadata_map metadata{}; @@ -75,10 +71,6 @@ namespace meta_hpp metadata_map metadata{}; }; - struct scope_opts final { - metadata_map metadata{}; - }; - struct variable_opts final { metadata_map metadata{}; }; @@ -89,7 +81,7 @@ namespace meta_hpp template < detail::array_kind Array > class array_bind final { public: - explicit array_bind(type_opts opts); + explicit array_bind(metadata_map metadata); operator array_type() const noexcept; private: detail::array_type_data_ptr data_; @@ -101,7 +93,7 @@ namespace meta_hpp template < detail::class_kind Class > class class_bind final { public: - explicit class_bind(type_opts opts); + explicit class_bind(metadata_map metadata); operator class_type() const noexcept; // constructor_ @@ -228,7 +220,7 @@ namespace meta_hpp template < detail::enum_kind Enum > class enum_bind final { public: - explicit enum_bind(type_opts opts); + explicit enum_bind(metadata_map metadata); operator enum_type() const noexcept; enum_bind& evalue_(std::string name, Enum value); @@ -243,7 +235,7 @@ namespace meta_hpp template < detail::function_kind Function > class function_bind final { public: - explicit function_bind(type_opts opts); + explicit function_bind(metadata_map metadata); operator function_type() const noexcept; private: detail::function_type_data_ptr data_; @@ -255,7 +247,7 @@ namespace meta_hpp template < detail::member_kind Member > class member_bind final { public: - explicit member_bind(type_opts opts); + explicit member_bind(metadata_map metadata); operator member_type() const noexcept; private: detail::member_type_data_ptr data_; @@ -267,7 +259,7 @@ namespace meta_hpp template < detail::method_kind Method > class method_bind final { public: - explicit method_bind(type_opts opts); + explicit method_bind(metadata_map metadata); operator method_type() const noexcept; private: detail::method_type_data_ptr data_; @@ -279,7 +271,7 @@ namespace meta_hpp template < detail::nullptr_kind Nullptr > class nullptr_bind final { public: - explicit nullptr_bind(type_opts opts); + explicit nullptr_bind(metadata_map metadata); operator nullptr_type() const noexcept; private: detail::nullptr_type_data_ptr data_; @@ -291,7 +283,7 @@ namespace meta_hpp template < detail::number_kind Number > class number_bind final { public: - explicit number_bind(type_opts opts); + explicit number_bind(metadata_map metadata); operator number_type() const noexcept; private: detail::number_type_data_ptr data_; @@ -303,7 +295,7 @@ namespace meta_hpp template < detail::pointer_kind Pointer > class pointer_bind final { public: - explicit pointer_bind(type_opts opts); + explicit pointer_bind(metadata_map metadata); operator pointer_type() const noexcept; private: detail::pointer_type_data_ptr data_; @@ -315,7 +307,7 @@ namespace meta_hpp template < detail::reference_kind Reference > class reference_bind final { public: - explicit reference_bind(type_opts opts); + explicit reference_bind(metadata_map metadata); operator reference_type() const noexcept; private: detail::reference_type_data_ptr data_; @@ -327,7 +319,7 @@ namespace meta_hpp template < detail::void_kind Void > class void_bind final { public: - explicit void_bind(type_opts opts); + explicit void_bind(metadata_map metadata); operator void_type() const noexcept; private: detail::void_type_data_ptr data_; @@ -341,8 +333,8 @@ namespace meta_hpp struct local_tag {}; struct static_tag {}; - explicit scope_bind(std::string name, scope_opts opts, local_tag); - explicit scope_bind(std::string_view name, scope_opts opts, static_tag); + explicit scope_bind(std::string name, metadata_map metadata, local_tag); + explicit scope_bind(std::string_view name, metadata_map metadata, static_tag); operator scope() const noexcept; template < detail::class_kind Class > @@ -400,68 +392,68 @@ namespace meta_hpp namespace meta_hpp { template < detail::array_kind Array > - array_bind array_(type_opts opts = {}) { - return array_bind{std::move(opts)}; + array_bind array_(metadata_map metadata = {}) { + return array_bind{std::move(metadata)}; } template < detail::class_kind Class > - class_bind class_(type_opts opts = {}) { - return class_bind{std::move(opts)}; + class_bind class_(metadata_map metadata = {}) { + return class_bind{std::move(metadata)}; } template < detail::enum_kind Enum > - enum_bind enum_(type_opts opts = {}) { - return enum_bind{std::move(opts)}; + enum_bind enum_(metadata_map metadata = {}) { + return enum_bind{std::move(metadata)}; } template < detail::function_kind Function > - function_bind function_(type_opts opts = {}) { - return function_bind{std::move(opts)}; + function_bind function_(metadata_map metadata = {}) { + return function_bind{std::move(metadata)}; } template < detail::member_kind Member > - member_bind member_(type_opts opts = {}) { - return member_bind{std::move(opts)}; + member_bind member_(metadata_map metadata = {}) { + return member_bind{std::move(metadata)}; } template < detail::method_kind Method > - method_bind method_(type_opts opts = {}) { - return method_bind{std::move(opts)}; + method_bind method_(metadata_map metadata = {}) { + return method_bind{std::move(metadata)}; } template < detail::nullptr_kind Nullptr > - nullptr_bind nullptr_(type_opts opts = {}) { - return nullptr_bind{std::move(opts)}; + nullptr_bind nullptr_(metadata_map metadata = {}) { + return nullptr_bind{std::move(metadata)}; } template < detail::number_kind Number > - number_bind number_(type_opts opts = {}) { - return number_bind{std::move(opts)}; + number_bind number_(metadata_map metadata = {}) { + return number_bind{std::move(metadata)}; } template < detail::pointer_kind Pointer > - pointer_bind pointer_(type_opts opts = {}) { - return pointer_bind{std::move(opts)}; + pointer_bind pointer_(metadata_map metadata = {}) { + return pointer_bind{std::move(metadata)}; } template < detail::reference_kind Reference > - reference_bind reference_(type_opts opts = {}) { - return reference_bind{std::move(opts)}; + reference_bind reference_(metadata_map metadata = {}) { + return reference_bind{std::move(metadata)}; } template < detail::void_kind Void > - void_bind void_(type_opts opts = {}) { - return void_bind{std::move(opts)}; + void_bind void_(metadata_map metadata = {}) { + return void_bind{std::move(metadata)}; } } namespace meta_hpp { - inline scope_bind local_scope_(std::string name, scope_opts opts = {}) { - return scope_bind{std::move(name), std::move(opts), scope_bind::local_tag()}; + inline scope_bind local_scope_(std::string name, metadata_map metadata = {}) { + return scope_bind{std::move(name), std::move(metadata), scope_bind::local_tag()}; } - inline scope_bind static_scope_(std::string_view name, scope_opts opts = {}) { - return scope_bind{name, std::move(opts), scope_bind::static_tag()}; + inline scope_bind static_scope_(std::string_view name, metadata_map metadata = {}) { + return scope_bind{name, std::move(metadata), scope_bind::static_tag()}; } } diff --git a/headers/meta.hpp/meta_binds/array_bind.hpp b/headers/meta.hpp/meta_binds/array_bind.hpp index d7277e9..1985278 100644 --- a/headers/meta.hpp/meta_binds/array_bind.hpp +++ b/headers/meta.hpp/meta_binds/array_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::array_kind Array > - array_bind::array_bind(type_opts opts) + array_bind::array_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::array_kind Array > diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index 9038360..6a7b37a 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::class_kind Class > - class_bind::class_bind(type_opts opts) + class_bind::class_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::class_kind Class > diff --git a/headers/meta.hpp/meta_binds/enum_bind.hpp b/headers/meta.hpp/meta_binds/enum_bind.hpp index 5c19926..d44512b 100644 --- a/headers/meta.hpp/meta_binds/enum_bind.hpp +++ b/headers/meta.hpp/meta_binds/enum_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::enum_kind Enum > - enum_bind::enum_bind(type_opts opts) + enum_bind::enum_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::enum_kind Enum > diff --git a/headers/meta.hpp/meta_binds/function_bind.hpp b/headers/meta.hpp/meta_binds/function_bind.hpp index 45424f1..0c1634e 100644 --- a/headers/meta.hpp/meta_binds/function_bind.hpp +++ b/headers/meta.hpp/meta_binds/function_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::function_kind Function > - function_bind::function_bind(type_opts opts) + function_bind::function_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::function_kind Function > diff --git a/headers/meta.hpp/meta_binds/member_bind.hpp b/headers/meta.hpp/meta_binds/member_bind.hpp index c1636ec..4bd30d5 100644 --- a/headers/meta.hpp/meta_binds/member_bind.hpp +++ b/headers/meta.hpp/meta_binds/member_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::member_kind Member > - member_bind::member_bind(type_opts opts) + member_bind::member_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::member_kind Member > diff --git a/headers/meta.hpp/meta_binds/method_bind.hpp b/headers/meta.hpp/meta_binds/method_bind.hpp index b860973..05651d1 100644 --- a/headers/meta.hpp/meta_binds/method_bind.hpp +++ b/headers/meta.hpp/meta_binds/method_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::method_kind Method > - method_bind::method_bind(type_opts opts) + method_bind::method_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::method_kind Method > diff --git a/headers/meta.hpp/meta_binds/nullptr_bind.hpp b/headers/meta.hpp/meta_binds/nullptr_bind.hpp index daa79e9..4b53d3e 100644 --- a/headers/meta.hpp/meta_binds/nullptr_bind.hpp +++ b/headers/meta.hpp/meta_binds/nullptr_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::nullptr_kind Nullptr > - nullptr_bind::nullptr_bind(type_opts opts) + nullptr_bind::nullptr_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::nullptr_kind Nullptr > diff --git a/headers/meta.hpp/meta_binds/number_bind.hpp b/headers/meta.hpp/meta_binds/number_bind.hpp index 3a0c83f..fff3f19 100644 --- a/headers/meta.hpp/meta_binds/number_bind.hpp +++ b/headers/meta.hpp/meta_binds/number_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::number_kind Number > - number_bind::number_bind(type_opts opts) + number_bind::number_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::number_kind Number > diff --git a/headers/meta.hpp/meta_binds/pointer_bind.hpp b/headers/meta.hpp/meta_binds/pointer_bind.hpp index bef44f3..1be0b01 100644 --- a/headers/meta.hpp/meta_binds/pointer_bind.hpp +++ b/headers/meta.hpp/meta_binds/pointer_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::pointer_kind Pointer > - pointer_bind::pointer_bind(type_opts opts) + pointer_bind::pointer_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::pointer_kind Pointer > diff --git a/headers/meta.hpp/meta_binds/reference_bind.hpp b/headers/meta.hpp/meta_binds/reference_bind.hpp index 9511984..1ed1235 100644 --- a/headers/meta.hpp/meta_binds/reference_bind.hpp +++ b/headers/meta.hpp/meta_binds/reference_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::reference_kind Reference > - reference_bind::reference_bind(type_opts opts) + reference_bind::reference_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::reference_kind Reference > diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index 5ed613d..4f25d51 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -15,14 +15,14 @@ namespace meta_hpp { // NOLINTNEXTLINE(readability-named-parameter) - inline scope_bind::scope_bind(std::string name, scope_opts opts, local_tag) - : state_{detail::scope_state::make(std::move(name), std::move(opts.metadata))} {} + inline scope_bind::scope_bind(std::string name, metadata_map metadata, local_tag) + : state_{detail::scope_state::make(std::move(name), std::move(metadata))} {} // NOLINTNEXTLINE(readability-named-parameter) - inline scope_bind::scope_bind(std::string_view name, scope_opts opts, static_tag) + inline scope_bind::scope_bind(std::string_view name, metadata_map metadata, static_tag) : state_{detail::state_access(detail::resolve_scope(name))} { - state_->metadata.swap(opts.metadata); - state_->metadata.merge(opts.metadata); + state_->metadata.swap(metadata); + state_->metadata.merge(metadata); } inline scope_bind::operator scope() const noexcept { diff --git a/headers/meta.hpp/meta_binds/void_bind.hpp b/headers/meta.hpp/meta_binds/void_bind.hpp index 17c7497..62fddb4 100644 --- a/headers/meta.hpp/meta_binds/void_bind.hpp +++ b/headers/meta.hpp/meta_binds/void_bind.hpp @@ -14,10 +14,10 @@ namespace meta_hpp { template < detail::void_kind Void > - void_bind::void_bind(type_opts opts) + void_bind::void_bind(metadata_map metadata) : data_{detail::type_access(detail::resolve_type())} { - data_->metadata.swap(opts.metadata); - data_->metadata.merge(opts.metadata); + data_->metadata.swap(metadata); + data_->metadata.merge(metadata); } template < detail::void_kind Void > diff --git a/untests/meta_states/metadata_tests.cpp b/untests/meta_states/metadata_tests.cpp index 04e59eb..34c55d8 100644 --- a/untests/meta_states/metadata_tests.cpp +++ b/untests/meta_states/metadata_tests.cpp @@ -38,10 +38,8 @@ TEST_CASE("meta/meta_states/metadata/enum") { using namespace std::string_literals; meta::enum_({ - .metadata{ - {"desc1", meta::uvalue{"enum-desc1"s}}, - {"desc2", meta::uvalue{"enum-desc2"s}}, - } + {"desc1", meta::uvalue{"enum-desc1"s}}, + {"desc2", meta::uvalue{"enum-desc2"s}}, }) .evalue_("red", color::red, { .metadata{{"desc1", meta::uvalue{"red-color"s}}} @@ -56,10 +54,8 @@ TEST_CASE("meta/meta_states/metadata/enum") { // metadata override meta::enum_({ - .metadata{ - {"desc2", meta::uvalue{"new-enum-desc2"s}}, - {"desc3", meta::uvalue{"new-enum-desc3"s}}, - } + {"desc2", meta::uvalue{"new-enum-desc2"s}}, + {"desc3", meta::uvalue{"new-enum-desc3"s}}, }); meta::enum_() @@ -93,10 +89,8 @@ TEST_CASE("meta/meta_states/metadata/class") { using namespace std::string_literals; meta::class_({ - .metadata{ - {"desc1", meta::uvalue{"class-desc1"s}}, - {"desc2", meta::uvalue{"class-desc2"s}}, - }, + {"desc1", meta::uvalue{"class-desc1"s}}, + {"desc2", meta::uvalue{"class-desc2"s}}, }) .constructor_({ .arguments{{ @@ -142,10 +136,8 @@ TEST_CASE("meta/meta_states/metadata/class") { // metadata override meta::class_({ - .metadata{ - {"desc2", meta::uvalue{"new-class-desc2"s}}, - {"desc3", meta::uvalue{"new-class-desc3"s}}, - } + {"desc2", meta::uvalue{"new-class-desc2"s}}, + {"desc3", meta::uvalue{"new-class-desc3"s}}, }); // @@ -245,87 +237,88 @@ TEST_CASE("meta/meta_states/metadata/class") { } } +TEST_CASE("meta/meta_states/metadata/scope") { + namespace meta = meta_hpp; + using namespace std::string_literals; + + SUBCASE("local_scope") { + const meta::scope lscope = meta::local_scope_("local-scope", { + {"desc", meta::uvalue{"scope-desc"s}} + }); + CHECK(lscope.get_metadata().at("desc") == "scope-desc"s); + } + + SUBCASE("static_scope") { + meta::static_scope_("meta/meta_states/metadata/scope/static-scope", { + {"desc", meta::uvalue{"scope-desc"s}} + }); + CHECK(meta::resolve_scope("meta/meta_states/metadata/scope/static-scope").get_metadata().at("desc") == "scope-desc"s); + } +} + TEST_CASE("meta/meta_states/metadata/other") { namespace meta = meta_hpp; using namespace std::string_literals; SUBCASE("array") { meta::array_({ - .metadata{ - {"desc", meta::uvalue{"int[]-type"s}} - } + {"desc", meta::uvalue{"int[]-type"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "int[]-type"s); } SUBCASE("function") { meta::function_({ - .metadata{ - {"desc", meta::uvalue{"int->int"s}} - } + {"desc", meta::uvalue{"int->int"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "int->int"s); } SUBCASE("member") { meta::member_({ - .metadata{ - {"desc", meta::uvalue{"ivec2::int"s}} - } + {"desc", meta::uvalue{"ivec2::int"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "ivec2::int"s); } SUBCASE("method") { meta::method_({ - .metadata{ - {"desc", meta::uvalue{"ivec2(int -> int)"s}} - } + {"desc", meta::uvalue{"ivec2(int -> int)"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "ivec2(int -> int)"s); } SUBCASE("nullptr") { meta::nullptr_({ - .metadata{ - {"desc", meta::uvalue{"nullptr_t"s}} - } + {"desc", meta::uvalue{"nullptr_t"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "nullptr_t"s); } SUBCASE("number") { meta::number_({ - .metadata{ - {"desc", meta::uvalue{"int-type"s}} - } + {"desc", meta::uvalue{"int-type"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "int-type"s); } SUBCASE("pointer") { meta::pointer_({ - .metadata{ - {"desc", meta::uvalue{"int*-type"s}} - } + {"desc", meta::uvalue{"int*-type"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "int*-type"s); } SUBCASE("reference") { meta::reference_({ - .metadata{ - {"desc", meta::uvalue{"int&-type"s}} - } + {"desc", meta::uvalue{"int&-type"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "int&-type"s); } SUBCASE("void") { meta::void_({ - .metadata{ - {"desc", meta::uvalue{"void-type"s}} - } + {"desc", meta::uvalue{"void-type"s}} }); CHECK(meta::resolve_type().get_metadata().at("desc") == "void-type"s); }