更新结构的IDName,直接为每种类型定义一个ConstStringSet来区分,代码理解更直接
This commit is contained in:
parent
fd72f42c92
commit
926c20448f
@ -5,18 +5,24 @@
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
template<typename SC>
|
||||
bool RegistryIDName(const size_t hash_code,ConstStringView<SC> &csv,const SC *name_string,const int name_length);
|
||||
template<typename T,typename SC>
|
||||
bool RegistryIDName(ConstStringView<SC> &csv,const SC *name_string,const int name_length)
|
||||
{
|
||||
if(!T::id_name_set)
|
||||
T::id_name_set=new ConstStringSet<SC>;
|
||||
|
||||
return(T::id_name_set->AddString(csv,name_string,name_length)>=0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 顺序ID+名称数据结构模板<br>
|
||||
* 按添加进来的名字先后顺序一个个产生连续的序号,所有数据只可读不可写
|
||||
*/
|
||||
template<typename SC,const char *IDNAME_TAG> class OrderedIDName:public Comparator<OrderedIDName<SC,IDNAME_TAG>>
|
||||
template<typename SC,typename MANAGER> class OrderedIDName:public Comparator<OrderedIDName<SC,MANAGER>>
|
||||
{
|
||||
public:
|
||||
|
||||
using SelfClass=OrderedIDName<SC,IDNAME_TAG>;
|
||||
using SelfClass=OrderedIDName<SC,MANAGER>;
|
||||
|
||||
protected:
|
||||
|
||||
@ -39,7 +45,7 @@ namespace hgl
|
||||
return;
|
||||
}
|
||||
|
||||
RegistryIDName<SC>(typeid(SelfClass).hash_code(),csv,name_string,name_length);
|
||||
RegistryIDName<MANAGER,SC>(csv,name_string,name_length);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -90,10 +96,11 @@ namespace hgl
|
||||
const int compare(const OrderedIDName &oin)const override{return GetID()-oin.GetID();}
|
||||
};//class IDName
|
||||
|
||||
#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()不同
|
||||
|
||||
#define HGL_DEFINE_IDNAME(name,char_type) struct IDName##_##name##_Manager{static ConstStringSet<char_type> *id_name_set;}; \
|
||||
ConstStringSet<char_type> *IDName##_##name##_Manager::id_name_set=nullptr; \
|
||||
using name=OrderedIDName<char_type,IDName##_##name##_Manager>; \
|
||||
using name##Set=SortedSet<name>;
|
||||
|
||||
HGL_DEFINE_IDNAME(AIDName, char)
|
||||
HGL_DEFINE_IDNAME(WIDName, wchar_t)
|
||||
HGL_DEFINE_IDNAME(U8IDName, u8char)
|
||||
|
@ -27,8 +27,7 @@ SOURCE_GROUP("DataType\\BitsArray" FILES ${BITS_ARRAY_FILES})
|
||||
SET(TYPE_IDNAME_HEADER_FILES ${TYPE_INCLUDE_PATH}/ConstStringSet.h
|
||||
${TYPE_INCLUDE_PATH}/IDName.h)
|
||||
|
||||
SET(TYPE_IDNAME_SOURCE_FILES Text/ConstStringSetSaveToTextStream.cpp
|
||||
Type/IDName.cpp)
|
||||
SET(TYPE_IDNAME_SOURCE_FILES Text/ConstStringSetSaveToTextStream.cpp)
|
||||
|
||||
SOURCE_GROUP("DataType\\IDName" FILES ${TYPE_IDNAME_HEADER_FILES} ${TYPE_IDNAME_SOURCE_FILES})
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
#include<hgl/type/IDName.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
template<typename SC>
|
||||
bool RegistryIDName(const size_t hash_code,ConstStringView<SC> &csv,const SC *name_string,const int name_length)
|
||||
{
|
||||
static ObjectMap<size_t,ConstStringSet<SC>> css_map;
|
||||
|
||||
ConstStringSet<SC> *css;
|
||||
|
||||
if(!css_map.Get(hash_code,css))
|
||||
{
|
||||
css=new ConstStringSet<SC>;
|
||||
css_map.Add(hash_code,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);}
|
||||
|
||||
REGISTRY_ID_NAME(char)
|
||||
REGISTRY_ID_NAME(wchar_t)
|
||||
REGISTRY_ID_NAME(u8char)
|
||||
REGISTRY_ID_NAME(u16char)
|
||||
REGISTRY_ID_NAME(os_char)
|
||||
|
||||
#undef REGISTRY_ID_NAME
|
||||
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user