From 14b6391490ae40b9201a154b7838eb8a4849065d Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 10 Apr 2022 14:35:40 +0700 Subject: [PATCH] public meta_registry header instead detail using --- .clang-tidy | 2 + CMakeLists.txt | 1 + headers/meta.hpp/meta_all.hpp | 10 +- headers/meta.hpp/meta_binds/array_bind.hpp | 5 +- headers/meta.hpp/meta_binds/class_bind.hpp | 9 +- headers/meta.hpp/meta_binds/enum_bind.hpp | 5 +- headers/meta.hpp/meta_binds/function_bind.hpp | 5 +- headers/meta.hpp/meta_binds/member_bind.hpp | 5 +- headers/meta.hpp/meta_binds/method_bind.hpp | 5 +- headers/meta.hpp/meta_binds/nullptr_bind.hpp | 5 +- headers/meta.hpp/meta_binds/number_bind.hpp | 5 +- headers/meta.hpp/meta_binds/pointer_bind.hpp | 5 +- .../meta.hpp/meta_binds/reference_bind.hpp | 5 +- headers/meta.hpp/meta_binds/scope_bind.hpp | 8 +- headers/meta.hpp/meta_binds/void_bind.hpp | 5 +- .../meta.hpp/meta_detail/state_registry.hpp | 26 ++--- .../meta.hpp/meta_detail/type_registry.hpp | 94 +++---------------- .../meta.hpp/meta_indices/argument_index.hpp | 5 +- .../meta_indices/constructor_index.hpp | 5 +- .../meta_indices/destructor_index.hpp | 5 +- .../meta.hpp/meta_indices/evalue_index.hpp | 5 +- .../meta.hpp/meta_indices/function_index.hpp | 5 +- .../meta.hpp/meta_indices/member_index.hpp | 5 +- .../meta.hpp/meta_indices/method_index.hpp | 5 +- headers/meta.hpp/meta_indices/scope_index.hpp | 3 +- .../meta.hpp/meta_indices/variable_index.hpp | 5 +- headers/meta.hpp/meta_registry.hpp | 85 +++++++++++++++++ headers/meta.hpp/meta_states/scope.hpp | 5 +- headers/meta.hpp/meta_types/array_type.hpp | 2 +- headers/meta.hpp/meta_types/class_type.hpp | 12 +-- .../meta.hpp/meta_types/constructor_type.hpp | 2 +- .../meta.hpp/meta_types/destructor_type.hpp | 2 +- headers/meta.hpp/meta_types/enum_type.hpp | 2 +- headers/meta.hpp/meta_types/function_type.hpp | 2 +- headers/meta.hpp/meta_types/member_type.hpp | 2 +- headers/meta.hpp/meta_types/method_type.hpp | 2 +- headers/meta.hpp/meta_types/nullptr_type.hpp | 1 + headers/meta.hpp/meta_types/number_type.hpp | 1 + headers/meta.hpp/meta_types/pointer_type.hpp | 2 +- .../meta.hpp/meta_types/reference_type.hpp | 2 +- headers/meta.hpp/meta_types/void_type.hpp | 1 + headers/meta.hpp/meta_uvalue/uvalue.hpp | 19 ++-- 42 files changed, 184 insertions(+), 201 deletions(-) create mode 100644 headers/meta.hpp/meta_registry.hpp diff --git a/.clang-tidy b/.clang-tidy index d4c66b5..b4cdaef 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,8 @@ --- Checks: '-*, + bugprone-*, + clang-analyzer-*, concurrency-*, diff --git a/CMakeLists.txt b/CMakeLists.txt index 90f58a0..4724086 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(EnableASan) +include(EnableGCov) include(EnableUBSan) add_subdirectory(manuals) diff --git a/headers/meta.hpp/meta_all.hpp b/headers/meta.hpp/meta_all.hpp index a4aeaa8..070501d 100644 --- a/headers/meta.hpp/meta_all.hpp +++ b/headers/meta.hpp/meta_all.hpp @@ -34,6 +34,8 @@ #include "meta_indices/scope_index.hpp" #include "meta_indices/variable_index.hpp" +#include "meta_registry.hpp" + #include "meta_states.hpp" #include "meta_states/argument.hpp" #include "meta_states/constructor.hpp" @@ -64,11 +66,3 @@ #include "meta_uvalue.hpp" #include "meta_uvalue/invoke.hpp" #include "meta_uvalue/uvalue.hpp" - -namespace meta_hpp -{ - using detail::resolve_type; - using detail::resolve_polymorphic_type; - - using detail::resolve_scope; -} diff --git a/headers/meta.hpp/meta_binds/array_bind.hpp b/headers/meta.hpp/meta_binds/array_bind.hpp index 1985278..bf42683 100644 --- a/headers/meta.hpp/meta_binds/array_bind.hpp +++ b/headers/meta.hpp/meta_binds/array_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::array_kind Array > array_bind::array_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index ec44df0..9fddbd7 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::class_kind Class > class_bind::class_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } @@ -34,7 +33,7 @@ namespace meta_hpp class_bind& class_bind::base_() requires detail::class_bind_base_kind { - const class_type base_type = detail::resolve_type(); + const class_type base_type = resolve_type(); if ( data_->bases.contains(base_type) ) { return *this; } @@ -280,7 +279,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), detail::resolve_type()); + data_->typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } diff --git a/headers/meta.hpp/meta_binds/enum_bind.hpp b/headers/meta.hpp/meta_binds/enum_bind.hpp index d44512b..4c4316a 100644 --- a/headers/meta.hpp/meta_binds/enum_bind.hpp +++ b/headers/meta.hpp/meta_binds/enum_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::enum_kind Enum > enum_bind::enum_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/function_bind.hpp b/headers/meta.hpp/meta_binds/function_bind.hpp index 0c1634e..7453ce0 100644 --- a/headers/meta.hpp/meta_binds/function_bind.hpp +++ b/headers/meta.hpp/meta_binds/function_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::function_kind Function > function_bind::function_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/member_bind.hpp b/headers/meta.hpp/meta_binds/member_bind.hpp index 4bd30d5..d0163b5 100644 --- a/headers/meta.hpp/meta_binds/member_bind.hpp +++ b/headers/meta.hpp/meta_binds/member_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::member_kind Member > member_bind::member_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/method_bind.hpp b/headers/meta.hpp/meta_binds/method_bind.hpp index 05651d1..b1add6f 100644 --- a/headers/meta.hpp/meta_binds/method_bind.hpp +++ b/headers/meta.hpp/meta_binds/method_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::method_kind Method > method_bind::method_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/nullptr_bind.hpp b/headers/meta.hpp/meta_binds/nullptr_bind.hpp index 4b53d3e..2f1c345 100644 --- a/headers/meta.hpp/meta_binds/nullptr_bind.hpp +++ b/headers/meta.hpp/meta_binds/nullptr_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::nullptr_kind Nullptr > nullptr_bind::nullptr_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/number_bind.hpp b/headers/meta.hpp/meta_binds/number_bind.hpp index fff3f19..feeb8a2 100644 --- a/headers/meta.hpp/meta_binds/number_bind.hpp +++ b/headers/meta.hpp/meta_binds/number_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::number_kind Number > number_bind::number_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/pointer_bind.hpp b/headers/meta.hpp/meta_binds/pointer_bind.hpp index 1be0b01..aaf18e8 100644 --- a/headers/meta.hpp/meta_binds/pointer_bind.hpp +++ b/headers/meta.hpp/meta_binds/pointer_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::pointer_kind Pointer > pointer_bind::pointer_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/reference_bind.hpp b/headers/meta.hpp/meta_binds/reference_bind.hpp index 1ed1235..3148c8e 100644 --- a/headers/meta.hpp/meta_binds/reference_bind.hpp +++ b/headers/meta.hpp/meta_binds/reference_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::reference_kind Reference > reference_bind::reference_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index 9e207ba..4db401c 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -8,9 +8,7 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/state_registry.hpp" -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { @@ -20,7 +18,7 @@ namespace meta_hpp // NOLINTNEXTLINE(readability-named-parameter) inline scope_bind::scope_bind(std::string_view name, metadata_map metadata, static_tag) - : state_{detail::state_access(detail::resolve_scope(name))} { + : state_{detail::state_access(resolve_scope(name))} { state_->metadata.swap(metadata); state_->metadata.merge(metadata); } @@ -99,7 +97,7 @@ namespace meta_hpp template < typename Type > scope_bind& scope_bind::typedef_(std::string name) { - state_->typedefs.insert_or_assign(std::move(name), detail::resolve_type()); + state_->typedefs.insert_or_assign(std::move(name), resolve_type()); return *this; } diff --git a/headers/meta.hpp/meta_binds/void_bind.hpp b/headers/meta.hpp/meta_binds/void_bind.hpp index 62fddb4..e2d256e 100644 --- a/headers/meta.hpp/meta_binds/void_bind.hpp +++ b/headers/meta.hpp/meta_binds/void_bind.hpp @@ -8,14 +8,13 @@ #include "../meta_base.hpp" #include "../meta_binds.hpp" - -#include "../meta_detail/type_registry.hpp" +#include "../meta_registry.hpp" namespace meta_hpp { template < detail::void_kind Void > void_bind::void_bind(metadata_map metadata) - : data_{detail::type_access(detail::resolve_type())} { + : data_{detail::type_access(resolve_type())} { data_->metadata.swap(metadata); data_->metadata.merge(metadata); } diff --git a/headers/meta.hpp/meta_detail/state_registry.hpp b/headers/meta.hpp/meta_detail/state_registry.hpp index 0c2a56f..b46e82c 100644 --- a/headers/meta.hpp/meta_detail/state_registry.hpp +++ b/headers/meta.hpp/meta_detail/state_registry.hpp @@ -13,11 +13,19 @@ namespace meta_hpp::detail { class state_registry final { public: + class locker final : noncopyable { + public: + explicit locker() + : lock_{instance().mutex_} {} + private: + std::lock_guard lock_; + }; + [[nodiscard]] static state_registry& instance() { static state_registry instance; return instance; } - + public: [[nodiscard]] scope get_scope_by_name(std::string_view name) const noexcept { const locker lock; @@ -38,14 +46,6 @@ namespace meta_hpp::detail auto state = scope_state::make(std::string{name}, metadata_map{}); return scopes_.insert_or_assign(std::string{name}, std::move(state)).first->second; } - public: - class locker : noncopyable { - public: - explicit locker() - : lock_{instance().mutex_} {} - private: - std::lock_guard lock_; - }; private: state_registry() = default; private: @@ -53,11 +53,3 @@ namespace meta_hpp::detail std::map> scopes_; }; } - -namespace meta_hpp::detail -{ - [[nodiscard]] inline scope resolve_scope(std::string_view name) { - state_registry& registry = state_registry::instance(); - return registry.resolve_scope(name); - } -} diff --git a/headers/meta.hpp/meta_detail/type_registry.hpp b/headers/meta.hpp/meta_detail/type_registry.hpp index 7002b87..363e60e 100644 --- a/headers/meta.hpp/meta_detail/type_registry.hpp +++ b/headers/meta.hpp/meta_detail/type_registry.hpp @@ -13,11 +13,19 @@ namespace meta_hpp::detail { class type_registry final { public: + class locker final : noncopyable { + public: + explicit locker() + : lock_{instance().mutex_} {} + private: + std::lock_guard lock_; + }; + [[nodiscard]] static type_registry& instance() { static type_registry instance; return instance; } - + public: [[nodiscard]] any_type get_type_by_id(type_id id) const noexcept { const locker lock; @@ -37,11 +45,7 @@ namespace meta_hpp::detail return any_type{}; } - - // - // - // - + public: template < array_kind Array > [[nodiscard]] array_type resolve_type() { return resolve_array_type(); } @@ -74,11 +78,7 @@ namespace meta_hpp::detail template < void_kind Void > [[nodiscard]] void_type resolve_type() { return resolve_void_type(); } - - // - // - // - + public: template < array_kind Array > [[nodiscard]] array_type resolve_array_type() { return array_type{resolve_array_type_data()}; } @@ -117,11 +117,7 @@ namespace meta_hpp::detail template < void_kind Void > [[nodiscard]] void_type resolve_void_type() { return void_type{resolve_void_type_data()}; } - - // - // - // - + private: template < array_kind Array > [[nodiscard]] array_type_data* resolve_array_type_data() { static array_type_data data{type_list{}}; @@ -210,14 +206,6 @@ namespace meta_hpp::detail ensure_type(data); return &data; } - public: - class locker : noncopyable { - public: - explicit locker() - : lock_{instance().mutex_} {} - private: - std::lock_guard lock_; - }; private: type_registry() = default; @@ -238,61 +226,3 @@ namespace meta_hpp::detail std::map> type_by_rtti_; }; } - -namespace meta_hpp::detail -{ - template < typename T > - [[nodiscard]] auto resolve_type() { - type_registry& registry = type_registry::instance(); - return registry.resolve_type>(); - } - - template < typename... Ts > - [[nodiscard]] std::vector resolve_types() { - return { resolve_type()... }; - } -} - -namespace meta_hpp::detail -{ - template < class_kind Class, typename... Args > - constructor_type resolve_constructor_type() { - type_registry& registry = type_registry::instance(); - return registry.resolve_constructor_type(); - } - - template < class_kind Class > - destructor_type resolve_destructor_type() { - type_registry& registry = type_registry::instance(); - return registry.resolve_destructor_type(); - } -} - -namespace meta_hpp::detail -{ - template < typename T > - // NOLINTNEXTLINE(readability-named-parameter) - [[nodiscard]] auto resolve_type(T&&) { - return resolve_type>(); - } - - template < typename... Ts > - // NOLINTNEXTLINE(readability-named-parameter) - [[nodiscard]] std::vector resolve_types(type_list) { - return { resolve_type()... }; - } -} - -namespace meta_hpp::detail -{ - template < typename T > - [[nodiscard]] any_type resolve_polymorphic_type(T&& v) noexcept { - #ifndef META_HPP_NO_RTTI - type_registry& registry = type_registry::instance(); - return registry.get_type_by_rtti(typeid(v)); - #else - (void)v; - return any_type{}; - #endif - } -} diff --git a/headers/meta.hpp/meta_indices/argument_index.hpp b/headers/meta.hpp/meta_indices/argument_index.hpp index 6cf8d75..21f11b6 100644 --- a/headers/meta.hpp/meta_indices/argument_index.hpp +++ b/headers/meta.hpp/meta_indices/argument_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline argument_index::argument_index(any_type type, std::size_t position) @@ -20,7 +19,7 @@ namespace meta_hpp template < typename Argument > inline argument_index argument_index::make(std::size_t position) { - return argument_index{detail::resolve_type(), position}; + return argument_index{resolve_type(), position}; } inline std::size_t argument_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/constructor_index.hpp b/headers/meta.hpp/meta_indices/constructor_index.hpp index 1aefb28..0222dc9 100644 --- a/headers/meta.hpp/meta_indices/constructor_index.hpp +++ b/headers/meta.hpp/meta_indices/constructor_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline constructor_index::constructor_index(constructor_type type) @@ -19,7 +18,7 @@ namespace meta_hpp template < detail::class_kind Class, typename... Args > constructor_index constructor_index::make() { - return constructor_index{detail::resolve_constructor_type()}; + return constructor_index{resolve_constructor_type()}; } inline std::size_t constructor_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/destructor_index.hpp b/headers/meta.hpp/meta_indices/destructor_index.hpp index c1af272..3dc80e8 100644 --- a/headers/meta.hpp/meta_indices/destructor_index.hpp +++ b/headers/meta.hpp/meta_indices/destructor_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline destructor_index::destructor_index(destructor_type type) @@ -19,7 +18,7 @@ namespace meta_hpp template < detail::class_kind Class > destructor_index destructor_index::make() { - return destructor_index{detail::resolve_destructor_type()}; + return destructor_index{resolve_destructor_type()}; } inline std::size_t destructor_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/evalue_index.hpp b/headers/meta.hpp/meta_indices/evalue_index.hpp index d3122d2..ec9032d 100644 --- a/headers/meta.hpp/meta_indices/evalue_index.hpp +++ b/headers/meta.hpp/meta_indices/evalue_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline evalue_index::evalue_index(enum_type type, std::string name) @@ -20,7 +19,7 @@ namespace meta_hpp template < detail::enum_kind Enum > evalue_index evalue_index::make(std::string name) { - return evalue_index{detail::resolve_type(), std::move(name)}; + return evalue_index{resolve_type(), std::move(name)}; } inline std::size_t evalue_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/function_index.hpp b/headers/meta.hpp/meta_indices/function_index.hpp index 19c0bed..d910900 100644 --- a/headers/meta.hpp/meta_indices/function_index.hpp +++ b/headers/meta.hpp/meta_indices/function_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline function_index::function_index(function_type type, std::string name) @@ -20,7 +19,7 @@ namespace meta_hpp template < detail::function_kind Function > function_index function_index::make(std::string name) { - return function_index{detail::resolve_type(), std::move(name)}; + return function_index{resolve_type(), std::move(name)}; } inline std::size_t function_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/member_index.hpp b/headers/meta.hpp/meta_indices/member_index.hpp index cf5a9d0..d12e569 100644 --- a/headers/meta.hpp/meta_indices/member_index.hpp +++ b/headers/meta.hpp/meta_indices/member_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline member_index::member_index(member_type type, std::string name) @@ -20,7 +19,7 @@ namespace meta_hpp template < detail::member_kind Member > member_index member_index::make(std::string name) { - return member_index{detail::resolve_type(), std::move(name)}; + return member_index{resolve_type(), std::move(name)}; } inline std::size_t member_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/method_index.hpp b/headers/meta.hpp/meta_indices/method_index.hpp index 02d1e61..5cf670a 100644 --- a/headers/meta.hpp/meta_indices/method_index.hpp +++ b/headers/meta.hpp/meta_indices/method_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline method_index::method_index(method_type type, std::string name) @@ -20,7 +19,7 @@ namespace meta_hpp template < detail::method_kind Method > method_index method_index::make(std::string name) { - return method_index{detail::resolve_type(), std::move(name)}; + return method_index{resolve_type(), std::move(name)}; } inline std::size_t method_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_indices/scope_index.hpp b/headers/meta.hpp/meta_indices/scope_index.hpp index 8f7bb5c..a93c2d4 100644 --- a/headers/meta.hpp/meta_indices/scope_index.hpp +++ b/headers/meta.hpp/meta_indices/scope_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_states.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline scope_index::scope_index(std::string name) diff --git a/headers/meta.hpp/meta_indices/variable_index.hpp b/headers/meta.hpp/meta_indices/variable_index.hpp index 11e41fa..96f7cf0 100644 --- a/headers/meta.hpp/meta_indices/variable_index.hpp +++ b/headers/meta.hpp/meta_indices/variable_index.hpp @@ -8,10 +8,9 @@ #include "../meta_base.hpp" #include "../meta_indices.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { inline variable_index::variable_index(pointer_type type, std::string name) @@ -20,7 +19,7 @@ namespace meta_hpp template < detail::pointer_kind Pointer > variable_index variable_index::make(std::string name) { - return variable_index{detail::resolve_type(), std::move(name)}; + return variable_index{resolve_type(), std::move(name)}; } inline std::size_t variable_index::get_hash() const noexcept { diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp new file mode 100644 index 0000000..882748f --- /dev/null +++ b/headers/meta.hpp/meta_registry.hpp @@ -0,0 +1,85 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/meta.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2021-2022, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#pragma once + +#include "meta_base.hpp" +#include "meta_states.hpp" +#include "meta_types.hpp" + +#include "meta_detail/state_registry.hpp" +#include "meta_detail/type_registry.hpp" + +namespace meta_hpp +{ + template < typename T > + [[nodiscard]] auto resolve_type() { + using namespace detail; + type_registry& registry = type_registry::instance(); + return registry.resolve_type>(); + } + + template < typename... Ts > + [[nodiscard]] std::vector resolve_types() { + return { resolve_type()... }; + } +} + +namespace meta_hpp +{ + template < typename T > + // NOLINTNEXTLINE(readability-named-parameter) + [[nodiscard]] auto resolve_type(T&&) { + return resolve_type>(); + } + + template < typename... Ts > + // NOLINTNEXTLINE(readability-named-parameter) + [[nodiscard]] std::vector resolve_types(type_list) { + return { resolve_type()... }; + } +} + +namespace meta_hpp +{ + template < detail::class_kind Class, typename... Args > + constructor_type resolve_constructor_type() { + using namespace detail; + type_registry& registry = type_registry::instance(); + return registry.resolve_constructor_type(); + } + + template < detail::class_kind Class > + destructor_type resolve_destructor_type() { + using namespace detail; + type_registry& registry = type_registry::instance(); + return registry.resolve_destructor_type(); + } +} + +namespace meta_hpp +{ + template < typename T > + [[nodiscard]] any_type resolve_polymorphic_type(T&& v) noexcept { + #ifndef META_HPP_NO_RTTI + using namespace detail; + type_registry& registry = type_registry::instance(); + return registry.get_type_by_rtti(typeid(v)); + #else + (void)v; + return any_type{}; + #endif + } +} + +namespace meta_hpp +{ + [[nodiscard]] inline scope resolve_scope(std::string_view name) { + using namespace detail; + state_registry& registry = state_registry::instance(); + return registry.resolve_scope(name); + } +} diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index 5b95a37..6a66b0a 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -7,6 +7,7 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_states.hpp" #include "../meta_types.hpp" @@ -16,8 +17,6 @@ #include "../meta_states/function.hpp" #include "../meta_states/variable.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp::detail { inline scope_state_ptr scope_state::make(std::string name, metadata_map metadata) { @@ -99,7 +98,7 @@ namespace meta_hpp template < typename... Args > function scope::get_function_with(std::string_view name) const noexcept { - return get_function_with(name, {detail::resolve_type()...}); + return get_function_with(name, {resolve_type()...}); } template < typename Iter > diff --git a/headers/meta.hpp/meta_types/array_type.hpp b/headers/meta.hpp/meta_types/array_type.hpp index 883c4a2..d7e5f1d 100644 --- a/headers/meta.hpp/meta_types/array_type.hpp +++ b/headers/meta.hpp/meta_types/array_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/array_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index a816048..8af64f5 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -7,6 +7,7 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" #include "../meta_states/constructor.hpp" @@ -15,7 +16,6 @@ #include "../meta_states/method.hpp" #include "../meta_states/variable.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/class_traits.hpp" namespace meta_hpp::detail @@ -133,7 +133,7 @@ namespace meta_hpp template < detail::class_kind Derived > bool class_type::is_base_of() const noexcept { - return is_base_of(detail::resolve_type()); + return is_base_of(resolve_type()); } inline bool class_type::is_base_of(const class_type& derived) const noexcept { @@ -156,7 +156,7 @@ namespace meta_hpp template < detail::class_kind Base > bool class_type::is_derived_from() const noexcept { - return is_derived_from(detail::resolve_type()); + return is_derived_from(resolve_type()); } inline bool class_type::is_derived_from(const class_type& base) const noexcept { @@ -263,7 +263,7 @@ namespace meta_hpp template < typename... Args > constructor class_type::get_constructor_with() const noexcept { - return get_constructor_with({detail::resolve_type()...}); + return get_constructor_with({resolve_type()...}); } template < typename Iter > @@ -291,7 +291,7 @@ namespace meta_hpp template < typename... Args > function class_type::get_function_with(std::string_view name) const noexcept { - return get_function_with(name, {detail::resolve_type()...}); + return get_function_with(name, {resolve_type()...}); } template < typename Iter > @@ -330,7 +330,7 @@ namespace meta_hpp template < typename... Args > method class_type::get_method_with(std::string_view name) const noexcept { - return get_method_with(name, {detail::resolve_type()...}); + return get_method_with(name, {resolve_type()...}); } template < typename Iter > diff --git a/headers/meta.hpp/meta_types/constructor_type.hpp b/headers/meta.hpp/meta_types/constructor_type.hpp index bf5d47a..2da9e7b 100644 --- a/headers/meta.hpp/meta_types/constructor_type.hpp +++ b/headers/meta.hpp/meta_types/constructor_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/constructor_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/destructor_type.hpp b/headers/meta.hpp/meta_types/destructor_type.hpp index 51b1464..5a0b510 100644 --- a/headers/meta.hpp/meta_types/destructor_type.hpp +++ b/headers/meta.hpp/meta_types/destructor_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/destructor_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/enum_type.hpp b/headers/meta.hpp/meta_types/enum_type.hpp index b7d44f2..818064a 100644 --- a/headers/meta.hpp/meta_types/enum_type.hpp +++ b/headers/meta.hpp/meta_types/enum_type.hpp @@ -7,11 +7,11 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" #include "../meta_states/evalue.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/enum_traits.hpp" #include "../meta_detail/value_utilities/uarg.hpp" diff --git a/headers/meta.hpp/meta_types/function_type.hpp b/headers/meta.hpp/meta_types/function_type.hpp index b5d5a32..b4bcbe2 100644 --- a/headers/meta.hpp/meta_types/function_type.hpp +++ b/headers/meta.hpp/meta_types/function_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/function_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/member_type.hpp b/headers/meta.hpp/meta_types/member_type.hpp index a8c64db..06b706c 100644 --- a/headers/meta.hpp/meta_types/member_type.hpp +++ b/headers/meta.hpp/meta_types/member_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/member_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/method_type.hpp b/headers/meta.hpp/meta_types/method_type.hpp index e092712..a9d86c7 100644 --- a/headers/meta.hpp/meta_types/method_type.hpp +++ b/headers/meta.hpp/meta_types/method_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/method_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/nullptr_type.hpp b/headers/meta.hpp/meta_types/nullptr_type.hpp index 4646a00..a2c7ddd 100644 --- a/headers/meta.hpp/meta_types/nullptr_type.hpp +++ b/headers/meta.hpp/meta_types/nullptr_type.hpp @@ -7,6 +7,7 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/number_type.hpp b/headers/meta.hpp/meta_types/number_type.hpp index 4a8fa30..cbb5934 100644 --- a/headers/meta.hpp/meta_types/number_type.hpp +++ b/headers/meta.hpp/meta_types/number_type.hpp @@ -7,6 +7,7 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" #include "../meta_detail/type_traits/number_traits.hpp" diff --git a/headers/meta.hpp/meta_types/pointer_type.hpp b/headers/meta.hpp/meta_types/pointer_type.hpp index ab5b889..4964f6b 100644 --- a/headers/meta.hpp/meta_types/pointer_type.hpp +++ b/headers/meta.hpp/meta_types/pointer_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/pointer_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/reference_type.hpp b/headers/meta.hpp/meta_types/reference_type.hpp index 41a7bd2..60fd331 100644 --- a/headers/meta.hpp/meta_types/reference_type.hpp +++ b/headers/meta.hpp/meta_types/reference_type.hpp @@ -7,9 +7,9 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" -#include "../meta_detail/type_registry.hpp" #include "../meta_detail/type_traits/reference_traits.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_types/void_type.hpp b/headers/meta.hpp/meta_types/void_type.hpp index 4b0b70f..859ca4e 100644 --- a/headers/meta.hpp/meta_types/void_type.hpp +++ b/headers/meta.hpp/meta_types/void_type.hpp @@ -7,6 +7,7 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_types.hpp" namespace meta_hpp::detail diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 8b14a85..a2c7b9a 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -7,6 +7,7 @@ #pragma once #include "../meta_base.hpp" +#include "../meta_registry.hpp" #include "../meta_uvalue.hpp" #include "../meta_detail/value_traits/deref_traits.hpp" @@ -16,8 +17,6 @@ #include "../meta_detail/value_traits/less_traits.hpp" #include "../meta_detail/value_traits/ostream_traits.hpp" -#include "../meta_detail/type_registry.hpp" - namespace meta_hpp { struct uvalue::vtable_t final { @@ -118,7 +117,7 @@ namespace meta_hpp // NOLINTNEXTLINE(readability-function-cognitive-complexity) static vtable_t* get() { static vtable_t table{ - .type = detail::resolve_type(), + .type = resolve_type(), .data = [](storage_u& from) noexcept -> void* { return storage_cast(from); @@ -302,7 +301,7 @@ namespace meta_hpp } inline const any_type& uvalue::get_type() const noexcept { - static any_type void_type = detail::resolve_type(); + static any_type void_type = resolve_type(); return vtable_ != nullptr ? vtable_->type : void_type; } @@ -365,7 +364,7 @@ namespace meta_hpp template < typename T > std::decay_t* uvalue::try_cast() noexcept { using Tp = std::decay_t; - return get_type() == detail::resolve_type() + return get_type() == resolve_type() ? vtable_t::storage_cast(storage_) : nullptr; } @@ -373,7 +372,7 @@ namespace meta_hpp template < typename T > const std::decay_t* uvalue::try_cast() const noexcept { using Tp = std::decay_t; - return get_type() == detail::resolve_type() + return get_type() == resolve_type() ? vtable_t::storage_cast(storage_) : nullptr; } @@ -388,7 +387,7 @@ namespace meta_hpp } const any_type& l_type = l.get_type(); - const any_type& r_type = detail::resolve_type(); + const any_type& r_type = resolve_type(); return (l_type < r_type) || (l_type == r_type && l.cast() < r); } @@ -399,7 +398,7 @@ namespace meta_hpp return false; } - const any_type& l_type = detail::resolve_type(); + const any_type& l_type = resolve_type(); const any_type& r_type = r.get_type(); return (l_type < r_type) || (l_type == r_type && l < r.cast()); @@ -430,7 +429,7 @@ namespace meta_hpp } const any_type& l_type = l.get_type(); - const any_type& r_type = detail::resolve_type(); + const any_type& r_type = resolve_type(); return l_type == r_type && l.cast() == r; } @@ -441,7 +440,7 @@ namespace meta_hpp return false; } - const any_type& l_type = detail::resolve_type(); + const any_type& l_type = resolve_type(); const any_type& r_type = r.get_type(); return l_type == r_type && l == r.cast();