diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 3ae0d4c..c766596 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -1127,7 +1127,7 @@ namespace meta_hpp::detail std::is_same_v; template < type_family T > - [[nodiscard]] auto type_access(const T& type) { + [[nodiscard]] typename T::data_ptr type_access(const T& type) { return type.data_; } } @@ -1678,7 +1678,9 @@ namespace meta_hpp { class any_type final { public: - explicit any_type() = default; + using data_ptr = detail::type_data_base*; + + any_type() = default; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1730,14 +1732,16 @@ namespace meta_hpp [[nodiscard]] reference_type as_reference() const noexcept; [[nodiscard]] void_type as_void() const noexcept; private: - detail::type_data_base* data_{}; - friend auto detail::type_access(const any_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const any_type&); }; class array_type final { public: + using data_ptr = detail::array_type_data*; + array_type() = default; - array_type(detail::array_type_data* data); + array_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1749,14 +1753,16 @@ namespace meta_hpp [[nodiscard]] std::size_t get_extent() const noexcept; [[nodiscard]] any_type get_data_type() const noexcept; private: - detail::array_type_data* data_{}; - friend auto detail::type_access(const array_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const array_type&); }; class class_type final { public: + using data_ptr = detail::class_type_data*; + class_type() = default; - class_type(detail::class_type_data* data); + class_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1827,14 +1833,16 @@ namespace meta_hpp [[nodiscard]] method get_method_with(std::string_view name, std::span args) const noexcept; [[nodiscard]] method get_method_with(std::string_view name, std::initializer_list args) const noexcept; private: - detail::class_type_data* data_{}; - friend auto detail::type_access(const class_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const class_type&); }; class constructor_type final { public: + using data_ptr = detail::constructor_type_data*; + constructor_type() = default; - constructor_type(detail::constructor_type_data* data); + constructor_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1848,14 +1856,16 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const any_type_list& get_argument_types() const noexcept; private: - detail::constructor_type_data* data_{}; - friend auto detail::type_access(const constructor_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const constructor_type&); }; class destructor_type final { public: + using data_ptr = detail::destructor_type_data*; + destructor_type() = default; - destructor_type(detail::destructor_type_data* data); + destructor_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1866,14 +1876,16 @@ namespace meta_hpp [[nodiscard]] any_type get_class_type() const noexcept; private: - detail::destructor_type_data* data_{}; - friend auto detail::type_access(const destructor_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const destructor_type&); }; class enum_type final { public: + using data_ptr = detail::enum_type_data*; + enum_type() = default; - enum_type(detail::enum_type_data* data); + enum_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1895,14 +1907,16 @@ namespace meta_hpp template < typename T > [[nodiscard]] T name_to_value_as(std::string_view name) const; private: - detail::enum_type_data* data_{}; - friend auto detail::type_access(const enum_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const enum_type&); }; class function_type final { public: + using data_ptr = detail::function_type_data*; + function_type() = default; - function_type(detail::function_type_data* data); + function_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1916,14 +1930,16 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const any_type_list& get_argument_types() const noexcept; private: - detail::function_type_data* data_{}; - friend auto detail::type_access(const function_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const function_type&); }; class member_type final { public: + using data_ptr = detail::member_type_data*; + member_type() = default; - member_type(detail::member_type_data* data); + member_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1935,14 +1951,16 @@ namespace meta_hpp [[nodiscard]] class_type get_owner_type() const noexcept; [[nodiscard]] any_type get_value_type() const noexcept; private: - detail::member_type_data* data_{}; - friend auto detail::type_access(const member_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const member_type&); }; class method_type final { public: + using data_ptr = detail::method_type_data*; + method_type() = default; - method_type(detail::method_type_data* data); + method_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1957,14 +1975,16 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const any_type_list& get_argument_types() const noexcept; private: - detail::method_type_data* data_{}; - friend auto detail::type_access(const method_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const method_type&); }; class nullptr_type final { public: + using data_ptr = detail::nullptr_type_data*; + nullptr_type() = default; - nullptr_type(detail::nullptr_type_data* data); + nullptr_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1972,14 +1992,16 @@ namespace meta_hpp [[nodiscard]] type_id get_id() const noexcept; [[nodiscard]] const metadata_map& get_metadata() const noexcept; private: - detail::nullptr_type_data* data_{}; - friend auto detail::type_access(const nullptr_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const nullptr_type&); }; class number_type final { public: + using data_ptr = detail::number_type_data*; + number_type() = default; - number_type(detail::number_type_data* data); + number_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -1991,14 +2013,16 @@ namespace meta_hpp [[nodiscard]] std::size_t get_size() const noexcept; [[nodiscard]] std::size_t get_align() const noexcept; private: - detail::number_type_data* data_{}; - friend auto detail::type_access(const number_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const number_type&); }; class pointer_type final { public: + using data_ptr = detail::pointer_type_data*; + pointer_type() = default; - pointer_type(detail::pointer_type_data* data); + pointer_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2009,14 +2033,16 @@ namespace meta_hpp [[nodiscard]] any_type get_data_type() const noexcept; private: - detail::pointer_type_data* data_{}; - friend auto detail::type_access(const pointer_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const pointer_type&); }; class reference_type final { public: + using data_ptr = detail::reference_type_data*; + reference_type() = default; - reference_type(detail::reference_type_data* data); + reference_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2027,14 +2053,16 @@ namespace meta_hpp [[nodiscard]] any_type get_data_type() const noexcept; private: - detail::reference_type_data* data_{}; - friend auto detail::type_access(const reference_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const reference_type&); }; class void_type final { public: + using data_ptr = detail::void_type_data*; + void_type() = default; - void_type(detail::void_type_data* data); + void_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2042,8 +2070,8 @@ namespace meta_hpp [[nodiscard]] type_id get_id() const noexcept; [[nodiscard]] const metadata_map& get_metadata() const noexcept; private: - detail::void_type_data* data_{}; - friend auto detail::type_access(const void_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const void_type&); }; } @@ -2568,7 +2596,7 @@ namespace meta_hpp::detail std::is_same_v; template < state_family T > - [[nodiscard]] auto state_access(const T& state) { + [[nodiscard]] typename T::state_ptr state_access(const T& state) { return state.state_; } } @@ -2666,10 +2694,10 @@ namespace meta_hpp class argument final { public: using index_type = argument_index; + using state_ptr = detail::argument_state_ptr; - explicit argument() = default; - explicit argument(detail::argument_state_ptr state) noexcept; - argument& operator=(detail::argument_state_ptr state) noexcept; + argument() = default; + argument(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2682,17 +2710,17 @@ namespace meta_hpp [[nodiscard]] const std::string& get_name() const noexcept; private: - detail::argument_state_ptr state_; - friend auto detail::state_access(const argument&); + state_ptr state_; + friend state_ptr detail::state_access(const argument&); }; class constructor final { public: using index_type = constructor_index; + using state_ptr = detail::constructor_state_ptr; - explicit constructor() = default; - constructor(detail::constructor_state_ptr state) noexcept; - constructor& operator=(detail::constructor_state_ptr state) noexcept; + constructor() = default; + constructor(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2717,17 +2745,17 @@ namespace meta_hpp [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; private: - detail::constructor_state_ptr state_; - friend auto detail::state_access(const constructor&); + state_ptr state_; + friend state_ptr detail::state_access(const constructor&); }; class destructor final { public: using index_type = destructor_index; + using state_ptr = detail::destructor_state_ptr; - explicit destructor() = default; - destructor(detail::destructor_state_ptr state) noexcept; - destructor& operator=(detail::destructor_state_ptr state) noexcept; + destructor() = default; + destructor(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2742,17 +2770,17 @@ namespace meta_hpp void destroy_at(void* mem) const; private: - detail::destructor_state_ptr state_; - friend auto detail::state_access(const destructor&); + state_ptr state_; + friend state_ptr detail::state_access(const destructor&); }; class evalue final { public: using index_type = evalue_index; + using state_ptr = detail::evalue_state_ptr; - explicit evalue() = default; - evalue(detail::evalue_state_ptr state) noexcept; - evalue& operator=(detail::evalue_state_ptr state) noexcept; + evalue() = default; + evalue(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2772,17 +2800,17 @@ namespace meta_hpp template < typename T > [[nodiscard]] T get_underlying_value_as() const; private: - detail::evalue_state_ptr state_; - friend auto detail::state_access(const evalue&); + state_ptr state_; + friend state_ptr detail::state_access(const evalue&); }; class function final { public: using index_type = function_index; + using state_ptr = detail::function_state_ptr; - explicit function() = default; - function(detail::function_state_ptr state) noexcept; - function& operator=(detail::function_state_ptr state) noexcept; + function() = default; + function(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2808,17 +2836,17 @@ namespace meta_hpp [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; private: - detail::function_state_ptr state_; - friend auto detail::state_access(const function&); + state_ptr state_; + friend state_ptr detail::state_access(const function&); }; class member final { public: using index_type = member_index; + using state_ptr = detail::member_state_ptr; - explicit member() = default; - member(detail::member_state_ptr state) noexcept; - member& operator=(detail::member_state_ptr state) noexcept; + member() = default; + member(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2856,17 +2884,17 @@ namespace meta_hpp template < typename Instance, typename Value > [[nodiscard]] bool is_settable_with(Instance&& instance, Value&& value) const noexcept; private: - detail::member_state_ptr state_; - friend auto detail::state_access(const member&); + state_ptr state_; + friend state_ptr detail::state_access(const member&); }; class method final { public: using index_type = method_index; + using state_ptr = detail::method_state_ptr; - explicit method() = default; - method(detail::method_state_ptr state) noexcept; - method& operator=(detail::method_state_ptr state) noexcept; + method() = default; + method(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2892,17 +2920,17 @@ namespace meta_hpp [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; private: - detail::method_state_ptr state_; - friend auto detail::state_access(const method&); + state_ptr state_; + friend state_ptr detail::state_access(const method&); }; class scope final { public: using index_type = scope_index; + using state_ptr = detail::scope_state_ptr; - explicit scope() = default; - explicit scope(detail::scope_state_ptr state) noexcept; - scope& operator=(detail::scope_state_ptr state) noexcept; + scope() = default; + scope(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2927,17 +2955,17 @@ namespace meta_hpp [[nodiscard]] function get_function_with(std::string_view name, std::span args) const noexcept; [[nodiscard]] function get_function_with(std::string_view name, std::initializer_list args) const noexcept; private: - detail::scope_state_ptr state_; - friend auto detail::state_access(const scope&); + state_ptr state_; + friend state_ptr detail::state_access(const scope&); }; class variable final { public: using index_type = variable_index; + using state_ptr = detail::variable_state_ptr; - explicit variable() = default; - variable(detail::variable_state_ptr state) noexcept; - variable& operator=(detail::variable_state_ptr state) noexcept; + variable() = default; + variable(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -2967,8 +2995,8 @@ namespace meta_hpp template < typename Value > [[nodiscard]] bool is_settable_with(Value&& value) const noexcept; private: - detail::variable_state_ptr state_; - friend auto detail::state_access(const variable&); + state_ptr state_; + friend state_ptr detail::state_access(const variable&); }; } @@ -3160,7 +3188,7 @@ namespace meta_hpp::detail typedef_map typedefs{}; variable_set 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 { @@ -3220,8 +3248,10 @@ namespace meta_hpp::detail return iter->second; } - auto state = scope_state::make(std::string{name}); - auto&& [iter, _] = scopes_.insert_or_assign(std::string{name}, std::move(state)); + auto&& [iter, _] = scopes_.insert_or_assign( + std::string{name}, + scope_state::make(std::string{name}, metadata_map{})); + return iter->second; } private: @@ -3590,7 +3620,7 @@ namespace meta_hpp }; struct method_opts final { - argument_opts_list arguments{}; + argument_opts_list arguments; metadata_map metadata{}; }; @@ -3599,26 +3629,70 @@ namespace meta_hpp }; } +namespace meta_hpp +{ + template < detail::type_family Type > + class type_bind_base { + public: + explicit type_bind_base(const Type& type, metadata_map metadata) + : data_{detail::type_access(type)} { + detail::insert_or_assign(data_->metadata, std::move(metadata)); + } + + operator Type() const noexcept { + return Type{data_}; + } + protected: + using data_ptr = typename Type::data_ptr; + using data_ref = decltype(*std::declval()); + + [[nodiscard]] data_ref get_data() noexcept { + return *data_; + } + private: + data_ptr data_; + detail::type_registry::locker locker_; + }; + + template < detail::state_family State > + class state_bind_base { + public: + explicit state_bind_base(const State& state, metadata_map metadata) + : state_{detail::state_access(state)} { + detail::insert_or_assign(state_->metadata, std::move(metadata)); + } + + operator State() const noexcept { + return State{state_}; + } + protected: + using state_ptr = typename State::state_ptr; + using state_ref = decltype(*std::declval()); + + [[nodiscard]] state_ref get_state() noexcept { + return *state_; + } + private: + state_ptr state_; + detail::state_registry::locker locker_; + }; +} + namespace meta_hpp { template < detail::array_kind Array > - class array_bind final { + class array_bind final : public type_bind_base { public: explicit array_bind(metadata_map metadata); - operator array_type() const noexcept; - private: - detail::array_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::class_kind Class > - class class_bind final { + class class_bind final : public type_bind_base { public: explicit class_bind(metadata_map metadata); - operator class_type() const noexcept; // base_ @@ -3739,138 +3813,98 @@ namespace meta_hpp Pointer pointer, variable_opts opts, Policy = Policy{}); - private: - detail::class_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::enum_kind Enum > - class enum_bind final { + class enum_bind final : public type_bind_base { public: explicit enum_bind(metadata_map metadata); - operator enum_type() const noexcept; enum_bind& evalue_(std::string name, Enum value); enum_bind& evalue_(std::string name, Enum value, evalue_opts opts); - private: - detail::enum_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::function_kind Function > - class function_bind final { + class function_bind final : public type_bind_base { public: explicit function_bind(metadata_map metadata); - operator function_type() const noexcept; - private: - detail::function_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::member_kind Member > - class member_bind final { + class member_bind final : public type_bind_base { public: explicit member_bind(metadata_map metadata); - operator member_type() const noexcept; - private: - detail::member_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::method_kind Method > - class method_bind final { + class method_bind final : public type_bind_base { public: explicit method_bind(metadata_map metadata); - operator method_type() const noexcept; - private: - detail::method_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::nullptr_kind Nullptr > - class nullptr_bind final { + class nullptr_bind final : public type_bind_base { public: explicit nullptr_bind(metadata_map metadata); - operator nullptr_type() const noexcept; - private: - detail::nullptr_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::number_kind Number > - class number_bind final { + class number_bind final : public type_bind_base { public: explicit number_bind(metadata_map metadata); - operator number_type() const noexcept; - private: - detail::number_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::pointer_kind Pointer > - class pointer_bind final { + class pointer_bind final : public type_bind_base { public: explicit pointer_bind(metadata_map metadata); - operator pointer_type() const noexcept; - private: - detail::pointer_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::reference_kind Reference > - class reference_bind final { + class reference_bind final : public type_bind_base { public: explicit reference_bind(metadata_map metadata); - operator reference_type() const noexcept; - private: - detail::reference_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::void_kind Void > - class void_bind final { + class void_bind final : public type_bind_base { public: explicit void_bind(metadata_map metadata); - operator void_type() const noexcept; - private: - detail::void_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { - class scope_bind final { + class scope_bind final : public state_bind_base { public: explicit scope_bind(const scope& scope, metadata_map metadata); - operator scope() const noexcept; // function_ @@ -3918,9 +3952,6 @@ namespace meta_hpp Pointer pointer, variable_opts opts, Policy = Policy{}); - private: - detail::scope_state_ptr state_; - detail::state_registry::locker locker_{}; }; } @@ -3985,8 +4016,8 @@ namespace meta_hpp namespace meta_hpp { inline scope_bind local_scope_(std::string name, metadata_map metadata = {}) { - scope local_scope{detail::scope_state::make(std::move(name))}; - return scope_bind{local_scope, std::move(metadata)}; + scope local_scope{detail::scope_state::make(std::move(name), std::move(metadata))}; + return scope_bind{local_scope, {}}; } inline scope_bind static_scope_(std::string_view name, metadata_map metadata = {}) { @@ -4003,33 +4034,19 @@ namespace meta_hpp { template < detail::array_kind Array > array_bind::array_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::array_kind Array > - array_bind::operator array_type() const noexcept { - return array_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::class_kind Class > class_bind::class_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - + : type_bind_base{resolve_type(), std::move(metadata)} { if constexpr ( std::is_destructible_v ) { destructor_(); } } - template < detail::class_kind Class > - class_bind::operator class_type() const noexcept { - return class_type{data_}; - } - // // base_ // @@ -4042,18 +4059,18 @@ namespace meta_hpp ([this](std::in_place_type_t) { const class_type& base_type = resolve_type(); - if ( auto&& [_, emplaced] = data_->bases.emplace(base_type); !emplaced ) { + if ( auto&& [_, emplaced] = get_data().bases.emplace(base_type); !emplaced ) { return; } META_HPP_TRY { - data_->bases_info.emplace(base_type, detail::class_type_data::base_info{ + get_data().bases_info.emplace(base_type, detail::class_type_data::base_info{ .upcast = +[](void* derived) -> void* { return static_cast(static_cast(derived)); } }); } META_HPP_CATCH(...) { - data_->bases.erase(base_type); + get_data().bases.erase(base_type); META_HPP_RETHROW(); } }(std::in_place_type), ...); @@ -4092,7 +4109,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(data_->constructors, std::move(state)); + detail::insert_or_assign(get_data().constructors, std::move(state)); return *this; } @@ -4112,7 +4129,7 @@ namespace meta_hpp requires detail::class_bind_destructor_kind { auto state = detail::destructor_state::make(std::move(opts.metadata)); - detail::insert_or_assign(data_->destructors, std::move(state)); + detail::insert_or_assign(get_data().destructors, std::move(state)); return *this; } @@ -4153,7 +4170,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(data_->functions, std::move(state)); + detail::insert_or_assign(get_data().functions, std::move(state)); return *this; } @@ -4180,7 +4197,7 @@ namespace meta_hpp detail::state_access(arg)->name = std::data(arguments)[i]; } - detail::insert_or_assign(data_->functions, std::move(state)); + detail::insert_or_assign(get_data().functions, std::move(state)); return *this; } @@ -4212,7 +4229,7 @@ namespace meta_hpp std::move(name), std::move(member), std::move(opts.metadata)); - detail::insert_or_assign(data_->members, std::move(state)); + detail::insert_or_assign(get_data().members, std::move(state)); return *this; } @@ -4255,7 +4272,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(data_->methods, std::move(state)); + detail::insert_or_assign(get_data().methods, std::move(state)); return *this; } @@ -4283,7 +4300,7 @@ namespace meta_hpp detail::state_access(arg)->name = std::data(arguments)[i]; } - detail::insert_or_assign(data_->methods, std::move(state)); + detail::insert_or_assign(get_data().methods, std::move(state)); return *this; } @@ -4294,7 +4311,7 @@ namespace meta_hpp template < detail::class_kind Class > template < typename Type > class_bind& class_bind::typedef_(std::string name) { - data_->typedefs.insert_or_assign(std::move(name), resolve_type()); + get_data().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } @@ -4324,7 +4341,7 @@ namespace meta_hpp std::move(name), std::move(pointer), std::move(opts.metadata)); - detail::insert_or_assign(data_->variables, std::move(state)); + detail::insert_or_assign(get_data().variables, std::move(state)); return *this; } } @@ -4333,14 +4350,7 @@ namespace meta_hpp { template < detail::enum_kind Enum > enum_bind::enum_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::enum_kind Enum > - enum_bind::operator enum_type() const noexcept { - return enum_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} template < detail::enum_kind Enum > enum_bind& enum_bind::evalue_(std::string name, Enum value) { @@ -4353,7 +4363,7 @@ namespace meta_hpp std::move(name), std::move(value), std::move(opts.metadata)); - detail::insert_or_assign(data_->evalues, std::move(state)); + detail::insert_or_assign(get_data().evalues, std::move(state)); return *this; } } @@ -4362,110 +4372,55 @@ namespace meta_hpp { template < detail::function_kind Function > function_bind::function_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::function_kind Function > - function_bind::operator function_type() const noexcept { - return function_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::member_kind Member > member_bind::member_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::member_kind Member > - member_bind::operator member_type() const noexcept { - return member_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::method_kind Method > method_bind::method_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::method_kind Method > - method_bind::operator method_type() const noexcept { - return method_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::nullptr_kind Nullptr > nullptr_bind::nullptr_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::nullptr_kind Nullptr > - nullptr_bind::operator nullptr_type() const noexcept { - return nullptr_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::number_kind Number > number_bind::number_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::number_kind Number > - number_bind::operator number_type() const noexcept { - return number_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::pointer_kind Pointer > pointer_bind::pointer_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::pointer_kind Pointer > - pointer_bind::operator pointer_type() const noexcept { - return pointer_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { template < detail::reference_kind Reference > reference_bind::reference_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::reference_kind Reference > - reference_bind::operator reference_type() const noexcept { - return reference_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp { inline scope_bind::scope_bind(const scope& scope, metadata_map metadata) - : state_{detail::state_access(scope)} { - detail::insert_or_assign(state_->metadata, std::move(metadata)); - } - - inline scope_bind::operator scope() const noexcept { - return scope{state_}; - } + : state_bind_base{scope, std::move(metadata)} {} // // function_ @@ -4502,7 +4457,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(state_->functions, std::move(state)); + detail::insert_or_assign(get_state().functions, std::move(state)); return *this; } @@ -4528,7 +4483,7 @@ namespace meta_hpp detail::state_access(arg)->name = std::data(arguments)[i]; } - detail::insert_or_assign(state_->functions, std::move(state)); + detail::insert_or_assign(get_state().functions, std::move(state)); return *this; } @@ -4538,7 +4493,7 @@ namespace meta_hpp template < typename Type > scope_bind& scope_bind::typedef_(std::string name) { - state_->typedefs.insert_or_assign(std::move(name), resolve_type()); + get_state().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } @@ -4566,7 +4521,7 @@ namespace meta_hpp std::move(name), std::move(pointer), std::move(opts.metadata)); - detail::insert_or_assign(state_->variables, std::move(state)); + detail::insert_or_assign(get_state().variables, std::move(state)); return *this; } } @@ -4575,14 +4530,7 @@ namespace meta_hpp { template < detail::void_kind Void > void_bind::void_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::void_kind Void > - void_bind::operator void_type() const noexcept { - return void_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } namespace meta_hpp @@ -4907,14 +4855,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline argument::argument(detail::argument_state_ptr state) noexcept + inline argument::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_; } @@ -4959,7 +4902,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline constructor_type::constructor_type(detail::constructor_type_data* data) + inline constructor_type::constructor_type(data_ptr data) : data_{data} {} inline bool constructor_type::is_valid() const noexcept { @@ -5592,14 +5535,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline constructor::constructor(detail::constructor_state_ptr state) noexcept + inline constructor::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_; } @@ -5687,7 +5625,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline destructor_type::destructor_type(detail::destructor_type_data* data) + inline destructor_type::destructor_type(data_ptr data) : data_{data} {} inline bool destructor_type::is_valid() const noexcept { @@ -5767,14 +5705,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline destructor::destructor(detail::destructor_state_ptr state) noexcept + inline destructor::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_; } @@ -5821,7 +5754,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline enum_type::enum_type(detail::enum_type_data* data) + inline enum_type::enum_type(data_ptr data) : data_{data} {} inline bool enum_type::is_valid() const noexcept { @@ -5905,14 +5838,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline evalue::evalue(detail::evalue_state_ptr state) noexcept + inline evalue::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_; } @@ -5971,7 +5899,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline function_type::function_type(detail::function_type_data* data) + inline function_type::function_type(data_ptr data) : data_{data} {} inline bool function_type::is_valid() const noexcept { @@ -6123,14 +6051,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline function::function(detail::function_state_ptr state) noexcept + inline function::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_; } @@ -6217,7 +6140,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline member_type::member_type(detail::member_type_data* data) + inline member_type::member_type(data_ptr data) : data_{data} {} inline bool member_type::is_valid() const noexcept { @@ -6626,14 +6549,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline member::member(detail::member_state_ptr state) noexcept + inline member::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_; } @@ -6735,7 +6653,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline method_type::method_type(detail::method_type_data* data) + inline method_type::method_type(data_ptr data) : data_{data} {} inline bool method_type::is_valid() const noexcept { @@ -6901,14 +6819,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline method::method(detail::method_state_ptr state) noexcept + inline method::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_; } @@ -6997,7 +6910,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline pointer_type::pointer_type(detail::pointer_type_data* data) + inline pointer_type::pointer_type(data_ptr data) : data_{data} {} inline bool pointer_type::is_valid() const noexcept { @@ -7122,14 +7035,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline variable::variable(detail::variable_state_ptr state) noexcept + inline variable::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_; } @@ -7210,7 +7118,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline class_type::class_type(detail::class_type_data* data) + inline class_type::class_type(data_ptr data) : data_{data} {} inline bool class_type::is_valid() const noexcept { @@ -7567,23 +7475,19 @@ namespace meta_hpp 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) noexcept + inline scope::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_; } @@ -7864,7 +7768,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline array_type::array_type(detail::array_type_data* data) + inline array_type::array_type(data_ptr data) : data_{data} {} inline bool array_type::is_valid() const noexcept { @@ -7908,7 +7812,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline nullptr_type::nullptr_type(detail::nullptr_type_data* data) + inline nullptr_type::nullptr_type(data_ptr data) : data_{data} {} inline bool nullptr_type::is_valid() const noexcept { @@ -7943,7 +7847,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline number_type::number_type(detail::number_type_data* data) + inline number_type::number_type(data_ptr data) : data_{data} {} inline bool number_type::is_valid() const noexcept { @@ -7989,7 +7893,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline reference_type::reference_type(detail::reference_type_data* data) + inline reference_type::reference_type(data_ptr data) : data_{data} {} inline bool reference_type::is_valid() const noexcept { @@ -8029,7 +7933,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline void_type::void_type(detail::void_type_data* data) + inline void_type::void_type(data_ptr data) : data_{data} {} inline bool void_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 292e4f1..7629f1a 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -70,7 +70,7 @@ namespace meta_hpp }; struct method_opts final { - argument_opts_list arguments{}; + argument_opts_list arguments; metadata_map metadata{}; }; @@ -79,26 +79,70 @@ namespace meta_hpp }; } +namespace meta_hpp +{ + template < detail::type_family Type > + class type_bind_base { + public: + explicit type_bind_base(const Type& type, metadata_map metadata) + : data_{detail::type_access(type)} { + detail::insert_or_assign(data_->metadata, std::move(metadata)); + } + + operator Type() const noexcept { + return Type{data_}; + } + protected: + using data_ptr = typename Type::data_ptr; + using data_ref = decltype(*std::declval()); + + [[nodiscard]] data_ref get_data() noexcept { + return *data_; + } + private: + data_ptr data_; + detail::type_registry::locker locker_; + }; + + template < detail::state_family State > + class state_bind_base { + public: + explicit state_bind_base(const State& state, metadata_map metadata) + : state_{detail::state_access(state)} { + detail::insert_or_assign(state_->metadata, std::move(metadata)); + } + + operator State() const noexcept { + return State{state_}; + } + protected: + using state_ptr = typename State::state_ptr; + using state_ref = decltype(*std::declval()); + + [[nodiscard]] state_ref get_state() noexcept { + return *state_; + } + private: + state_ptr state_; + detail::state_registry::locker locker_; + }; +} + namespace meta_hpp { template < detail::array_kind Array > - class array_bind final { + class array_bind final : public type_bind_base { public: explicit array_bind(metadata_map metadata); - operator array_type() const noexcept; - private: - detail::array_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::class_kind Class > - class class_bind final { + class class_bind final : public type_bind_base { public: explicit class_bind(metadata_map metadata); - operator class_type() const noexcept; // base_ @@ -219,138 +263,98 @@ namespace meta_hpp Pointer pointer, variable_opts opts, Policy = Policy{}); - private: - detail::class_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::enum_kind Enum > - class enum_bind final { + class enum_bind final : public type_bind_base { public: explicit enum_bind(metadata_map metadata); - operator enum_type() const noexcept; enum_bind& evalue_(std::string name, Enum value); enum_bind& evalue_(std::string name, Enum value, evalue_opts opts); - private: - detail::enum_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::function_kind Function > - class function_bind final { + class function_bind final : public type_bind_base { public: explicit function_bind(metadata_map metadata); - operator function_type() const noexcept; - private: - detail::function_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::member_kind Member > - class member_bind final { + class member_bind final : public type_bind_base { public: explicit member_bind(metadata_map metadata); - operator member_type() const noexcept; - private: - detail::member_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::method_kind Method > - class method_bind final { + class method_bind final : public type_bind_base { public: explicit method_bind(metadata_map metadata); - operator method_type() const noexcept; - private: - detail::method_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::nullptr_kind Nullptr > - class nullptr_bind final { + class nullptr_bind final : public type_bind_base { public: explicit nullptr_bind(metadata_map metadata); - operator nullptr_type() const noexcept; - private: - detail::nullptr_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::number_kind Number > - class number_bind final { + class number_bind final : public type_bind_base { public: explicit number_bind(metadata_map metadata); - operator number_type() const noexcept; - private: - detail::number_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::pointer_kind Pointer > - class pointer_bind final { + class pointer_bind final : public type_bind_base { public: explicit pointer_bind(metadata_map metadata); - operator pointer_type() const noexcept; - private: - detail::pointer_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::reference_kind Reference > - class reference_bind final { + class reference_bind final : public type_bind_base { public: explicit reference_bind(metadata_map metadata); - operator reference_type() const noexcept; - private: - detail::reference_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { template < detail::void_kind Void > - class void_bind final { + class void_bind final : public type_bind_base { public: explicit void_bind(metadata_map metadata); - operator void_type() const noexcept; - private: - detail::void_type_data* data_{}; - detail::type_registry::locker locker_{}; }; } namespace meta_hpp { - class scope_bind final { + class scope_bind final : public state_bind_base { public: explicit scope_bind(const scope& scope, metadata_map metadata); - operator scope() const noexcept; // function_ @@ -398,9 +402,6 @@ namespace meta_hpp Pointer pointer, variable_opts opts, Policy = Policy{}); - private: - detail::scope_state_ptr state_; - detail::state_registry::locker locker_{}; }; } @@ -465,8 +466,8 @@ namespace meta_hpp namespace meta_hpp { inline scope_bind local_scope_(std::string name, metadata_map metadata = {}) { - scope local_scope{detail::scope_state::make(std::move(name))}; - return scope_bind{local_scope, std::move(metadata)}; + scope local_scope{detail::scope_state::make(std::move(name), std::move(metadata))}; + return scope_bind{local_scope, {}}; } inline scope_bind static_scope_(std::string_view name, metadata_map metadata = {}) { diff --git a/headers/meta.hpp/meta_binds/array_bind.hpp b/headers/meta.hpp/meta_binds/array_bind.hpp index 713ef2b..656a0e3 100644 --- a/headers/meta.hpp/meta_binds/array_bind.hpp +++ b/headers/meta.hpp/meta_binds/array_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::array_kind Array > array_bind::array_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::array_kind Array > - array_bind::operator array_type() const noexcept { - return array_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index 1c8c2c3..0be72de 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -14,19 +14,12 @@ namespace meta_hpp { template < detail::class_kind Class > class_bind::class_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - + : type_bind_base{resolve_type(), std::move(metadata)} { if constexpr ( std::is_destructible_v ) { destructor_(); } } - template < detail::class_kind Class > - class_bind::operator class_type() const noexcept { - return class_type{data_}; - } - // // base_ // @@ -39,18 +32,18 @@ namespace meta_hpp ([this](std::in_place_type_t) { const class_type& base_type = resolve_type(); - if ( auto&& [_, emplaced] = data_->bases.emplace(base_type); !emplaced ) { + if ( auto&& [_, emplaced] = get_data().bases.emplace(base_type); !emplaced ) { return; } META_HPP_TRY { - data_->bases_info.emplace(base_type, detail::class_type_data::base_info{ + get_data().bases_info.emplace(base_type, detail::class_type_data::base_info{ .upcast = +[](void* derived) -> void* { return static_cast(static_cast(derived)); } }); } META_HPP_CATCH(...) { - data_->bases.erase(base_type); + get_data().bases.erase(base_type); META_HPP_RETHROW(); } }(std::in_place_type), ...); @@ -89,7 +82,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(data_->constructors, std::move(state)); + detail::insert_or_assign(get_data().constructors, std::move(state)); return *this; } @@ -109,7 +102,7 @@ namespace meta_hpp requires detail::class_bind_destructor_kind { auto state = detail::destructor_state::make(std::move(opts.metadata)); - detail::insert_or_assign(data_->destructors, std::move(state)); + detail::insert_or_assign(get_data().destructors, std::move(state)); return *this; } @@ -150,7 +143,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(data_->functions, std::move(state)); + detail::insert_or_assign(get_data().functions, std::move(state)); return *this; } @@ -177,7 +170,7 @@ namespace meta_hpp detail::state_access(arg)->name = std::data(arguments)[i]; } - detail::insert_or_assign(data_->functions, std::move(state)); + detail::insert_or_assign(get_data().functions, std::move(state)); return *this; } @@ -209,7 +202,7 @@ namespace meta_hpp std::move(name), std::move(member), std::move(opts.metadata)); - detail::insert_or_assign(data_->members, std::move(state)); + detail::insert_or_assign(get_data().members, std::move(state)); return *this; } @@ -252,7 +245,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(data_->methods, std::move(state)); + detail::insert_or_assign(get_data().methods, std::move(state)); return *this; } @@ -280,7 +273,7 @@ namespace meta_hpp detail::state_access(arg)->name = std::data(arguments)[i]; } - detail::insert_or_assign(data_->methods, std::move(state)); + detail::insert_or_assign(get_data().methods, std::move(state)); return *this; } @@ -291,7 +284,7 @@ namespace meta_hpp template < detail::class_kind Class > template < typename Type > class_bind& class_bind::typedef_(std::string name) { - data_->typedefs.insert_or_assign(std::move(name), resolve_type()); + get_data().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } @@ -321,7 +314,7 @@ namespace meta_hpp std::move(name), std::move(pointer), std::move(opts.metadata)); - detail::insert_or_assign(data_->variables, std::move(state)); + detail::insert_or_assign(get_data().variables, std::move(state)); return *this; } } diff --git a/headers/meta.hpp/meta_binds/enum_bind.hpp b/headers/meta.hpp/meta_binds/enum_bind.hpp index 9a2b77b..9c3bfb0 100644 --- a/headers/meta.hpp/meta_binds/enum_bind.hpp +++ b/headers/meta.hpp/meta_binds/enum_bind.hpp @@ -14,14 +14,7 @@ namespace meta_hpp { template < detail::enum_kind Enum > enum_bind::enum_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::enum_kind Enum > - enum_bind::operator enum_type() const noexcept { - return enum_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} template < detail::enum_kind Enum > enum_bind& enum_bind::evalue_(std::string name, Enum value) { @@ -34,7 +27,7 @@ namespace meta_hpp std::move(name), std::move(value), std::move(opts.metadata)); - detail::insert_or_assign(data_->evalues, std::move(state)); + detail::insert_or_assign(get_data().evalues, std::move(state)); return *this; } } diff --git a/headers/meta.hpp/meta_binds/function_bind.hpp b/headers/meta.hpp/meta_binds/function_bind.hpp index 27c8ca0..e11dd6b 100644 --- a/headers/meta.hpp/meta_binds/function_bind.hpp +++ b/headers/meta.hpp/meta_binds/function_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::function_kind Function > function_bind::function_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::function_kind Function > - function_bind::operator function_type() const noexcept { - return function_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/member_bind.hpp b/headers/meta.hpp/meta_binds/member_bind.hpp index 1c4c4c4..878ee7e 100644 --- a/headers/meta.hpp/meta_binds/member_bind.hpp +++ b/headers/meta.hpp/meta_binds/member_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::member_kind Member > member_bind::member_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::member_kind Member > - member_bind::operator member_type() const noexcept { - return member_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/method_bind.hpp b/headers/meta.hpp/meta_binds/method_bind.hpp index 195bcb2..f643d5c 100644 --- a/headers/meta.hpp/meta_binds/method_bind.hpp +++ b/headers/meta.hpp/meta_binds/method_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::method_kind Method > method_bind::method_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::method_kind Method > - method_bind::operator method_type() const noexcept { - return method_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/nullptr_bind.hpp b/headers/meta.hpp/meta_binds/nullptr_bind.hpp index f2d03f1..d0e1288 100644 --- a/headers/meta.hpp/meta_binds/nullptr_bind.hpp +++ b/headers/meta.hpp/meta_binds/nullptr_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::nullptr_kind Nullptr > nullptr_bind::nullptr_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::nullptr_kind Nullptr > - nullptr_bind::operator nullptr_type() const noexcept { - return nullptr_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/number_bind.hpp b/headers/meta.hpp/meta_binds/number_bind.hpp index 8880d0e..5bbf3ca 100644 --- a/headers/meta.hpp/meta_binds/number_bind.hpp +++ b/headers/meta.hpp/meta_binds/number_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::number_kind Number > number_bind::number_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::number_kind Number > - number_bind::operator number_type() const noexcept { - return number_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/pointer_bind.hpp b/headers/meta.hpp/meta_binds/pointer_bind.hpp index 176acd1..74c88b7 100644 --- a/headers/meta.hpp/meta_binds/pointer_bind.hpp +++ b/headers/meta.hpp/meta_binds/pointer_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::pointer_kind Pointer > pointer_bind::pointer_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::pointer_kind Pointer > - pointer_bind::operator pointer_type() const noexcept { - return pointer_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/reference_bind.hpp b/headers/meta.hpp/meta_binds/reference_bind.hpp index 4ab9a9b..d87cb71 100644 --- a/headers/meta.hpp/meta_binds/reference_bind.hpp +++ b/headers/meta.hpp/meta_binds/reference_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::reference_kind Reference > reference_bind::reference_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::reference_kind Reference > - reference_bind::operator reference_type() const noexcept { - return reference_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index c80ad82..077cd6a 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -13,13 +13,7 @@ namespace meta_hpp { inline scope_bind::scope_bind(const scope& scope, metadata_map metadata) - : state_{detail::state_access(scope)} { - detail::insert_or_assign(state_->metadata, std::move(metadata)); - } - - inline scope_bind::operator scope() const noexcept { - return scope{state_}; - } + : state_bind_base{scope, std::move(metadata)} {} // // function_ @@ -56,7 +50,7 @@ namespace meta_hpp detail::state_access(arg)->metadata = std::move(opts.arguments[i].metadata); } - detail::insert_or_assign(state_->functions, std::move(state)); + detail::insert_or_assign(get_state().functions, std::move(state)); return *this; } @@ -82,7 +76,7 @@ namespace meta_hpp detail::state_access(arg)->name = std::data(arguments)[i]; } - detail::insert_or_assign(state_->functions, std::move(state)); + detail::insert_or_assign(get_state().functions, std::move(state)); return *this; } @@ -92,7 +86,7 @@ namespace meta_hpp template < typename Type > scope_bind& scope_bind::typedef_(std::string name) { - state_->typedefs.insert_or_assign(std::move(name), resolve_type()); + get_state().typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } @@ -120,7 +114,7 @@ namespace meta_hpp std::move(name), std::move(pointer), std::move(opts.metadata)); - detail::insert_or_assign(state_->variables, std::move(state)); + detail::insert_or_assign(get_state().variables, std::move(state)); return *this; } } diff --git a/headers/meta.hpp/meta_binds/void_bind.hpp b/headers/meta.hpp/meta_binds/void_bind.hpp index a69126d..34b7c27 100644 --- a/headers/meta.hpp/meta_binds/void_bind.hpp +++ b/headers/meta.hpp/meta_binds/void_bind.hpp @@ -14,12 +14,5 @@ namespace meta_hpp { template < detail::void_kind Void > void_bind::void_bind(metadata_map metadata) - : data_{detail::type_access(resolve_type())} { - detail::insert_or_assign(data_->metadata, std::move(metadata)); - } - - template < detail::void_kind Void > - void_bind::operator void_type() const noexcept { - return void_type{data_}; - } + : type_bind_base{resolve_type(), std::move(metadata)} {} } diff --git a/headers/meta.hpp/meta_detail/state_family.hpp b/headers/meta.hpp/meta_detail/state_family.hpp index 18d890e..19d092b 100644 --- a/headers/meta.hpp/meta_detail/state_family.hpp +++ b/headers/meta.hpp/meta_detail/state_family.hpp @@ -23,7 +23,7 @@ namespace meta_hpp::detail std::is_same_v; template < state_family T > - [[nodiscard]] auto state_access(const T& state) { + [[nodiscard]] typename T::state_ptr state_access(const T& state) { return state.state_; } } diff --git a/headers/meta.hpp/meta_detail/state_registry.hpp b/headers/meta.hpp/meta_detail/state_registry.hpp index 2f39aef..c6cae37 100644 --- a/headers/meta.hpp/meta_detail/state_registry.hpp +++ b/headers/meta.hpp/meta_detail/state_registry.hpp @@ -49,8 +49,10 @@ namespace meta_hpp::detail return iter->second; } - auto state = scope_state::make(std::string{name}); - auto&& [iter, _] = scopes_.insert_or_assign(std::string{name}, std::move(state)); + auto&& [iter, _] = scopes_.insert_or_assign( + std::string{name}, + scope_state::make(std::string{name}, metadata_map{})); + return iter->second; } private: diff --git a/headers/meta.hpp/meta_detail/type_family.hpp b/headers/meta.hpp/meta_detail/type_family.hpp index 00a8e40..c7693fc 100644 --- a/headers/meta.hpp/meta_detail/type_family.hpp +++ b/headers/meta.hpp/meta_detail/type_family.hpp @@ -28,7 +28,7 @@ namespace meta_hpp::detail std::is_same_v; template < type_family T > - [[nodiscard]] auto type_access(const T& type) { + [[nodiscard]] typename T::data_ptr type_access(const T& type) { return type.data_; } } diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index f0e4396..09871c4 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -106,10 +106,10 @@ namespace meta_hpp class argument final { public: using index_type = argument_index; + using state_ptr = detail::argument_state_ptr; - explicit argument() = default; - explicit argument(detail::argument_state_ptr state) noexcept; - argument& operator=(detail::argument_state_ptr state) noexcept; + argument() = default; + argument(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -122,17 +122,17 @@ namespace meta_hpp [[nodiscard]] const std::string& get_name() const noexcept; private: - detail::argument_state_ptr state_; - friend auto detail::state_access(const argument&); + state_ptr state_; + friend state_ptr detail::state_access(const argument&); }; class constructor final { public: using index_type = constructor_index; + using state_ptr = detail::constructor_state_ptr; - explicit constructor() = default; - constructor(detail::constructor_state_ptr state) noexcept; - constructor& operator=(detail::constructor_state_ptr state) noexcept; + constructor() = default; + constructor(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -157,17 +157,17 @@ namespace meta_hpp [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; private: - detail::constructor_state_ptr state_; - friend auto detail::state_access(const constructor&); + state_ptr state_; + friend state_ptr detail::state_access(const constructor&); }; class destructor final { public: using index_type = destructor_index; + using state_ptr = detail::destructor_state_ptr; - explicit destructor() = default; - destructor(detail::destructor_state_ptr state) noexcept; - destructor& operator=(detail::destructor_state_ptr state) noexcept; + destructor() = default; + destructor(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -182,17 +182,17 @@ namespace meta_hpp void destroy_at(void* mem) const; private: - detail::destructor_state_ptr state_; - friend auto detail::state_access(const destructor&); + state_ptr state_; + friend state_ptr detail::state_access(const destructor&); }; class evalue final { public: using index_type = evalue_index; + using state_ptr = detail::evalue_state_ptr; - explicit evalue() = default; - evalue(detail::evalue_state_ptr state) noexcept; - evalue& operator=(detail::evalue_state_ptr state) noexcept; + evalue() = default; + evalue(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -212,17 +212,17 @@ namespace meta_hpp template < typename T > [[nodiscard]] T get_underlying_value_as() const; private: - detail::evalue_state_ptr state_; - friend auto detail::state_access(const evalue&); + state_ptr state_; + friend state_ptr detail::state_access(const evalue&); }; class function final { public: using index_type = function_index; + using state_ptr = detail::function_state_ptr; - explicit function() = default; - function(detail::function_state_ptr state) noexcept; - function& operator=(detail::function_state_ptr state) noexcept; + function() = default; + function(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -248,17 +248,17 @@ namespace meta_hpp [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; private: - detail::function_state_ptr state_; - friend auto detail::state_access(const function&); + state_ptr state_; + friend state_ptr detail::state_access(const function&); }; class member final { public: using index_type = member_index; + using state_ptr = detail::member_state_ptr; - explicit member() = default; - member(detail::member_state_ptr state) noexcept; - member& operator=(detail::member_state_ptr state) noexcept; + member() = default; + member(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -296,17 +296,17 @@ namespace meta_hpp template < typename Instance, typename Value > [[nodiscard]] bool is_settable_with(Instance&& instance, Value&& value) const noexcept; private: - detail::member_state_ptr state_; - friend auto detail::state_access(const member&); + state_ptr state_; + friend state_ptr detail::state_access(const member&); }; class method final { public: using index_type = method_index; + using state_ptr = detail::method_state_ptr; - explicit method() = default; - method(detail::method_state_ptr state) noexcept; - method& operator=(detail::method_state_ptr state) noexcept; + method() = default; + method(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -332,17 +332,17 @@ namespace meta_hpp [[nodiscard]] argument get_argument(std::size_t position) const noexcept; [[nodiscard]] const argument_list& get_arguments() const noexcept; private: - detail::method_state_ptr state_; - friend auto detail::state_access(const method&); + state_ptr state_; + friend state_ptr detail::state_access(const method&); }; class scope final { public: using index_type = scope_index; + using state_ptr = detail::scope_state_ptr; - explicit scope() = default; - explicit scope(detail::scope_state_ptr state) noexcept; - scope& operator=(detail::scope_state_ptr state) noexcept; + scope() = default; + scope(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -367,17 +367,17 @@ namespace meta_hpp [[nodiscard]] function get_function_with(std::string_view name, std::span args) const noexcept; [[nodiscard]] function get_function_with(std::string_view name, std::initializer_list args) const noexcept; private: - detail::scope_state_ptr state_; - friend auto detail::state_access(const scope&); + state_ptr state_; + friend state_ptr detail::state_access(const scope&); }; class variable final { public: using index_type = variable_index; + using state_ptr = detail::variable_state_ptr; - explicit variable() = default; - variable(detail::variable_state_ptr state) noexcept; - variable& operator=(detail::variable_state_ptr state) noexcept; + variable() = default; + variable(state_ptr state) noexcept; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -407,8 +407,8 @@ namespace meta_hpp template < typename Value > [[nodiscard]] bool is_settable_with(Value&& value) const noexcept; private: - detail::variable_state_ptr state_; - friend auto detail::state_access(const variable&); + state_ptr state_; + friend state_ptr detail::state_access(const variable&); }; } @@ -600,7 +600,7 @@ namespace meta_hpp::detail typedef_map typedefs{}; variable_set 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 { diff --git a/headers/meta.hpp/meta_states/argument.hpp b/headers/meta.hpp/meta_states/argument.hpp index 9effff3..eaeab9a 100644 --- a/headers/meta.hpp/meta_states/argument.hpp +++ b/headers/meta.hpp/meta_states/argument.hpp @@ -23,14 +23,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline argument::argument(detail::argument_state_ptr state) noexcept + inline argument::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_; } diff --git a/headers/meta.hpp/meta_states/constructor.hpp b/headers/meta.hpp/meta_states/constructor.hpp index 43efa53..81db4d1 100644 --- a/headers/meta.hpp/meta_states/constructor.hpp +++ b/headers/meta.hpp/meta_states/constructor.hpp @@ -142,14 +142,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline constructor::constructor(detail::constructor_state_ptr state) noexcept + inline constructor::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_; } diff --git a/headers/meta.hpp/meta_states/destructor.hpp b/headers/meta.hpp/meta_states/destructor.hpp index 8f392fa..6630af4 100644 --- a/headers/meta.hpp/meta_states/destructor.hpp +++ b/headers/meta.hpp/meta_states/destructor.hpp @@ -64,14 +64,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline destructor::destructor(detail::destructor_state_ptr state) noexcept + inline destructor::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_; } diff --git a/headers/meta.hpp/meta_states/evalue.hpp b/headers/meta.hpp/meta_states/evalue.hpp index 6b30f19..f485d4f 100644 --- a/headers/meta.hpp/meta_states/evalue.hpp +++ b/headers/meta.hpp/meta_states/evalue.hpp @@ -26,14 +26,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline evalue::evalue(detail::evalue_state_ptr state) noexcept + inline evalue::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_; } diff --git a/headers/meta.hpp/meta_states/function.hpp b/headers/meta.hpp/meta_states/function.hpp index 226ff8a..737e247 100644 --- a/headers/meta.hpp/meta_states/function.hpp +++ b/headers/meta.hpp/meta_states/function.hpp @@ -124,14 +124,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline function::function(detail::function_state_ptr state) noexcept + inline function::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_; } diff --git a/headers/meta.hpp/meta_states/member.hpp b/headers/meta.hpp/meta_states/member.hpp index 583b4a6..bbc8e71 100644 --- a/headers/meta.hpp/meta_states/member.hpp +++ b/headers/meta.hpp/meta_states/member.hpp @@ -161,14 +161,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline member::member(detail::member_state_ptr state) noexcept + inline member::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_; } diff --git a/headers/meta.hpp/meta_states/method.hpp b/headers/meta.hpp/meta_states/method.hpp index 6ed8f8d..761ba48 100644 --- a/headers/meta.hpp/meta_states/method.hpp +++ b/headers/meta.hpp/meta_states/method.hpp @@ -135,14 +135,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline method::method(detail::method_state_ptr state) noexcept + inline method::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_; } diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index 924e7cb..e804ce4 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -19,23 +19,19 @@ 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) noexcept + inline scope::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_; } diff --git a/headers/meta.hpp/meta_states/variable.hpp b/headers/meta.hpp/meta_states/variable.hpp index 7269d12..5ac330f 100644 --- a/headers/meta.hpp/meta_states/variable.hpp +++ b/headers/meta.hpp/meta_states/variable.hpp @@ -109,14 +109,9 @@ namespace meta_hpp::detail namespace meta_hpp { - inline variable::variable(detail::variable_state_ptr state) noexcept + inline variable::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_; } diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index ca9ad51..6a708d7 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -62,7 +62,9 @@ namespace meta_hpp { class any_type final { public: - explicit any_type() = default; + using data_ptr = detail::type_data_base*; + + any_type() = default; [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -114,14 +116,16 @@ namespace meta_hpp [[nodiscard]] reference_type as_reference() const noexcept; [[nodiscard]] void_type as_void() const noexcept; private: - detail::type_data_base* data_{}; - friend auto detail::type_access(const any_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const any_type&); }; class array_type final { public: + using data_ptr = detail::array_type_data*; + array_type() = default; - array_type(detail::array_type_data* data); + array_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -133,14 +137,16 @@ namespace meta_hpp [[nodiscard]] std::size_t get_extent() const noexcept; [[nodiscard]] any_type get_data_type() const noexcept; private: - detail::array_type_data* data_{}; - friend auto detail::type_access(const array_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const array_type&); }; class class_type final { public: + using data_ptr = detail::class_type_data*; + class_type() = default; - class_type(detail::class_type_data* data); + class_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -211,14 +217,16 @@ namespace meta_hpp [[nodiscard]] method get_method_with(std::string_view name, std::span args) const noexcept; [[nodiscard]] method get_method_with(std::string_view name, std::initializer_list args) const noexcept; private: - detail::class_type_data* data_{}; - friend auto detail::type_access(const class_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const class_type&); }; class constructor_type final { public: + using data_ptr = detail::constructor_type_data*; + constructor_type() = default; - constructor_type(detail::constructor_type_data* data); + constructor_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -232,14 +240,16 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const any_type_list& get_argument_types() const noexcept; private: - detail::constructor_type_data* data_{}; - friend auto detail::type_access(const constructor_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const constructor_type&); }; class destructor_type final { public: + using data_ptr = detail::destructor_type_data*; + destructor_type() = default; - destructor_type(detail::destructor_type_data* data); + destructor_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -250,14 +260,16 @@ namespace meta_hpp [[nodiscard]] any_type get_class_type() const noexcept; private: - detail::destructor_type_data* data_{}; - friend auto detail::type_access(const destructor_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const destructor_type&); }; class enum_type final { public: + using data_ptr = detail::enum_type_data*; + enum_type() = default; - enum_type(detail::enum_type_data* data); + enum_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -279,14 +291,16 @@ namespace meta_hpp template < typename T > [[nodiscard]] T name_to_value_as(std::string_view name) const; private: - detail::enum_type_data* data_{}; - friend auto detail::type_access(const enum_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const enum_type&); }; class function_type final { public: + using data_ptr = detail::function_type_data*; + function_type() = default; - function_type(detail::function_type_data* data); + function_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -300,14 +314,16 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const any_type_list& get_argument_types() const noexcept; private: - detail::function_type_data* data_{}; - friend auto detail::type_access(const function_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const function_type&); }; class member_type final { public: + using data_ptr = detail::member_type_data*; + member_type() = default; - member_type(detail::member_type_data* data); + member_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -319,14 +335,16 @@ namespace meta_hpp [[nodiscard]] class_type get_owner_type() const noexcept; [[nodiscard]] any_type get_value_type() const noexcept; private: - detail::member_type_data* data_{}; - friend auto detail::type_access(const member_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const member_type&); }; class method_type final { public: + using data_ptr = detail::method_type_data*; + method_type() = default; - method_type(detail::method_type_data* data); + method_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -341,14 +359,16 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const any_type_list& get_argument_types() const noexcept; private: - detail::method_type_data* data_{}; - friend auto detail::type_access(const method_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const method_type&); }; class nullptr_type final { public: + using data_ptr = detail::nullptr_type_data*; + nullptr_type() = default; - nullptr_type(detail::nullptr_type_data* data); + nullptr_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -356,14 +376,16 @@ namespace meta_hpp [[nodiscard]] type_id get_id() const noexcept; [[nodiscard]] const metadata_map& get_metadata() const noexcept; private: - detail::nullptr_type_data* data_{}; - friend auto detail::type_access(const nullptr_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const nullptr_type&); }; class number_type final { public: + using data_ptr = detail::number_type_data*; + number_type() = default; - number_type(detail::number_type_data* data); + number_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -375,14 +397,16 @@ namespace meta_hpp [[nodiscard]] std::size_t get_size() const noexcept; [[nodiscard]] std::size_t get_align() const noexcept; private: - detail::number_type_data* data_{}; - friend auto detail::type_access(const number_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const number_type&); }; class pointer_type final { public: + using data_ptr = detail::pointer_type_data*; + pointer_type() = default; - pointer_type(detail::pointer_type_data* data); + pointer_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -393,14 +417,16 @@ namespace meta_hpp [[nodiscard]] any_type get_data_type() const noexcept; private: - detail::pointer_type_data* data_{}; - friend auto detail::type_access(const pointer_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const pointer_type&); }; class reference_type final { public: + using data_ptr = detail::reference_type_data*; + reference_type() = default; - reference_type(detail::reference_type_data* data); + reference_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -411,14 +437,16 @@ namespace meta_hpp [[nodiscard]] any_type get_data_type() const noexcept; private: - detail::reference_type_data* data_{}; - friend auto detail::type_access(const reference_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const reference_type&); }; class void_type final { public: + using data_ptr = detail::void_type_data*; + void_type() = default; - void_type(detail::void_type_data* data); + void_type(data_ptr data); [[nodiscard]] bool is_valid() const noexcept; [[nodiscard]] explicit operator bool() const noexcept; @@ -426,8 +454,8 @@ namespace meta_hpp [[nodiscard]] type_id get_id() const noexcept; [[nodiscard]] const metadata_map& get_metadata() const noexcept; private: - detail::void_type_data* data_{}; - friend auto detail::type_access(const void_type&); + data_ptr data_{}; + friend data_ptr detail::type_access(const void_type&); }; } diff --git a/headers/meta.hpp/meta_types/array_type.hpp b/headers/meta.hpp/meta_types/array_type.hpp index c4edbeb..709d7aa 100644 --- a/headers/meta.hpp/meta_types/array_type.hpp +++ b/headers/meta.hpp/meta_types/array_type.hpp @@ -27,7 +27,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline array_type::array_type(detail::array_type_data* data) + inline array_type::array_type(data_ptr data) : data_{data} {} inline bool array_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index a5955b8..f67ef39 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -34,7 +34,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline class_type::class_type(detail::class_type_data* data) + inline class_type::class_type(data_ptr data) : data_{data} {} inline bool class_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/constructor_type.hpp b/headers/meta.hpp/meta_types/constructor_type.hpp index 93e15c6..8239de9 100644 --- a/headers/meta.hpp/meta_types/constructor_type.hpp +++ b/headers/meta.hpp/meta_types/constructor_type.hpp @@ -27,7 +27,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline constructor_type::constructor_type(detail::constructor_type_data* data) + inline constructor_type::constructor_type(data_ptr data) : data_{data} {} inline bool constructor_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/destructor_type.hpp b/headers/meta.hpp/meta_types/destructor_type.hpp index 04e953f..df06a1d 100644 --- a/headers/meta.hpp/meta_types/destructor_type.hpp +++ b/headers/meta.hpp/meta_types/destructor_type.hpp @@ -26,7 +26,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline destructor_type::destructor_type(detail::destructor_type_data* data) + inline destructor_type::destructor_type(data_ptr data) : data_{data} {} inline bool destructor_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/enum_type.hpp b/headers/meta.hpp/meta_types/enum_type.hpp index a59cebd..fa3b7f9 100644 --- a/headers/meta.hpp/meta_types/enum_type.hpp +++ b/headers/meta.hpp/meta_types/enum_type.hpp @@ -29,7 +29,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline enum_type::enum_type(detail::enum_type_data* data) + inline enum_type::enum_type(data_ptr data) : data_{data} {} inline bool enum_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/function_type.hpp b/headers/meta.hpp/meta_types/function_type.hpp index 9580e21..a442e18 100644 --- a/headers/meta.hpp/meta_types/function_type.hpp +++ b/headers/meta.hpp/meta_types/function_type.hpp @@ -27,7 +27,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline function_type::function_type(detail::function_type_data* data) + inline function_type::function_type(data_ptr data) : data_{data} {} inline bool function_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/member_type.hpp b/headers/meta.hpp/meta_types/member_type.hpp index 48f41c0..5a3e4d2 100644 --- a/headers/meta.hpp/meta_types/member_type.hpp +++ b/headers/meta.hpp/meta_types/member_type.hpp @@ -27,7 +27,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline member_type::member_type(detail::member_type_data* data) + inline member_type::member_type(data_ptr data) : data_{data} {} inline bool member_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/method_type.hpp b/headers/meta.hpp/meta_types/method_type.hpp index c04acfe..2a2b3fb 100644 --- a/headers/meta.hpp/meta_types/method_type.hpp +++ b/headers/meta.hpp/meta_types/method_type.hpp @@ -28,7 +28,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline method_type::method_type(detail::method_type_data* data) + inline method_type::method_type(data_ptr data) : data_{data} {} inline bool method_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/nullptr_type.hpp b/headers/meta.hpp/meta_types/nullptr_type.hpp index 3107f5f..a2825d6 100644 --- a/headers/meta.hpp/meta_types/nullptr_type.hpp +++ b/headers/meta.hpp/meta_types/nullptr_type.hpp @@ -22,7 +22,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline nullptr_type::nullptr_type(detail::nullptr_type_data* data) + inline nullptr_type::nullptr_type(data_ptr data) : data_{data} {} inline bool nullptr_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/number_type.hpp b/headers/meta.hpp/meta_types/number_type.hpp index 144eb50..b186cbc 100644 --- a/headers/meta.hpp/meta_types/number_type.hpp +++ b/headers/meta.hpp/meta_types/number_type.hpp @@ -27,7 +27,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline number_type::number_type(detail::number_type_data* data) + inline number_type::number_type(data_ptr data) : data_{data} {} inline bool number_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/pointer_type.hpp b/headers/meta.hpp/meta_types/pointer_type.hpp index 41562ca..8ce09db 100644 --- a/headers/meta.hpp/meta_types/pointer_type.hpp +++ b/headers/meta.hpp/meta_types/pointer_type.hpp @@ -26,7 +26,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline pointer_type::pointer_type(detail::pointer_type_data* data) + inline pointer_type::pointer_type(data_ptr data) : data_{data} {} inline bool pointer_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/reference_type.hpp b/headers/meta.hpp/meta_types/reference_type.hpp index 310f67a..8406255 100644 --- a/headers/meta.hpp/meta_types/reference_type.hpp +++ b/headers/meta.hpp/meta_types/reference_type.hpp @@ -26,7 +26,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline reference_type::reference_type(detail::reference_type_data* data) + inline reference_type::reference_type(data_ptr data) : data_{data} {} inline bool reference_type::is_valid() const noexcept { diff --git a/headers/meta.hpp/meta_types/void_type.hpp b/headers/meta.hpp/meta_types/void_type.hpp index 16ea422..9a2000c 100644 --- a/headers/meta.hpp/meta_types/void_type.hpp +++ b/headers/meta.hpp/meta_types/void_type.hpp @@ -22,7 +22,7 @@ namespace meta_hpp::detail namespace meta_hpp { - inline void_type::void_type(detail::void_type_data* data) + inline void_type::void_type(data_ptr data) : data_{data} {} inline bool void_type::is_valid() const noexcept {