1#ifndef NEFORCE_CORE_REFLECT_REGISTRY_HPP__
2#define NEFORCE_CORE_REFLECT_REGISTRY_HPP__
14NEFORCE_BEGIN_NAMESPACE__
18NEFORCE_BEGIN_REFLECT__
33class NEFORCE_API registry {
62 auto it = types_.find(
id);
63 if (it != types_.end()) {
67 auto name_hash = name.to_hash();
69 name_hash_to_type_id_.emplace(name_hash,
id);
70 return *new_it->second;
81 auto name_hash = name.to_hash();
82 auto map_it = name_hash_to_type_id_.find(name_hash);
83 if (map_it == name_hash_to_type_id_.end()) {
86 auto it = types_.find(map_it->second);
87 return it != types_.end() ? it->second.get() :
nullptr;
107 const auto it = types_.find(
id);
108 return it != types_.end() ? it->second.get() :
nullptr;
118 template <
typename Func>
121 for (
auto& type: types_) {
134 for (
const auto& type: types_) {
135 type.second->resolve_bases_unlocked(
this);
156 size_t signal_offset,
void* receiver_obj,
string_view receiver_type,
158 const auto* s_meta =
instance().find(sender_type);
159 const auto* r_meta =
instance().find(receiver_type);
160 if ((s_meta ==
nullptr) || (r_meta ==
nullptr)) {
164 const auto* slot = r_meta->get_function(slot_name);
165 if (slot ==
nullptr) {
169 auto* sig_base =
reinterpret_cast<signal_base*
>(
static_cast<char*
>(sender_obj) + signal_offset);
170 if (sig_base ==
nullptr) {
192NEFORCE_END_NAMESPACE__
void for_each(Func &&func)
遍历所有注册的类型
meta_type * find(type_id id)
查找类型
meta_type * find(string_view name)
查找类型
static bool dynamic_connect(void *sender_obj, string_view sender_type, string_view signal_name, size_t signal_offset, void *receiver_obj, string_view receiver_type, string_view slot_name)
查找信号并连接到槽函数
static registry & instance()
获取单例实例
void resolve_all_bases()
解析所有类型的基类关系
meta_type & register_type(string_view name)
注册类型
static bool connect_signal_to_slot(signal_base *sig, const meta_function *slot, void *receiver)
将信号连接至反射槽函数
meta_type * find_unlocked(string_view name)
查找类型
constexpr type_id type_id_for() noexcept
计算类型 T 的运行时期类型标识
basic_string_view< char > string_view
字符字符串视图
constexpr unique_ptr< T > make_unique(Args &&... args)
创建unique_ptr