From 0c94d21de4d5513b608ce54f942fb403758506f8 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 7 Jun 2025 04:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=9A=84IDName=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8C=BA=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/type/IDName.h | 25 +++++++++++++------------ src/Type/IDName.cpp | 12 +++++++----- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/inc/hgl/type/IDName.h b/inc/hgl/type/IDName.h index 8be9358..5aec4ea 100644 --- a/inc/hgl/type/IDName.h +++ b/inc/hgl/type/IDName.h @@ -2,22 +2,21 @@ #include #include -#include namespace hgl { template - bool RegistryIDName(const size_t hash_code,ConstStringView &csv,const SC *name_string,const int name_length); + bool RegistryIDName(const char *IDNameTag,ConstStringView &csv,const SC *name_string,const int name_length); /** * 顺序ID+名称数据结构模板
* 按添加进来的名字先后顺序一个个产生连续的序号,所有数据只可读不可写 */ - template class OrderedIDName:public Comparator> - { + template class OrderedIDName:public Comparator> + { public: - using SelfClass=OrderedIDName; + using SelfClass=OrderedIDName; protected: @@ -40,7 +39,7 @@ namespace hgl return; } - RegistryIDName(typeid(*this).hash_code(),csv,name_string,name_length); + RegistryIDName(IDNAME_TAG,csv,name_string,name_length); } public: @@ -91,11 +90,13 @@ namespace hgl const int compare(const OrderedIDName &oin)const override{return GetID()-oin.GetID();} };//class IDName -#define DefineIDName(name,type) using name=OrderedIDName; using name##Set=SortedSet; //使用__COUNTER__是为了让typeid()不同 +#define HGL_DEFINE_IDNAME(name,type) constexpr const char IDNameTag_##name[]=#name; \ + using name=OrderedIDName; \ + using name##Set=SortedSet; //使用__COUNTER__是为了让typeid()不同 - DefineIDName(AIDName, char) - DefineIDName(WIDName, wchar_t) - DefineIDName(U8IDName, u8char) - DefineIDName(U16IDName, u16char) - DefineIDName(OSIDName, os_char) + HGL_DEFINE_IDNAME(AIDName, char) + HGL_DEFINE_IDNAME(WIDName, wchar_t) + HGL_DEFINE_IDNAME(U8IDName, u8char) + HGL_DEFINE_IDNAME(U16IDName, u16char) + HGL_DEFINE_IDNAME(OSIDName, os_char) }//namespace hgl diff --git a/src/Type/IDName.cpp b/src/Type/IDName.cpp index 234efce..974f8af 100644 --- a/src/Type/IDName.cpp +++ b/src/Type/IDName.cpp @@ -3,22 +3,24 @@ namespace hgl { template - bool RegistryIDName(const size_t hash_code,ConstStringView &csv,const SC *name_string,const int name_length) + bool RegistryIDName(const char *tag,ConstStringView &csv,const SC *name_string,const int name_length) { - static ObjectMap> css_map; + static ObjectMap> css_map; ConstStringSet *css; - if(!css_map.Get(hash_code,css)) + const AnsiString IDNameTag=tag; + + if(!css_map.Get(IDNameTag,css)) { css=new ConstStringSet; - css_map.Add(hash_code,css); + css_map.Add(IDNameTag,css); } return(css->AddString(csv,name_string,name_length)>=0); } -#define REGISTRY_ID_NAME(type) bool RegistryIDName_##type(const size_t hash_code,ConstStringView &csv,const type *name,const int length){return RegistryIDName(hash_code,csv,name,length);} +#define REGISTRY_ID_NAME(type) bool RegistryIDName_##type(const char *tag,ConstStringView &csv,const type *name,const int length){return RegistryIDName(tag,csv,name,length);} REGISTRY_ID_NAME(char) REGISTRY_ID_NAME(wchar_t)