diff --git a/headers/meta.hpp/meta_base.hpp b/headers/meta.hpp/meta_base.hpp index a0b294a..258ac8c 100644 --- a/headers/meta.hpp/meta_base.hpp +++ b/headers/meta.hpp/meta_base.hpp @@ -205,6 +205,7 @@ namespace meta_hpp { using argument_list = std::vector; using metadata_map = std::map>; + using typedef_map = std::map>; using class_set = std::set>; using class_map = std::map>; diff --git a/headers/meta.hpp/meta_binds.hpp b/headers/meta.hpp/meta_binds.hpp index 15bb5af..560f263 100644 --- a/headers/meta.hpp/meta_binds.hpp +++ b/headers/meta.hpp/meta_binds.hpp @@ -100,11 +100,6 @@ namespace meta_hpp explicit class_bind(metadata_map metadata); operator class_type() const noexcept; - // class_ - - template < detail::class_kind InternalClass > - class_bind& class_(std::string name); - // base_ template < detail::class_kind Base > @@ -131,11 +126,6 @@ namespace meta_hpp class_bind& destructor_(destructor_opts opts) requires detail::class_bind_destructor_kind; - // enum_ - - template < detail::enum_kind InternalEnum > - class_bind& enum_(std::string name); - // function_ template < detail::function_kind Function @@ -208,6 +198,11 @@ namespace meta_hpp Policy = Policy{}) requires detail::class_bind_method_kind; + // typdef_ + + template < typename Type > + class_bind& typedef_(std::string name); + // variable_ template < detail::pointer_kind Pointer @@ -361,12 +356,6 @@ namespace meta_hpp explicit scope_bind(std::string_view name, metadata_map metadata, static_tag); operator scope() const noexcept; - template < detail::class_kind Class > - scope_bind& class_(std::string name); - - template < detail::enum_kind Enum > - scope_bind& enum_(std::string name); - // function_ template < detail::function_kind Function @@ -392,6 +381,11 @@ namespace meta_hpp std::initializer_list arguments, Policy = Policy{}); + // typedef_ + + template < typename Type > + scope_bind& typedef_(std::string name); + // variable_ template < detail::pointer_kind Pointer diff --git a/headers/meta.hpp/meta_binds/class_bind.hpp b/headers/meta.hpp/meta_binds/class_bind.hpp index 29ae9ba..ec44df0 100644 --- a/headers/meta.hpp/meta_binds/class_bind.hpp +++ b/headers/meta.hpp/meta_binds/class_bind.hpp @@ -25,15 +25,6 @@ namespace meta_hpp return class_type{data_}; } - // class_ - - template < detail::class_kind Class > - template < detail::class_kind InternalClass > - class_bind& class_bind::class_(std::string name) { - data_->classes.insert_or_assign(std::move(name), detail::resolve_type()); - return *this; - } - // // base_ // @@ -113,17 +104,6 @@ namespace meta_hpp return *this; } - // - // enum_ - // - - template < detail::class_kind Class > - template < detail::enum_kind InternalEnum > - class_bind& class_bind::enum_(std::string name) { - data_->enums.insert_or_assign(std::move(name), detail::resolve_type()); - return *this; - } - // // function_ // @@ -293,6 +273,17 @@ namespace meta_hpp return *this; } + // + // typedef_ + // + + 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()); + return *this; + } + // // variable_ // diff --git a/headers/meta.hpp/meta_binds/scope_bind.hpp b/headers/meta.hpp/meta_binds/scope_bind.hpp index d5d6a2b..9e207ba 100644 --- a/headers/meta.hpp/meta_binds/scope_bind.hpp +++ b/headers/meta.hpp/meta_binds/scope_bind.hpp @@ -29,26 +29,6 @@ namespace meta_hpp return scope{state_}; } - // - // class_ - // - - template < detail::class_kind Class > - scope_bind& scope_bind::class_(std::string name) { - state_->classes.insert_or_assign(std::move(name), detail::resolve_type()); - return *this; - } - - // - // enum_ - // - - template < detail::enum_kind Enum > - scope_bind& scope_bind::enum_(std::string name) { - state_->enums.insert_or_assign(std::move(name), detail::resolve_type()); - return *this; - } - // // function_ // @@ -113,6 +93,16 @@ namespace meta_hpp return *this; } + // + // typedef_ + // + + template < typename Type > + scope_bind& scope_bind::typedef_(std::string name) { + state_->typedefs.insert_or_assign(std::move(name), detail::resolve_type()); + return *this; + } + // // variable_ // diff --git a/headers/meta.hpp/meta_states.hpp b/headers/meta.hpp/meta_states.hpp index a19196b..8926119 100644 --- a/headers/meta.hpp/meta_states.hpp +++ b/headers/meta.hpp/meta_states.hpp @@ -329,14 +329,12 @@ namespace meta_hpp [[nodiscard]] const std::string& get_name() const noexcept; - [[nodiscard]] const class_map& get_classes() const noexcept; - [[nodiscard]] const enum_map& get_enums() const noexcept; [[nodiscard]] const function_map& get_functions() const noexcept; + [[nodiscard]] const typedef_map& get_typedefs() const noexcept; [[nodiscard]] const variable_map& get_variables() const noexcept; - [[nodiscard]] class_type get_class(std::string_view name) const noexcept; - [[nodiscard]] enum_type get_enum(std::string_view name) const noexcept; [[nodiscard]] function get_function(std::string_view name) const noexcept; + [[nodiscard]] any_type get_typedef(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name) const noexcept; template < typename... Args > @@ -529,9 +527,8 @@ namespace meta_hpp::detail scope_index index; metadata_map metadata; - class_map classes{}; - enum_map enums{}; function_map functions{}; + typedef_map typedefs{}; variable_map variables{}; [[nodiscard]] static scope_state_ptr make(std::string name, metadata_map metadata); diff --git a/headers/meta.hpp/meta_states/scope.hpp b/headers/meta.hpp/meta_states/scope.hpp index 24ae2f6..5b95a37 100644 --- a/headers/meta.hpp/meta_states/scope.hpp +++ b/headers/meta.hpp/meta_states/scope.hpp @@ -58,36 +58,18 @@ namespace meta_hpp return state_->index.get_name(); } - inline const class_map& scope::get_classes() const noexcept { - return state_->classes; - } - - inline const enum_map& scope::get_enums() const noexcept { - return state_->enums; - } - inline const function_map& scope::get_functions() const noexcept { return state_->functions; } + inline const typedef_map& scope::get_typedefs() const noexcept { + return state_->typedefs; + } + inline const variable_map& scope::get_variables() const noexcept { return state_->variables; } - inline class_type scope::get_class(std::string_view name) const noexcept { - if ( auto iter = state_->classes.find(name); iter != state_->classes.end() ) { - return iter->second; - } - return class_type{}; - } - - inline enum_type scope::get_enum(std::string_view name) const noexcept { - if ( auto iter = state_->enums.find(name); iter != state_->enums.end() ) { - return iter->second; - } - return enum_type{}; - } - inline function scope::get_function(std::string_view name) const noexcept { for ( auto&& [index, function] : state_->functions ) { if ( index.get_name() == name ) { @@ -97,6 +79,15 @@ namespace meta_hpp return function{}; } + inline any_type scope::get_typedef(std::string_view name) const noexcept { + for ( auto&& [index, type] : state_->typedefs ) { + if ( index == name ) { + return type; + } + } + return any_type{}; + } + inline variable scope::get_variable(std::string_view name) const noexcept { for ( auto&& [index, variable] : state_->variables ) { if ( index.get_name() == name ) { diff --git a/headers/meta.hpp/meta_types.hpp b/headers/meta.hpp/meta_types.hpp index d2260ce..3b8c620 100644 --- a/headers/meta.hpp/meta_types.hpp +++ b/headers/meta.hpp/meta_types.hpp @@ -155,14 +155,13 @@ namespace meta_hpp [[nodiscard]] any_type get_argument_type(std::size_t position) const noexcept; [[nodiscard]] const std::vector& get_argument_types() const noexcept; - [[nodiscard]] const class_map& get_classes() const noexcept; [[nodiscard]] const class_set& get_bases() const noexcept; [[nodiscard]] const constructor_map& get_ctors() const noexcept; [[nodiscard]] const destructor_map& get_dtors() const noexcept; - [[nodiscard]] const enum_map& get_enums() const noexcept; [[nodiscard]] const function_map& get_functions() const noexcept; [[nodiscard]] const member_map& get_members() const noexcept; [[nodiscard]] const method_map& get_methods() const noexcept; + [[nodiscard]] const typedef_map& get_typedefs() const noexcept; [[nodiscard]] const variable_map& get_variables() const noexcept; template < typename... Args > @@ -182,11 +181,10 @@ namespace meta_hpp [[nodiscard]] bool is_derived_from() const noexcept; [[nodiscard]] bool is_derived_from(const class_type& base) const noexcept; - [[nodiscard]] class_type get_class(std::string_view name) const noexcept; - [[nodiscard]] enum_type get_enum(std::string_view name) const noexcept; [[nodiscard]] function get_function(std::string_view name) const noexcept; [[nodiscard]] member get_member(std::string_view name) const noexcept; [[nodiscard]] method get_method(std::string_view name) const noexcept; + [[nodiscard]] any_type get_typedef(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name) const noexcept; template < typename... Args > @@ -487,14 +485,13 @@ namespace meta_hpp::detail const std::size_t size; const std::vector argument_types; - class_map classes; class_set bases; constructor_map constructors; destructor_map destructors; - enum_map enums; function_map functions; member_map members; method_map methods; + typedef_map typedefs; variable_map variables; struct base_info final { diff --git a/headers/meta.hpp/meta_types/class_type.hpp b/headers/meta.hpp/meta_types/class_type.hpp index 8b46b1d..c46466d 100644 --- a/headers/meta.hpp/meta_types/class_type.hpp +++ b/headers/meta.hpp/meta_types/class_type.hpp @@ -73,10 +73,6 @@ namespace meta_hpp return data_->argument_types; } - inline const class_map& class_type::get_classes() const noexcept { - return data_->classes; - } - inline const class_set& class_type::get_bases() const noexcept { return data_->bases; } @@ -89,10 +85,6 @@ namespace meta_hpp return data_->destructors; } - inline const enum_map& class_type::get_enums() const noexcept { - return data_->enums; - } - inline const function_map& class_type::get_functions() const noexcept { return data_->functions; } @@ -105,6 +97,10 @@ namespace meta_hpp return data_->methods; } + inline const typedef_map& class_type::get_typedefs() const noexcept { + return data_->typedefs; + } + inline const variable_map& class_type::get_variables() const noexcept { return data_->variables; } @@ -181,20 +177,6 @@ namespace meta_hpp return false; } - inline class_type class_type::get_class(std::string_view name) const noexcept { - if ( auto iter = data_->classes.find(name); iter != data_->classes.end() ) { - return iter->second; - } - return class_type{}; - } - - inline enum_type class_type::get_enum(std::string_view name) const noexcept { - if ( auto iter = data_->enums.find(name); iter != data_->enums.end() ) { - return iter->second; - } - return enum_type{}; - } - inline function class_type::get_function(std::string_view name) const noexcept { for ( auto&& [index, function] : data_->functions ) { if ( index.get_name() == name ) { @@ -243,6 +225,22 @@ namespace meta_hpp return method{}; } + inline any_type class_type::get_typedef(std::string_view name) const noexcept { + for ( auto&& [index, type] : data_->typedefs ) { + if ( index == name ) { + return type; + } + } + + for ( auto&& base : data_->bases ) { + if ( any_type type = base.get_typedef(name); type ) { + return type; + } + } + + return any_type{}; + } + inline variable class_type::get_variable(std::string_view name) const noexcept { for ( auto&& [index, variable] : data_->variables ) { if ( index.get_name() == name ) { diff --git a/manuals/meta_examples/classes_example.cpp b/manuals/meta_examples/classes_example.cpp index bdf38e9..e258d93 100644 --- a/manuals/meta_examples/classes_example.cpp +++ b/manuals/meta_examples/classes_example.cpp @@ -10,7 +10,10 @@ namespace { class shape { public: + shape() = default; + shape(const shape&) = default; virtual ~shape() = default; + virtual int get_area() const = 0; }; diff --git a/manuals/meta_manuals.hpp b/manuals/meta_manuals.hpp index 245c449..d135216 100644 --- a/manuals/meta_manuals.hpp +++ b/manuals/meta_manuals.hpp @@ -11,6 +11,7 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wc++20-compat" #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +#pragma clang diagnostic ignored "-Wreserved-identifier" #pragma clang diagnostic ignored "-Wsigned-enum-bitfield" #pragma clang diagnostic ignored "-Wswitch-enum" #pragma clang diagnostic ignored "-Wundefined-func-template" diff --git a/untests/meta_states/scope_tests.cpp b/untests/meta_states/scope_tests.cpp index aa76c47..6aecd6b 100644 --- a/untests/meta_states/scope_tests.cpp +++ b/untests/meta_states/scope_tests.cpp @@ -41,9 +41,9 @@ TEST_CASE("meta/meta_states/scope") { namespace meta = meta_hpp; meta::static_scope_("meta/meta_states/scope/math") - .enum_("color") - .class_("ivec2") - .class_("ivec3") + .typedef_("color") + .typedef_("ivec2") + .typedef_("ivec3") .function_("iadd2", &iadd2, {"l", "r"}) .function_("iadd3", &iadd3, {"l"}) .variable_("static_ivec2", &static_ivec2) @@ -54,10 +54,8 @@ TEST_CASE("meta/meta_states/scope") { REQUIRE(math_scope.is_valid()); CHECK(math_scope.get_name() == "meta/meta_states/scope/math"); - CHECK(math_scope.get_classes().size() == 2); - CHECK(math_scope.get_enums().size() == 1); - CHECK(math_scope.get_functions().size() == 2); CHECK(math_scope.get_variables().size() == 2); + CHECK(math_scope.get_typedefs().size() == 3); SUBCASE("") { const meta::scope scope; @@ -74,20 +72,20 @@ TEST_CASE("meta/meta_states/scope") { } SUBCASE("classes") { - CHECK_FALSE(math_scope.get_class("non-existent-class")); + CHECK_FALSE(math_scope.get_typedef("non-existent-class")); - const meta::class_type ivec2_type = math_scope.get_class("ivec2"); - REQUIRE(ivec2_type); + const meta::any_type ivec2_type = math_scope.get_typedef("ivec2"); + CHECK(ivec2_type == meta::resolve_type()); - const meta::class_type ivec3_type = math_scope.get_class("ivec3"); - REQUIRE(ivec3_type); + const meta::any_type ivec3_type = math_scope.get_typedef("ivec3"); + CHECK(ivec3_type == meta::resolve_type()); } SUBCASE("enums") { - CHECK_FALSE(math_scope.get_enum("non-existent-enum")); + CHECK_FALSE(math_scope.get_typedef("non-existent-enum")); - const meta::enum_type color_type = math_scope.get_enum("color"); - REQUIRE(color_type); + const meta::any_type color_type = math_scope.get_typedef("color"); + CHECK(color_type == meta::resolve_type()); } SUBCASE("functions") { diff --git a/untests/meta_types/class_type2_tests.cpp b/untests/meta_types/class_type2_tests.cpp index f4870c1..1c5dc8a 100644 --- a/untests/meta_types/class_type2_tests.cpp +++ b/untests/meta_types/class_type2_tests.cpp @@ -18,20 +18,17 @@ TEST_CASE("meta/meta_types/class_type2") { namespace meta = meta_hpp; meta::class_() - .class_("internal_clazz") - .enum_("internal_enum"); + .typedef_("internal_clazz") + .typedef_("internal_enum"); const meta::class_type clazz_type = meta::resolve_type(); REQUIRE(clazz_type); - CHECK(clazz_type.get_class("internal_clazz") == meta::resolve_type()); - CHECK(clazz_type.get_enum("internal_enum") == meta::resolve_type()); + CHECK(clazz_type.get_typedef("internal_clazz") == meta::resolve_type()); + CHECK(clazz_type.get_typedef("internal_enum") == meta::resolve_type()); - CHECK(clazz_type.get_classes() == meta::class_map{ - {"internal_clazz", meta::resolve_type()} - }); - - CHECK(clazz_type.get_enums() == meta::enum_map{ - {"internal_enum", meta::resolve_type()} + CHECK(clazz_type.get_typedefs() == meta::typedef_map{ + {"internal_clazz", meta::resolve_type()}, + {"internal_enum", meta::resolve_type()}, }); }