diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp index c22c76c..2fdda74 100644 --- a/headers/meta.hpp/meta_registry.hpp +++ b/headers/meta.hpp/meta_registry.hpp @@ -24,43 +24,102 @@ namespace meta_hpp template < typename T > std::optional resolve() const { const family_id fid = get_type_family_id(); - return detail::find_opt(family_to_types_, fid); + return detail::find_opt(types_, fid); } template < auto T > std::optional resolve() const { const family_id fid = get_value_family_id(); - return detail::find_opt(family_to_types_, fid); + return detail::find_opt(types_, fid); } template < typename T > std::optional resolve(T&&) const { const family_id fid = get_type_family_id>(); - return detail::find_opt(family_to_types_, fid); + return detail::find_opt(types_, fid); } std::optional get_class_by_name(std::string_view name) const { - return detail::find_opt(name_to_classes_, name); + return detail::find_opt(classes_, name); } std::optional get_field_by_name(std::string_view name) const { - return detail::find_opt(name_to_fields_, name); + return detail::find_opt(fields_, name); } std::optional get_function_by_name(std::string_view name) const { - return detail::find_opt(name_to_functions_, name); + return detail::find_opt(functions_, name); } std::optional get_method_by_name(std::string_view name) const { - return detail::find_opt(name_to_methods_, name); + return detail::find_opt(methods_, name); } std::optional get_namespace_by_name(std::string_view name) const { - return detail::find_opt(name_to_namespaces_, name); + return detail::find_opt(namespaces_, name); } std::optional get_variable_by_name(std::string_view name) const { - return detail::find_opt(name_to_variables_, name); + return detail::find_opt(variables_, name); + } + + template < typename F > + void each_type(F&& f) const { + for ( auto&& id_type : types_ ) { + std::invoke(f, id_type.second); + } + } + + template < typename F > + void each_class(F&& f) const { + for ( auto&& id_info : classes_ ) { + std::invoke(f, id_info.second); + } + } + + template < typename F > + void each_field(F&& f) const { + for ( auto&& id_info : fields_ ) { + std::invoke(f, id_info.second); + } + } + + template < typename F > + void each_function(F&& f) const { + for ( auto&& id_info : functions_ ) { + std::invoke(f, id_info.second); + } + } + + template < typename F > + void each_method(F&& f) const { + for ( auto&& id_info : methods_ ) { + std::invoke(f, id_info.second); + } + } + + template < typename F > + void each_namespace(F&& f) const { + for ( auto&& id_info : namespaces_ ) { + std::invoke(f, id_info.second); + } + } + + template < typename F > + void each_variable(F&& f) const { + for ( auto&& id_info : variables_ ) { + std::invoke(f, id_info.second); + } + } + + template < typename F > + void visit(F&& f) const { + each_class(f); + each_field(f); + each_function(f); + each_method(f); + each_namespace(f); + each_variable(f); } template < typename... Internals > @@ -74,8 +133,8 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(name_to_classes_, name, info, &class_info::merge); - detail::merge_with(family_to_types_, info.fid(), info, &type::merge); + detail::merge_with(types_, info.fid(), info, &type::merge); + detail::merge_with(classes_, name, info, &class_info::merge); info.visit(overloaded { [](const data_info&) {}, @@ -90,8 +149,8 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(name_to_fields_, name, info, &field_info::merge); - detail::merge_with(family_to_types_, info.fid(), info, &type::merge); + detail::merge_with(types_, info.fid(), info, &type::merge); + detail::merge_with(fields_, name, info, &field_info::merge); info.visit(overloaded { [](const data_info&) {}, @@ -106,8 +165,8 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(name_to_functions_, name, info, &function_info::merge); - detail::merge_with(family_to_types_, info.fid(), info, &type::merge); + detail::merge_with(types_, info.fid(), info, &type::merge); + detail::merge_with(functions_, name, info, &function_info::merge); info.visit(overloaded { [](const data_info&) {}, @@ -122,8 +181,8 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(name_to_methods_, name, info, &method_info::merge); - detail::merge_with(family_to_types_, info.fid(), info, &type::merge); + detail::merge_with(types_, info.fid(), info, &type::merge); + detail::merge_with(methods_, name, info, &method_info::merge); info.visit(overloaded { [](const data_info&) {}, @@ -138,7 +197,7 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(name_to_namespaces_, name, info, &namespace_info::merge); + detail::merge_with(namespaces_, name, info, &namespace_info::merge); info.visit(overloaded { [](const data_info&) {}, @@ -153,8 +212,8 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(name_to_variables_, name, info, &variable_info::merge); - detail::merge_with(family_to_types_, info.fid(), info, &type::merge); + detail::merge_with(types_, info.fid(), info, &type::merge); + detail::merge_with(variables_, name, info, &variable_info::merge); info.visit(overloaded { [](const data_info&) {}, @@ -164,12 +223,12 @@ namespace meta_hpp }); } private: - std::map> family_to_types_; - std::map> name_to_classes_; - std::map> name_to_fields_; - std::map> name_to_functions_; - std::map> name_to_methods_; - std::map> name_to_namespaces_; - std::map> name_to_variables_; + std::map> types_; + std::map> classes_; + std::map> fields_; + std::map> functions_; + std::map> methods_; + std::map> namespaces_; + std::map> variables_; }; }