mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-14 11:40:35 +07:00
visit functions for registry
This commit is contained in:
@@ -24,43 +24,102 @@ namespace meta_hpp
|
||||
template < typename T >
|
||||
std::optional<type> resolve() const {
|
||||
const family_id fid = get_type_family_id<T>();
|
||||
return detail::find_opt(family_to_types_, fid);
|
||||
return detail::find_opt(types_, fid);
|
||||
}
|
||||
|
||||
template < auto T >
|
||||
std::optional<type> resolve() const {
|
||||
const family_id fid = get_value_family_id<T>();
|
||||
return detail::find_opt(family_to_types_, fid);
|
||||
return detail::find_opt(types_, fid);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
std::optional<type> resolve(T&&) const {
|
||||
const family_id fid = get_type_family_id<std::decay_t<T>>();
|
||||
return detail::find_opt(family_to_types_, fid);
|
||||
return detail::find_opt(types_, fid);
|
||||
}
|
||||
|
||||
std::optional<class_info> 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<field_info> 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<function_info> 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<method_info> 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<namespace_info> 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<variable_info> 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_id, type, std::less<>> family_to_types_;
|
||||
std::map<std::string, class_info, std::less<>> name_to_classes_;
|
||||
std::map<std::string, field_info, std::less<>> name_to_fields_;
|
||||
std::map<std::string, function_info, std::less<>> name_to_functions_;
|
||||
std::map<std::string, method_info, std::less<>> name_to_methods_;
|
||||
std::map<std::string, namespace_info, std::less<>> name_to_namespaces_;
|
||||
std::map<std::string, variable_info, std::less<>> name_to_variables_;
|
||||
std::map<family_id, type, std::less<>> types_;
|
||||
std::map<std::string, class_info, std::less<>> classes_;
|
||||
std::map<std::string, field_info, std::less<>> fields_;
|
||||
std::map<std::string, function_info, std::less<>> functions_;
|
||||
std::map<std::string, method_info, std::less<>> methods_;
|
||||
std::map<std::string, namespace_info, std::less<>> namespaces_;
|
||||
std::map<std::string, variable_info, std::less<>> variables_;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user