新的IDName改用字符串区分
This commit is contained in:
parent
f1a6f0b90e
commit
0c94d21de4
@ -2,22 +2,21 @@
|
||||
|
||||
#include<hgl/type/ConstStringSet.h>
|
||||
#include<hgl/type/SortedSet.h>
|
||||
#include<typeinfo>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
template<typename SC>
|
||||
bool RegistryIDName(const size_t hash_code,ConstStringView<SC> &csv,const SC *name_string,const int name_length);
|
||||
bool RegistryIDName(const char *IDNameTag,ConstStringView<SC> &csv,const SC *name_string,const int name_length);
|
||||
|
||||
/**
|
||||
* 顺序ID+名称数据结构模板<br>
|
||||
* 按添加进来的名字先后顺序一个个产生连续的序号,所有数据只可读不可写
|
||||
*/
|
||||
template<typename SC,int CLASS_COUNTER> class OrderedIDName:public Comparator<OrderedIDName<SC,CLASS_COUNTER>>
|
||||
template<typename SC,const char *IDNAME_TAG> class OrderedIDName:public Comparator<OrderedIDName<SC,IDNAME_TAG>>
|
||||
{
|
||||
public:
|
||||
|
||||
using SelfClass=OrderedIDName<SC,CLASS_COUNTER>;
|
||||
using SelfClass=OrderedIDName<SC,IDNAME_TAG>;
|
||||
|
||||
protected:
|
||||
|
||||
@ -40,7 +39,7 @@ namespace hgl
|
||||
return;
|
||||
}
|
||||
|
||||
RegistryIDName<SC>(typeid(*this).hash_code(),csv,name_string,name_length);
|
||||
RegistryIDName<SC>(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<type,__COUNTER__>; using name##Set=SortedSet<name>; //使用__COUNTER__是为了让typeid()不同
|
||||
#define HGL_DEFINE_IDNAME(name,type) constexpr const char IDNameTag_##name[]=#name; \
|
||||
using name=OrderedIDName<type,IDNameTag_##name>; \
|
||||
using name##Set=SortedSet<name>; //使用__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
|
||||
|
@ -3,22 +3,24 @@
|
||||
namespace hgl
|
||||
{
|
||||
template<typename SC>
|
||||
bool RegistryIDName(const size_t hash_code,ConstStringView<SC> &csv,const SC *name_string,const int name_length)
|
||||
bool RegistryIDName(const char *tag,ConstStringView<SC> &csv,const SC *name_string,const int name_length)
|
||||
{
|
||||
static ObjectMap<size_t,ConstStringSet<SC>> css_map;
|
||||
static ObjectMap<AnsiString,ConstStringSet<SC>> css_map;
|
||||
|
||||
ConstStringSet<SC> *css;
|
||||
|
||||
if(!css_map.Get(hash_code,css))
|
||||
const AnsiString IDNameTag=tag;
|
||||
|
||||
if(!css_map.Get(IDNameTag,css))
|
||||
{
|
||||
css=new ConstStringSet<SC>;
|
||||
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<type> &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<type> &csv,const type *name,const int length){return RegistryIDName(tag,csv,name,length);}
|
||||
|
||||
REGISTRY_ID_NAME(char)
|
||||
REGISTRY_ID_NAME(wchar_t)
|
||||
|
Loading…
x
Reference in New Issue
Block a user