ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
ngl::tools::nhash Class Reference

命名哈希码生成器。 More...

#include <tools_nhash.h>

Static Public Member Functions

template<typename T>
static nhashcode code ()
 获取类型的唯一哈希码。

Detailed Description

命名哈希码生成器。

为每个C++类型生成唯一的nhashcode。当多个类型具有相同的 typeid().hash_code()时,通过类型名称和递增索引进行消歧。

Note
线程安全,使用写锁保护内部映射表。
使用type_name<T>()获取类型名称作为消歧键。
auto code1 = nhash::code<MyClass>();
auto code2 = nhash::code<OtherClass>();
// code1 != code2 即使hash_code相同

Member Function Documentation

◆ code()

template<typename T>
nhashcode ngl::tools::nhash::code ( )
inlinestatic

获取类型的唯一哈希码。

Template Parameters
T要获取哈希码的类型
Returns
nhashcode 唯一的命名哈希码
Note
首次调用会分配索引,后续调用返回缓存结果。
线程安全。

The documentation for this class was generated from the following files: