add recursively flag to get_xxx class type functions

This commit is contained in:
BlackMATov
2023-03-06 22:49:50 +07:00
parent 424b6f6736
commit 139f075d77
6 changed files with 360 additions and 130 deletions

View File

@@ -2616,11 +2616,11 @@ namespace meta_hpp
[[nodiscard]] bool is_virtual_derived_from() const noexcept; [[nodiscard]] bool is_virtual_derived_from() const noexcept;
[[nodiscard]] bool is_virtual_derived_from(const class_type& base) const noexcept; [[nodiscard]] bool is_virtual_derived_from(const class_type& base) const noexcept;
[[nodiscard]] function get_function(std::string_view name) const noexcept; [[nodiscard]] function get_function(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] member get_member(std::string_view name) const noexcept; [[nodiscard]] member get_member(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] method get_method(std::string_view name) const noexcept; [[nodiscard]] method get_method(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] any_type get_typedef(std::string_view name) const noexcept; [[nodiscard]] any_type get_typedef(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] variable get_variable(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name, bool recursively = true) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] constructor get_constructor_with() const noexcept; [[nodiscard]] constructor get_constructor_with() const noexcept;
@@ -2632,18 +2632,56 @@ namespace meta_hpp
[[nodiscard]] destructor get_destructor() const noexcept; [[nodiscard]] destructor get_destructor() const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] function get_function_with(std::string_view name) const noexcept; [[nodiscard]] function get_function_with( //
std::string_view name,
bool recursively = true
) const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] function get_function_with(std::string_view name, Iter first, Iter last) const noexcept; [[nodiscard]] function get_function_with( //
[[nodiscard]] function get_function_with(std::string_view name, std::span<const any_type> args) const noexcept; std::string_view name,
[[nodiscard]] function get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; Iter first,
Iter last,
bool recursively = true
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::span<const any_type> args,
bool recursively = true
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::initializer_list<any_type> args,
bool recursively = true
) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] method get_method_with(std::string_view name) const noexcept; [[nodiscard]] method get_method_with( //
std::string_view name,
bool recursively = true
) const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] method get_method_with(std::string_view name, Iter first, Iter last) const noexcept; [[nodiscard]] method get_method_with( //
[[nodiscard]] method get_method_with(std::string_view name, std::span<const any_type> args) const noexcept; std::string_view name,
[[nodiscard]] method get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; Iter first,
Iter last,
bool recursively = true
) const noexcept;
[[nodiscard]] method get_method_with( //
std::string_view name,
std::span<const any_type> args,
bool recursively = true
) const noexcept;
[[nodiscard]] method get_method_with( //
std::string_view name,
std::initializer_list<any_type> args,
bool recursively = true
) const noexcept;
}; };
class constructor_type final : public type_base<constructor_type> { class constructor_type final : public type_base<constructor_type> {
@@ -3828,11 +3866,26 @@ namespace meta_hpp
[[nodiscard]] variable get_variable(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] function get_function_with(std::string_view name) const noexcept; [[nodiscard]] function get_function_with( //
std::string_view name
) const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] function get_function_with(std::string_view name, Iter first, Iter last) const noexcept; [[nodiscard]] function get_function_with( //
[[nodiscard]] function get_function_with(std::string_view name, std::span<const any_type> args) const noexcept; std::string_view name,
[[nodiscard]] function get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; Iter first,
Iter last
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::span<const any_type> args
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::initializer_list<any_type> args
) const noexcept;
}; };
class variable final : public state_base<variable> { class variable final : public state_base<variable> {
@@ -8418,78 +8471,88 @@ namespace meta_hpp
return base.is_virtual_base_of(*this); return base.is_virtual_base_of(*this);
} }
inline function class_type::get_function(std::string_view name) const noexcept { inline function class_type::get_function(std::string_view name, bool recursively) const noexcept {
for ( const function& function : data_->functions ) { for ( const function& function : data_->functions ) {
if ( function.get_name() == name ) { if ( function.get_name() == name ) {
return function; return function;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const function& function = base.get_function(name) ) { for ( const class_type& base : data_->base_classes ) {
return function; if ( const function& function = base.get_function(name, recursively) ) {
return function;
}
} }
} }
return function{}; return function{};
} }
inline member class_type::get_member(std::string_view name) const noexcept { inline member class_type::get_member(std::string_view name, bool recursively) const noexcept {
for ( const member& member : data_->members ) { for ( const member& member : data_->members ) {
if ( member.get_name() == name ) { if ( member.get_name() == name ) {
return member; return member;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const member& member = base.get_member(name) ) { for ( const class_type& base : data_->base_classes ) {
return member; if ( const member& member = base.get_member(name, recursively) ) {
return member;
}
} }
} }
return member{}; return member{};
} }
inline method class_type::get_method(std::string_view name) const noexcept { inline method class_type::get_method(std::string_view name, bool recursively) const noexcept {
for ( const method& method : data_->methods ) { for ( const method& method : data_->methods ) {
if ( method.get_name() == name ) { if ( method.get_name() == name ) {
return method; return method;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const method& method = base.get_method(name) ) { for ( const class_type& base : data_->base_classes ) {
return method; if ( const method& method = base.get_method(name, recursively) ) {
return method;
}
} }
} }
return method{}; return method{};
} }
inline any_type class_type::get_typedef(std::string_view name) const noexcept { inline any_type class_type::get_typedef(std::string_view name, bool recursively) const noexcept {
if ( auto iter{data_->typedefs.find(name)}; iter != data_->typedefs.end() ) { if ( auto iter{data_->typedefs.find(name)}; iter != data_->typedefs.end() ) {
return iter->second; return iter->second;
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const any_type& type = base.get_typedef(name) ) { for ( const class_type& base : data_->base_classes ) {
return type; if ( const any_type& type = base.get_typedef(name, recursively) ) {
return type;
}
} }
} }
return any_type{}; return any_type{};
} }
inline variable class_type::get_variable(std::string_view name) const noexcept { inline variable class_type::get_variable(std::string_view name, bool recursively) const noexcept {
for ( const variable& variable : data_->variables ) { for ( const variable& variable : data_->variables ) {
if ( variable.get_name() == name ) { if ( variable.get_name() == name ) {
return variable; return variable;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const variable& variable = base.get_variable(name) ) { for ( const class_type& base : data_->base_classes ) {
return variable; if ( const variable& variable = base.get_variable(name, recursively) ) {
return variable;
}
} }
} }
@@ -8541,13 +8604,21 @@ namespace meta_hpp
// //
template < typename... Args > template < typename... Args >
function class_type::get_function_with(std::string_view name) const noexcept { function class_type::get_function_with( //
std::string_view name,
bool recursively
) const noexcept {
detail::type_registry& registry{detail::type_registry::instance()}; detail::type_registry& registry{detail::type_registry::instance()};
return get_function_with(name, {registry.resolve_type<Args>()...}); return get_function_with(name, {registry.resolve_type<Args>()...}, recursively);
} }
template < typename Iter > template < typename Iter >
function class_type::get_function_with(std::string_view name, Iter first, Iter last) const noexcept { function class_type::get_function_with( //
std::string_view name,
Iter first,
Iter last,
bool recursively
) const noexcept {
for ( const function& function : data_->functions ) { for ( const function& function : data_->functions ) {
if ( function.get_name() != name ) { if ( function.get_name() != name ) {
continue; continue;
@@ -8559,21 +8630,31 @@ namespace meta_hpp
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const function& function = base.get_function_with(name, first, last) ) { for ( const class_type& base : data_->base_classes ) {
return function; if ( const function& function = base.get_function_with(name, first, last, recursively) ) {
return function;
}
} }
} }
return function{}; return function{};
} }
inline function class_type::get_function_with(std::string_view name, std::span<const any_type> args) const noexcept { inline function class_type::get_function_with( //
return get_function_with(name, args.begin(), args.end()); std::string_view name,
std::span<const any_type> args,
bool recursively
) const noexcept {
return get_function_with(name, args.begin(), args.end(), recursively);
} }
inline function class_type::get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept { inline function class_type::get_function_with( //
return get_function_with(name, args.begin(), args.end()); std::string_view name,
std::initializer_list<any_type> args,
bool recursively
) const noexcept {
return get_function_with(name, args.begin(), args.end(), recursively);
} }
// //
@@ -8581,13 +8662,21 @@ namespace meta_hpp
// //
template < typename... Args > template < typename... Args >
method class_type::get_method_with(std::string_view name) const noexcept { method class_type::get_method_with( //
std::string_view name,
bool recursively
) const noexcept {
detail::type_registry& registry{detail::type_registry::instance()}; detail::type_registry& registry{detail::type_registry::instance()};
return get_method_with(name, {registry.resolve_type<Args>()...}); return get_method_with(name, {registry.resolve_type<Args>()...}, recursively);
} }
template < typename Iter > template < typename Iter >
method class_type::get_method_with(std::string_view name, Iter first, Iter last) const noexcept { method class_type::get_method_with( //
std::string_view name,
Iter first,
Iter last,
bool recursively
) const noexcept {
for ( const method& method : data_->methods ) { for ( const method& method : data_->methods ) {
if ( method.get_name() != name ) { if ( method.get_name() != name ) {
continue; continue;
@@ -8599,21 +8688,31 @@ namespace meta_hpp
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const method& method = base.get_method_with(name, first, last) ) { for ( const class_type& base : data_->base_classes ) {
return method; if ( const method& method = base.get_method_with(name, first, last, recursively) ) {
return method;
}
} }
} }
return method{}; return method{};
} }
inline method class_type::get_method_with(std::string_view name, std::span<const any_type> args) const noexcept { inline method class_type::get_method_with( //
return get_method_with(name, args.begin(), args.end()); std::string_view name,
std::span<const any_type> args,
bool recursively
) const noexcept {
return get_method_with(name, args.begin(), args.end(), recursively);
} }
inline method class_type::get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept { inline method class_type::get_method_with( //
return get_method_with(name, args.begin(), args.end()); std::string_view name,
std::initializer_list<any_type> args,
bool recursively
) const noexcept {
return get_method_with(name, args.begin(), args.end(), recursively);
} }
} }
@@ -8673,13 +8772,19 @@ namespace meta_hpp
} }
template < typename... Args > template < typename... Args >
function scope::get_function_with(std::string_view name) const noexcept { function scope::get_function_with( //
std::string_view name
) const noexcept {
detail::type_registry& registry{detail::type_registry::instance()}; detail::type_registry& registry{detail::type_registry::instance()};
return get_function_with(name, {registry.resolve_type<Args>()...}); return get_function_with(name, {registry.resolve_type<Args>()...});
} }
template < typename Iter > template < typename Iter >
function scope::get_function_with(std::string_view name, Iter first, Iter last) const noexcept { function scope::get_function_with( //
std::string_view name,
Iter first,
Iter last
) const noexcept {
for ( const function& function : state_->functions ) { for ( const function& function : state_->functions ) {
if ( function.get_name() != name ) { if ( function.get_name() != name ) {
continue; continue;
@@ -8693,11 +8798,17 @@ namespace meta_hpp
return function{}; return function{};
} }
inline function scope::get_function_with(std::string_view name, std::span<const any_type> args) const noexcept { inline function scope::get_function_with( //
std::string_view name,
std::span<const any_type> args
) const noexcept {
return get_function_with(name, args.begin(), args.end()); return get_function_with(name, args.begin(), args.end());
} }
inline function scope::get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept { inline function scope::get_function_with( //
std::string_view name,
std::initializer_list<any_type> args
) const noexcept {
return get_function_with(name, args.begin(), args.end()); return get_function_with(name, args.begin(), args.end());
} }
} }

View File

@@ -386,8 +386,10 @@ TEST_CASE("meta/meta_types/class_type") {
CHECK(base_clazz_2_type.get_function("base_function_2")); CHECK(base_clazz_2_type.get_function("base_function_2"));
CHECK_FALSE(base_clazz_2_type.get_function("derived_function")); CHECK_FALSE(base_clazz_2_type.get_function("derived_function"));
CHECK(derived_clazz_type.get_function("base_function_1")); CHECK(derived_clazz_type.get_function("base_function_1", true));
CHECK(derived_clazz_type.get_function("base_function_2")); CHECK(derived_clazz_type.get_function("base_function_2", true));
CHECK_FALSE(derived_clazz_type.get_function("base_function_1", false));
CHECK_FALSE(derived_clazz_type.get_function("base_function_2", false));
CHECK(derived_clazz_type.get_function("derived_function")); CHECK(derived_clazz_type.get_function("derived_function"));
} }
@@ -400,8 +402,10 @@ TEST_CASE("meta/meta_types/class_type") {
CHECK(base_clazz_2_type.get_member("base_member_2")); CHECK(base_clazz_2_type.get_member("base_member_2"));
CHECK_FALSE(base_clazz_2_type.get_member("derived_member")); CHECK_FALSE(base_clazz_2_type.get_member("derived_member"));
CHECK(derived_clazz_type.get_member("base_member_1")); CHECK(derived_clazz_type.get_member("base_member_1", true));
CHECK(derived_clazz_type.get_member("base_member_2")); CHECK(derived_clazz_type.get_member("base_member_2", true));
CHECK_FALSE(derived_clazz_type.get_member("base_member_1", false));
CHECK_FALSE(derived_clazz_type.get_member("base_member_2", false));
CHECK(derived_clazz_type.get_member("derived_member")); CHECK(derived_clazz_type.get_member("derived_member"));
} }
@@ -414,8 +418,10 @@ TEST_CASE("meta/meta_types/class_type") {
CHECK(base_clazz_2_type.get_method("base_method_2")); CHECK(base_clazz_2_type.get_method("base_method_2"));
CHECK_FALSE(base_clazz_2_type.get_method("derived_method")); CHECK_FALSE(base_clazz_2_type.get_method("derived_method"));
CHECK(derived_clazz_type.get_method("base_method_1")); CHECK(derived_clazz_type.get_method("base_method_1", true));
CHECK(derived_clazz_type.get_method("base_method_2")); CHECK(derived_clazz_type.get_method("base_method_2", true));
CHECK_FALSE(derived_clazz_type.get_method("base_method_1", false));
CHECK_FALSE(derived_clazz_type.get_method("base_method_2", false));
CHECK(derived_clazz_type.get_method("derived_method")); CHECK(derived_clazz_type.get_method("derived_method"));
} }
@@ -428,8 +434,10 @@ TEST_CASE("meta/meta_types/class_type") {
CHECK(base_clazz_2_type.get_variable("base_variable_2")); CHECK(base_clazz_2_type.get_variable("base_variable_2"));
CHECK_FALSE(base_clazz_2_type.get_variable("derived_variable")); CHECK_FALSE(base_clazz_2_type.get_variable("derived_variable"));
CHECK(derived_clazz_type.get_variable("base_variable_1")); CHECK(derived_clazz_type.get_variable("base_variable_1", true));
CHECK(derived_clazz_type.get_variable("base_variable_2")); CHECK(derived_clazz_type.get_variable("base_variable_2", true));
CHECK_FALSE(derived_clazz_type.get_variable("base_variable_1", false));
CHECK_FALSE(derived_clazz_type.get_variable("base_variable_2", false));
CHECK(derived_clazz_type.get_variable("derived_variable")); CHECK(derived_clazz_type.get_variable("derived_variable"));
} }

View File

@@ -335,11 +335,26 @@ namespace meta_hpp
[[nodiscard]] variable get_variable(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] function get_function_with(std::string_view name) const noexcept; [[nodiscard]] function get_function_with( //
std::string_view name
) const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] function get_function_with(std::string_view name, Iter first, Iter last) const noexcept; [[nodiscard]] function get_function_with( //
[[nodiscard]] function get_function_with(std::string_view name, std::span<const any_type> args) const noexcept; std::string_view name,
[[nodiscard]] function get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; Iter first,
Iter last
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::span<const any_type> args
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::initializer_list<any_type> args
) const noexcept;
}; };
class variable final : public state_base<variable> { class variable final : public state_base<variable> {

View File

@@ -72,13 +72,19 @@ namespace meta_hpp
} }
template < typename... Args > template < typename... Args >
function scope::get_function_with(std::string_view name) const noexcept { function scope::get_function_with( //
std::string_view name
) const noexcept {
detail::type_registry& registry{detail::type_registry::instance()}; detail::type_registry& registry{detail::type_registry::instance()};
return get_function_with(name, {registry.resolve_type<Args>()...}); return get_function_with(name, {registry.resolve_type<Args>()...});
} }
template < typename Iter > template < typename Iter >
function scope::get_function_with(std::string_view name, Iter first, Iter last) const noexcept { function scope::get_function_with( //
std::string_view name,
Iter first,
Iter last
) const noexcept {
for ( const function& function : state_->functions ) { for ( const function& function : state_->functions ) {
if ( function.get_name() != name ) { if ( function.get_name() != name ) {
continue; continue;
@@ -92,11 +98,17 @@ namespace meta_hpp
return function{}; return function{};
} }
inline function scope::get_function_with(std::string_view name, std::span<const any_type> args) const noexcept { inline function scope::get_function_with( //
std::string_view name,
std::span<const any_type> args
) const noexcept {
return get_function_with(name, args.begin(), args.end()); return get_function_with(name, args.begin(), args.end());
} }
inline function scope::get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept { inline function scope::get_function_with( //
std::string_view name,
std::initializer_list<any_type> args
) const noexcept {
return get_function_with(name, args.begin(), args.end()); return get_function_with(name, args.begin(), args.end());
} }
} }

View File

@@ -200,11 +200,11 @@ namespace meta_hpp
[[nodiscard]] bool is_virtual_derived_from() const noexcept; [[nodiscard]] bool is_virtual_derived_from() const noexcept;
[[nodiscard]] bool is_virtual_derived_from(const class_type& base) const noexcept; [[nodiscard]] bool is_virtual_derived_from(const class_type& base) const noexcept;
[[nodiscard]] function get_function(std::string_view name) const noexcept; [[nodiscard]] function get_function(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] member get_member(std::string_view name) const noexcept; [[nodiscard]] member get_member(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] method get_method(std::string_view name) const noexcept; [[nodiscard]] method get_method(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] any_type get_typedef(std::string_view name) const noexcept; [[nodiscard]] any_type get_typedef(std::string_view name, bool recursively = true) const noexcept;
[[nodiscard]] variable get_variable(std::string_view name) const noexcept; [[nodiscard]] variable get_variable(std::string_view name, bool recursively = true) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] constructor get_constructor_with() const noexcept; [[nodiscard]] constructor get_constructor_with() const noexcept;
@@ -216,18 +216,56 @@ namespace meta_hpp
[[nodiscard]] destructor get_destructor() const noexcept; [[nodiscard]] destructor get_destructor() const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] function get_function_with(std::string_view name) const noexcept; [[nodiscard]] function get_function_with( //
std::string_view name,
bool recursively = true
) const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] function get_function_with(std::string_view name, Iter first, Iter last) const noexcept; [[nodiscard]] function get_function_with( //
[[nodiscard]] function get_function_with(std::string_view name, std::span<const any_type> args) const noexcept; std::string_view name,
[[nodiscard]] function get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; Iter first,
Iter last,
bool recursively = true
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::span<const any_type> args,
bool recursively = true
) const noexcept;
[[nodiscard]] function get_function_with( //
std::string_view name,
std::initializer_list<any_type> args,
bool recursively = true
) const noexcept;
template < typename... Args > template < typename... Args >
[[nodiscard]] method get_method_with(std::string_view name) const noexcept; [[nodiscard]] method get_method_with( //
std::string_view name,
bool recursively = true
) const noexcept;
template < typename Iter > template < typename Iter >
[[nodiscard]] method get_method_with(std::string_view name, Iter first, Iter last) const noexcept; [[nodiscard]] method get_method_with( //
[[nodiscard]] method get_method_with(std::string_view name, std::span<const any_type> args) const noexcept; std::string_view name,
[[nodiscard]] method get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept; Iter first,
Iter last,
bool recursively = true
) const noexcept;
[[nodiscard]] method get_method_with( //
std::string_view name,
std::span<const any_type> args,
bool recursively = true
) const noexcept;
[[nodiscard]] method get_method_with( //
std::string_view name,
std::initializer_list<any_type> args,
bool recursively = true
) const noexcept;
}; };
class constructor_type final : public type_base<constructor_type> { class constructor_type final : public type_base<constructor_type> {

View File

@@ -261,78 +261,88 @@ namespace meta_hpp
return base.is_virtual_base_of(*this); return base.is_virtual_base_of(*this);
} }
inline function class_type::get_function(std::string_view name) const noexcept { inline function class_type::get_function(std::string_view name, bool recursively) const noexcept {
for ( const function& function : data_->functions ) { for ( const function& function : data_->functions ) {
if ( function.get_name() == name ) { if ( function.get_name() == name ) {
return function; return function;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const function& function = base.get_function(name) ) { for ( const class_type& base : data_->base_classes ) {
return function; if ( const function& function = base.get_function(name, recursively) ) {
return function;
}
} }
} }
return function{}; return function{};
} }
inline member class_type::get_member(std::string_view name) const noexcept { inline member class_type::get_member(std::string_view name, bool recursively) const noexcept {
for ( const member& member : data_->members ) { for ( const member& member : data_->members ) {
if ( member.get_name() == name ) { if ( member.get_name() == name ) {
return member; return member;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const member& member = base.get_member(name) ) { for ( const class_type& base : data_->base_classes ) {
return member; if ( const member& member = base.get_member(name, recursively) ) {
return member;
}
} }
} }
return member{}; return member{};
} }
inline method class_type::get_method(std::string_view name) const noexcept { inline method class_type::get_method(std::string_view name, bool recursively) const noexcept {
for ( const method& method : data_->methods ) { for ( const method& method : data_->methods ) {
if ( method.get_name() == name ) { if ( method.get_name() == name ) {
return method; return method;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const method& method = base.get_method(name) ) { for ( const class_type& base : data_->base_classes ) {
return method; if ( const method& method = base.get_method(name, recursively) ) {
return method;
}
} }
} }
return method{}; return method{};
} }
inline any_type class_type::get_typedef(std::string_view name) const noexcept { inline any_type class_type::get_typedef(std::string_view name, bool recursively) const noexcept {
if ( auto iter{data_->typedefs.find(name)}; iter != data_->typedefs.end() ) { if ( auto iter{data_->typedefs.find(name)}; iter != data_->typedefs.end() ) {
return iter->second; return iter->second;
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const any_type& type = base.get_typedef(name) ) { for ( const class_type& base : data_->base_classes ) {
return type; if ( const any_type& type = base.get_typedef(name, recursively) ) {
return type;
}
} }
} }
return any_type{}; return any_type{};
} }
inline variable class_type::get_variable(std::string_view name) const noexcept { inline variable class_type::get_variable(std::string_view name, bool recursively) const noexcept {
for ( const variable& variable : data_->variables ) { for ( const variable& variable : data_->variables ) {
if ( variable.get_name() == name ) { if ( variable.get_name() == name ) {
return variable; return variable;
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const variable& variable = base.get_variable(name) ) { for ( const class_type& base : data_->base_classes ) {
return variable; if ( const variable& variable = base.get_variable(name, recursively) ) {
return variable;
}
} }
} }
@@ -384,13 +394,21 @@ namespace meta_hpp
// //
template < typename... Args > template < typename... Args >
function class_type::get_function_with(std::string_view name) const noexcept { function class_type::get_function_with( //
std::string_view name,
bool recursively
) const noexcept {
detail::type_registry& registry{detail::type_registry::instance()}; detail::type_registry& registry{detail::type_registry::instance()};
return get_function_with(name, {registry.resolve_type<Args>()...}); return get_function_with(name, {registry.resolve_type<Args>()...}, recursively);
} }
template < typename Iter > template < typename Iter >
function class_type::get_function_with(std::string_view name, Iter first, Iter last) const noexcept { function class_type::get_function_with( //
std::string_view name,
Iter first,
Iter last,
bool recursively
) const noexcept {
for ( const function& function : data_->functions ) { for ( const function& function : data_->functions ) {
if ( function.get_name() != name ) { if ( function.get_name() != name ) {
continue; continue;
@@ -402,21 +420,31 @@ namespace meta_hpp
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const function& function = base.get_function_with(name, first, last) ) { for ( const class_type& base : data_->base_classes ) {
return function; if ( const function& function = base.get_function_with(name, first, last, recursively) ) {
return function;
}
} }
} }
return function{}; return function{};
} }
inline function class_type::get_function_with(std::string_view name, std::span<const any_type> args) const noexcept { inline function class_type::get_function_with( //
return get_function_with(name, args.begin(), args.end()); std::string_view name,
std::span<const any_type> args,
bool recursively
) const noexcept {
return get_function_with(name, args.begin(), args.end(), recursively);
} }
inline function class_type::get_function_with(std::string_view name, std::initializer_list<any_type> args) const noexcept { inline function class_type::get_function_with( //
return get_function_with(name, args.begin(), args.end()); std::string_view name,
std::initializer_list<any_type> args,
bool recursively
) const noexcept {
return get_function_with(name, args.begin(), args.end(), recursively);
} }
// //
@@ -424,13 +452,21 @@ namespace meta_hpp
// //
template < typename... Args > template < typename... Args >
method class_type::get_method_with(std::string_view name) const noexcept { method class_type::get_method_with( //
std::string_view name,
bool recursively
) const noexcept {
detail::type_registry& registry{detail::type_registry::instance()}; detail::type_registry& registry{detail::type_registry::instance()};
return get_method_with(name, {registry.resolve_type<Args>()...}); return get_method_with(name, {registry.resolve_type<Args>()...}, recursively);
} }
template < typename Iter > template < typename Iter >
method class_type::get_method_with(std::string_view name, Iter first, Iter last) const noexcept { method class_type::get_method_with( //
std::string_view name,
Iter first,
Iter last,
bool recursively
) const noexcept {
for ( const method& method : data_->methods ) { for ( const method& method : data_->methods ) {
if ( method.get_name() != name ) { if ( method.get_name() != name ) {
continue; continue;
@@ -442,20 +478,30 @@ namespace meta_hpp
} }
} }
for ( const class_type& base : data_->base_classes ) { if ( recursively ) {
if ( const method& method = base.get_method_with(name, first, last) ) { for ( const class_type& base : data_->base_classes ) {
return method; if ( const method& method = base.get_method_with(name, first, last, recursively) ) {
return method;
}
} }
} }
return method{}; return method{};
} }
inline method class_type::get_method_with(std::string_view name, std::span<const any_type> args) const noexcept { inline method class_type::get_method_with( //
return get_method_with(name, args.begin(), args.end()); std::string_view name,
std::span<const any_type> args,
bool recursively
) const noexcept {
return get_method_with(name, args.begin(), args.end(), recursively);
} }
inline method class_type::get_method_with(std::string_view name, std::initializer_list<any_type> args) const noexcept { inline method class_type::get_method_with( //
return get_method_with(name, args.begin(), args.end()); std::string_view name,
std::initializer_list<any_type> args,
bool recursively
) const noexcept {
return get_method_with(name, args.begin(), args.end(), recursively);
} }
} }