恢复用size_t做为idname的索引.因为我们的索引是用hash_code产生的,传入字符串名字只是为让了typeid().hash_code()结果不一样

This commit is contained in:
hyzboy 2025-06-07 04:30:42 +08:00
parent 78a105affe
commit fd72f42c92
2 changed files with 7 additions and 9 deletions

View File

@ -6,7 +6,7 @@
namespace hgl namespace hgl
{ {
template<typename SC> template<typename SC>
bool RegistryIDName(const char *IDNameTag,ConstStringView<SC> &csv,const SC *name_string,const int name_length); bool RegistryIDName(const size_t hash_code,ConstStringView<SC> &csv,const SC *name_string,const int name_length);
/** /**
* ID+<br> * ID+<br>
@ -39,7 +39,7 @@ namespace hgl
return; return;
} }
RegistryIDName<SC>(IDNAME_TAG,csv,name_string,name_length); RegistryIDName<SC>(typeid(SelfClass).hash_code(),csv,name_string,name_length);
} }
public: public:

View File

@ -3,24 +3,22 @@
namespace hgl namespace hgl
{ {
template<typename SC> template<typename SC>
bool RegistryIDName(const char *tag,ConstStringView<SC> &csv,const SC *name_string,const int name_length) bool RegistryIDName(const size_t hash_code,ConstStringView<SC> &csv,const SC *name_string,const int name_length)
{ {
static ObjectMap<AnsiString,ConstStringSet<SC>> css_map; static ObjectMap<size_t,ConstStringSet<SC>> css_map;
ConstStringSet<SC> *css; ConstStringSet<SC> *css;
const AnsiString IDNameTag=tag; if(!css_map.Get(hash_code,css))
if(!css_map.Get(IDNameTag,css))
{ {
css=new ConstStringSet<SC>; css=new ConstStringSet<SC>;
css_map.Add(IDNameTag,css); css_map.Add(hash_code,css);
} }
return(css->AddString(csv,name_string,name_length)>=0); return(css->AddString(csv,name_string,name_length)>=0);
} }
#define REGISTRY_ID_NAME(type) bool RegistryIDName_##type(const char *tag,ConstStringView<type> &csv,const type *name,const int length){return RegistryIDName(tag,csv,name,length);} #define REGISTRY_ID_NAME(type) bool RegistryIDName_##type(const size_t hash_code,ConstStringView<type> &csv,const type *name,const int length){return RegistryIDName(hash_code,csv,name,length);}
REGISTRY_ID_NAME(char) REGISTRY_ID_NAME(char)
REGISTRY_ID_NAME(wchar_t) REGISTRY_ID_NAME(wchar_t)