From c9a6f2d0716c492cde3e357f73f720f8f4b5fe52 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 12 Feb 2022 05:06:18 +0700 Subject: [PATCH] metadata for every state --- headers/meta.hpp/meta_states.hpp | 97 ++++++++++++++------ headers/meta.hpp/meta_states/argument.hpp | 14 ++- headers/meta.hpp/meta_states/constructor.hpp | 16 +++- headers/meta.hpp/meta_states/destructor.hpp | 14 ++- headers/meta.hpp/meta_states/evalue.hpp | 14 ++- headers/meta.hpp/meta_states/function.hpp | 16 +++- headers/meta.hpp/meta_states/member.hpp | 14 ++- headers/meta.hpp/meta_states/method.hpp | 16 +++- headers/meta.hpp/meta_states/scope.hpp | 14 ++- headers/meta.hpp/meta_states/variable.hpp | 14 ++- 10 files changed, 182 insertions(+), 47 deletions(-) diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index d007ed5..a19196b 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -101,14 +101,18 @@ namespace meta_hpp class argument final { public: explicit argument() = default; - explicit argument(detail::argument_state_ptr state); + explicit argument(detail::argument_state_ptr state) noexcept; + argument& operator=(detail::argument_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const argument_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const any_type& get_type() const noexcept; [[nodiscard]] std::size_t get_position() const noexcept; + [[nodiscard]] const std::string& get_name() const noexcept; private: detail::argument_state_ptr state_; @@ -118,12 +122,15 @@ namespace meta_hpp class constructor final { public: explicit constructor() = default; - explicit constructor(detail::constructor_state_ptr state); + explicit constructor(detail::constructor_state_ptr state) noexcept; + constructor& operator=(detail::constructor_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const constructor_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const constructor_type& get_type() const noexcept; template < typename... Args > @@ -148,12 +155,15 @@ namespace meta_hpp class destructor final { public: explicit destructor() = default; - explicit destructor(detail::destructor_state_ptr state); + explicit destructor(detail::destructor_state_ptr state) noexcept; + destructor& operator=(detail::destructor_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const destructor_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const destructor_type& get_type() const noexcept; template < typename Arg > @@ -175,12 +185,15 @@ namespace meta_hpp class evalue final { public: explicit evalue() = default; - explicit evalue(detail::evalue_state_ptr state); + explicit evalue(detail::evalue_state_ptr state) noexcept; + evalue& operator=(detail::evalue_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const evalue_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const enum_type& get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; @@ -194,12 +207,15 @@ namespace meta_hpp class function final { public: explicit function() = default; - explicit function(detail::function_state_ptr state); + explicit function(detail::function_state_ptr state) noexcept; + function& operator=(detail::function_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const function_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const function_type& get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; @@ -225,12 +241,15 @@ namespace meta_hpp class member final { public: explicit member() = default; - explicit member(detail::member_state_ptr state); + explicit member(detail::member_state_ptr state) noexcept; + member& operator=(detail::member_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const member_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const member_type& get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; @@ -265,12 +284,15 @@ namespace meta_hpp class method final { public: explicit method() = default; - explicit method(detail::method_state_ptr state); + explicit method(detail::method_state_ptr state) noexcept; + method& operator=(detail::method_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const method_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const method_type& get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; @@ -296,12 +318,15 @@ namespace meta_hpp class scope final { public: explicit scope() = default; - explicit scope(detail::scope_state_ptr state); + explicit scope(detail::scope_state_ptr state) noexcept; + scope& operator=(detail::scope_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const scope_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const std::string& get_name() const noexcept; [[nodiscard]] const class_map& get_classes() const noexcept; @@ -328,12 +353,15 @@ namespace meta_hpp class variable final { public: explicit variable() = default; - explicit variable(detail::variable_state_ptr state); + explicit variable(detail::variable_state_ptr state) noexcept; + variable& operator=(detail::variable_state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; [[nodiscard]] const variable_index& get_index() const noexcept; + [[nodiscard]] const metadata_map& get_metadata() const noexcept; + [[nodiscard]] const pointer_type& get_type() const noexcept; [[nodiscard]] const std::string& get_name() const noexcept; @@ -394,18 +422,30 @@ namespace meta_hpp namespace meta_hpp::detail { + struct argument_state final { + argument_index index; + metadata_map metadata; + + std::string name{}; + + template < typename Argument > + [[nodiscard]] static argument_state_ptr make(std::size_t position, metadata_map metadata); + }; + struct constructor_state final { using invoke_impl = fixed_function)>; using is_invocable_with_impl = fixed_function)>; constructor_index index; + metadata_map metadata; + invoke_impl invoke; is_invocable_with_impl is_invocable_with; argument_list arguments; template < constructor_policy_kind Policy, class_kind Class, typename... Args > - [[nodiscard]] static constructor_state_ptr make(); + [[nodiscard]] static constructor_state_ptr make(metadata_map metadata); }; struct destructor_state final { @@ -413,20 +453,24 @@ namespace meta_hpp::detail using is_invocable_with_impl = fixed_function; destructor_index index; + metadata_map metadata; + invoke_impl invoke; is_invocable_with_impl is_invocable_with; template < class_kind Class > - [[nodiscard]] static destructor_state_ptr make(); + [[nodiscard]] static destructor_state_ptr make(metadata_map metadata); }; struct evalue_state final { evalue_index index; + metadata_map metadata; + uvalue enum_value; uvalue underlying_value; template < enum_kind Enum > - [[nodiscard]] static evalue_state_ptr make(std::string name, Enum evalue); + [[nodiscard]] static evalue_state_ptr make(std::string name, Enum evalue, metadata_map metadata); }; struct function_state final { @@ -434,13 +478,15 @@ namespace meta_hpp::detail using is_invocable_with_impl = fixed_function)>; function_index index; + metadata_map metadata; + invoke_impl invoke; is_invocable_with_impl is_invocable_with; argument_list arguments; template < function_policy_kind Policy, function_kind Function > - [[nodiscard]] static function_state_ptr make(std::string name, Function function); + [[nodiscard]] static function_state_ptr make(std::string name, Function function, metadata_map metadata); }; struct member_state final { @@ -451,13 +497,16 @@ namespace meta_hpp::detail using is_settable_with_impl = fixed_function; member_index index; + metadata_map metadata; + getter_impl getter; setter_impl setter; is_gettable_with_impl is_gettable_with; is_settable_with_impl is_settable_with; + template < member_policy_kind Policy, member_kind Member > - [[nodiscard]] static member_state_ptr make(std::string name, Member member); + [[nodiscard]] static member_state_ptr make(std::string name, Member member, metadata_map metadata); }; struct method_state final { @@ -465,33 +514,27 @@ namespace meta_hpp::detail using is_invocable_with_impl = fixed_function)>; method_index index; + metadata_map metadata; + invoke_impl invoke; is_invocable_with_impl is_invocable_with; argument_list arguments; template < method_policy_kind Policy, method_kind Method > - [[nodiscard]] static method_state_ptr make(std::string name, Method method); - }; - - struct argument_state final { - argument_index index; - - std::string name{}; - - template < typename Argument > - [[nodiscard]] static argument_state_ptr make(std::size_t position); + [[nodiscard]] static method_state_ptr make(std::string name, Method method, metadata_map metadata); }; struct scope_state final { scope_index index; + metadata_map metadata; class_map classes{}; enum_map enums{}; function_map functions{}; variable_map variables{}; - [[nodiscard]] static scope_state_ptr make(std::string name); + [[nodiscard]] static scope_state_ptr make(std::string name, metadata_map metadata); }; struct variable_state final { @@ -500,11 +543,13 @@ namespace meta_hpp::detail using is_settable_with_impl = fixed_function; variable_index index; + metadata_map metadata; + getter_impl getter; setter_impl setter; is_settable_with_impl is_settable_with; template < variable_policy_kind Policy, pointer_kind Pointer > - [[nodiscard]] static variable_state_ptr make(std::string name, Pointer pointer); + [[nodiscard]] static variable_state_ptr make(std::string name, Pointer pointer, metadata_map metadata); }; } diff --git a/headers/meta.hpp/meta_states/argument.hpp b/headers/meta.hpp/meta_states/argument.hpp index 6637394..371fd5b 100644 --- a/headers/meta.hpp/meta_states/argument.hpp +++ b/headers/meta.hpp/meta_states/argument.hpp @@ -12,9 +12,10 @@ namespace meta_hpp::detail { template < typename Argument > - inline argument_state_ptr argument_state::make(std::size_t position) { + inline argument_state_ptr argument_state::make(std::size_t position, metadata_map metadata) { return std::make_shared(argument_state{ .index{argument_index::make(position)}, + .metadata{std::move(metadata)}, }); } } @@ -22,9 +23,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline argument::argument(detail::argument_state_ptr state) + inline argument::argument(detail::argument_state_ptr state) noexcept : state_{std::move(state)} {} + inline argument& argument::operator=(detail::argument_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool argument::is_valid() const noexcept { return !!state_; } @@ -37,6 +43,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& argument::get_metadata() const noexcept { + return state_->metadata; + } + inline const any_type& argument::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index ec6ddc7..927ec5a 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -100,7 +100,7 @@ namespace meta_hpp::detail [&arguments](std::index_sequence) mutable { (arguments.push_back([](){ using P = detail::type_list_at_t; - return argument{detail::argument_state::make

(I)}; + return argument{detail::argument_state::make

(I, metadata_map{})}; }.template operator()()), ...); }(std::make_index_sequence()); @@ -111,9 +111,10 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < constructor_policy_kind Policy, class_kind Class, typename... Args > - constructor_state_ptr constructor_state::make() { + constructor_state_ptr constructor_state::make(metadata_map metadata) { return std::make_shared(constructor_state{ .index{constructor_index::make()}, + .metadata{std::move(metadata)}, .invoke{make_constructor_invoke()}, .is_invocable_with{make_constructor_is_invocable_with()}, .arguments{make_constructor_arguments()}, @@ -123,9 +124,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline constructor::constructor(detail::constructor_state_ptr state) + inline constructor::constructor(detail::constructor_state_ptr state) noexcept : state_{std::move(state)} {} + inline constructor& constructor::operator=(detail::constructor_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool constructor::is_valid() const noexcept { return !!state_; } @@ -138,6 +144,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& constructor::get_metadata() const noexcept { + return state_->metadata; + } + inline const constructor_type& constructor::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/destructor.hpp b/headers/meta.hpp/meta_states/destructor.hpp index 9df877e..3f7df85 100644 --- a/headers/meta.hpp/meta_states/destructor.hpp +++ b/headers/meta.hpp/meta_states/destructor.hpp @@ -54,9 +54,10 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < class_kind Class > - destructor_state_ptr destructor_state::make() { + destructor_state_ptr destructor_state::make(metadata_map metadata) { return std::make_shared(destructor_state{ .index{destructor_index::make()}, + .metadata{std::move(metadata)}, .invoke{make_destructor_invoke()}, .is_invocable_with{make_destructor_is_invocable_with()}, }); @@ -65,9 +66,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline destructor::destructor(detail::destructor_state_ptr state) + inline destructor::destructor(detail::destructor_state_ptr state) noexcept : state_{std::move(state)} {} + inline destructor& destructor::operator=(detail::destructor_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool destructor::is_valid() const noexcept { return !!state_; } @@ -80,6 +86,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& destructor::get_metadata() const noexcept { + return state_->metadata; + } + inline const destructor_type& destructor::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/evalue.hpp b/headers/meta.hpp/meta_states/evalue.hpp index c2ecb07..1f74966 100644 --- a/headers/meta.hpp/meta_states/evalue.hpp +++ b/headers/meta.hpp/meta_states/evalue.hpp @@ -14,9 +14,10 @@ namespace meta_hpp::detail { template < enum_kind Enum > - evalue_state_ptr evalue_state::make(std::string name, Enum evalue) { + evalue_state_ptr evalue_state::make(std::string name, Enum evalue, metadata_map metadata) { return std::make_shared(evalue_state{ .index{evalue_index::make(std::move(name))}, + .metadata{std::move(metadata)}, .enum_value{uvalue{evalue}}, .underlying_value{uvalue{stdex::to_underlying(evalue)}}, }); @@ -25,9 +26,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline evalue::evalue(detail::evalue_state_ptr state) + inline evalue::evalue(detail::evalue_state_ptr state) noexcept : state_{std::move(state)} {} + inline evalue& evalue::operator=(detail::evalue_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool evalue::is_valid() const noexcept { return !!state_; } @@ -40,6 +46,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& evalue::get_metadata() const noexcept { + return state_->metadata; + } + inline const enum_type& evalue::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 1efb637..287c71b 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -106,7 +106,7 @@ namespace meta_hpp::detail [&arguments](std::index_sequence) mutable { (arguments.push_back([](){ using P = detail::type_list_at_t; - return argument{detail::argument_state::make

(I)}; + return argument{detail::argument_state::make

(I, metadata_map{})}; }.template operator()()), ...); }(std::make_index_sequence()); @@ -117,9 +117,10 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < function_policy_kind Policy, function_kind Function > - function_state_ptr function_state::make(std::string name, Function function) { + function_state_ptr function_state::make(std::string name, Function function, metadata_map metadata) { return std::make_shared(function_state{ .index{function_index::make(std::move(name))}, + .metadata{std::move(metadata)}, .invoke{make_function_invoke(std::move(function))}, .is_invocable_with{make_function_is_invocable_with()}, .arguments{make_function_arguments()}, @@ -129,9 +130,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline function::function(detail::function_state_ptr state) + inline function::function(detail::function_state_ptr state) noexcept : state_{std::move(state)} {} + inline function& function::operator=(detail::function_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool function::is_valid() const noexcept { return !!state_; } @@ -144,6 +150,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& function::get_metadata() const noexcept { + return state_->metadata; + } + inline const function_type& function::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 7ccd730..f6a4e78 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -147,9 +147,10 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < member_policy_kind Policy, member_kind Member > - member_state_ptr member_state::make(std::string name, Member member) { + member_state_ptr member_state::make(std::string name, Member member, metadata_map metadata) { return std::make_shared(member_state{ .index{member_index::make(std::move(name))}, + .metadata{std::move(metadata)}, .getter{make_member_getter(member)}, .setter{make_member_setter(member)}, .is_gettable_with{make_member_is_gettable_with()}, @@ -160,9 +161,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline member::member(detail::member_state_ptr state) + inline member::member(detail::member_state_ptr state) noexcept : state_{std::move(state)} {} + inline member& member::operator=(detail::member_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool member::is_valid() const noexcept { return !!state_; } @@ -175,6 +181,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& member::get_metadata() const noexcept { + return state_->metadata; + } + inline const member_type& member::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index d6e1340..890d663 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -119,7 +119,7 @@ namespace meta_hpp::detail [&arguments](std::index_sequence) mutable { (arguments.push_back([](){ using P = detail::type_list_at_t; - return argument{detail::argument_state::make

(I)}; + return argument{detail::argument_state::make

(I, metadata_map{})}; }.template operator()()), ...); }(std::make_index_sequence()); @@ -130,9 +130,10 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < method_policy_kind Policy, method_kind Method > - method_state_ptr method_state::make(std::string name, Method method) { + method_state_ptr method_state::make(std::string name, Method method, metadata_map metadata) { return std::make_shared(method_state{ .index{method_index::make(std::move(name))}, + .metadata{std::move(metadata)}, .invoke{make_method_invoke(std::move(method))}, .is_invocable_with{make_method_is_invocable_with()}, .arguments{make_method_arguments()}, @@ -142,9 +143,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline method::method(detail::method_state_ptr state) + inline method::method(detail::method_state_ptr state) noexcept : state_{std::move(state)} {} + inline method& method::operator=(detail::method_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool method::is_valid() const noexcept { return !!state_; } @@ -157,6 +163,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& method::get_metadata() const noexcept { + return state_->metadata; + } + inline const method_type& method::get_type() const noexcept { return state_->index.get_type(); } diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index 98922b5..24ae2f6 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -20,18 +20,24 @@ namespace meta_hpp::detail { - inline scope_state_ptr scope_state::make(std::string name) { + inline scope_state_ptr scope_state::make(std::string name, metadata_map metadata) { return std::make_shared(scope_state{ .index{scope_index::make(std::move(name))}, + .metadata{std::move(metadata)}, }); } } namespace meta_hpp { - inline scope::scope(detail::scope_state_ptr state) + inline scope::scope(detail::scope_state_ptr state) noexcept : state_{std::move(state)} {} + inline scope& scope::operator=(detail::scope_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool scope::is_valid() const noexcept { return !!state_; } @@ -44,6 +50,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& scope::get_metadata() const noexcept { + return state_->metadata; + } + inline const std::string& scope::get_name() const noexcept { return state_->index.get_name(); } diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 011085c..657dee5 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -96,9 +96,10 @@ namespace meta_hpp::detail namespace meta_hpp::detail { template < variable_policy_kind Policy, pointer_kind Pointer > - variable_state_ptr variable_state::make(std::string name, Pointer pointer) { + variable_state_ptr variable_state::make(std::string name, Pointer pointer, metadata_map metadata) { return std::make_shared(variable_state{ .index{variable_index::make(std::move(name))}, + .metadata{std::move(metadata)}, .getter{make_variable_getter(pointer)}, .setter{make_variable_setter(pointer)}, .is_settable_with{make_variable_is_settable_with()}, @@ -108,9 +109,14 @@ namespace meta_hpp::detail namespace meta_hpp { - inline variable::variable(detail::variable_state_ptr state) + inline variable::variable(detail::variable_state_ptr state) noexcept : state_{std::move(state)} {} + inline variable& variable::operator=(detail::variable_state_ptr state) noexcept { + state_ = std::move(state); + return *this; + } + inline bool variable::is_valid() const noexcept { return !!state_; } @@ -123,6 +129,10 @@ namespace meta_hpp return state_->index; } + inline const metadata_map& variable::get_metadata() const noexcept { + return state_->metadata; + } + inline const pointer_type& variable::get_type() const noexcept { return state_->index.get_type(); }