Compare commits
2 Commits
fd0dbb0055
...
78a105affe
Author | SHA1 | Date | |
---|---|---|---|
78a105affe | |||
0c94d21de4 |
@ -2,22 +2,21 @@
|
|||||||
|
|
||||||
#include<hgl/type/ConstStringSet.h>
|
#include<hgl/type/ConstStringSet.h>
|
||||||
#include<hgl/type/SortedSet.h>
|
#include<hgl/type/SortedSet.h>
|
||||||
#include<typeinfo>
|
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
template<typename SC>
|
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>
|
* 顺序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:
|
public:
|
||||||
|
|
||||||
using SelfClass=OrderedIDName<SC,CLASS_COUNTER>;
|
using SelfClass=OrderedIDName<SC,IDNAME_TAG>;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ namespace hgl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RegistryIDName<SC>(typeid(*this).hash_code(),csv,name_string,name_length);
|
RegistryIDName<SC>(IDNAME_TAG,csv,name_string,name_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -91,7 +90,9 @@ namespace hgl
|
|||||||
const int compare(const OrderedIDName &oin)const override{return GetID()-oin.GetID();}
|
const int compare(const OrderedIDName &oin)const override{return GetID()-oin.GetID();}
|
||||||
};//class IDName
|
};//class IDName
|
||||||
|
|
||||||
#define HGL_DEFINE_IDNAME(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()不同
|
||||||
|
|
||||||
HGL_DEFINE_IDNAME(AIDName, char)
|
HGL_DEFINE_IDNAME(AIDName, char)
|
||||||
HGL_DEFINE_IDNAME(WIDName, wchar_t)
|
HGL_DEFINE_IDNAME(WIDName, wchar_t)
|
||||||
|
@ -3,22 +3,24 @@
|
|||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
template<typename SC>
|
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;
|
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=new ConstStringSet<SC>;
|
||||||
css_map.Add(hash_code,css);
|
css_map.Add(IDNameTag,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 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(char)
|
||||||
REGISTRY_ID_NAME(wchar_t)
|
REGISTRY_ID_NAME(wchar_t)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user