From 6d5612b8f2e4310654db86aeaa5fdacf9b5a2ce4 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 12 Jul 2024 02:51:59 +0800 Subject: [PATCH] Added IDNameTest.cpp, first test OK! --- datatype/IDNameTest.cpp | 120 ++++------------------------------------ 1 file changed, 12 insertions(+), 108 deletions(-) diff --git a/datatype/IDNameTest.cpp b/datatype/IDNameTest.cpp index f8f984c..bcc5c95 100644 --- a/datatype/IDNameTest.cpp +++ b/datatype/IDNameTest.cpp @@ -1,115 +1,19 @@ -#include -#include - -#include -#include +#include #include -namespace hgl -{ - namespace IDNameManager - { - template - bool RegistryIDName(ConstStringView &csv,const std::type_index &index,const SC *name_string) - { - static ObjectMap> css_set; - - ConstStringSet *css; - - if(css_set.KeyExist(index)) - { - css_set.Get(index,css); - } - else - { - css=new ConstStringSet; - css_set.Add(index,css); - } - - return css->AddString(csv,name_string,hgl::strlen(name_string)); - } - } - - /** - * 顺序ID+名称数据结构模板
- * 按添加进来的名字先后顺序一个个产生连续的序号,所有数据只可读不可写 - */ - template class OrderedIDName - { - protected: - - ConstStringView csv; - - protected: - - void Clear() - { - csv.id=-1; - csv.length=-1; - csv.str=nullptr; - } - - void Update(const SC *name_string) - { - if(!name_string) - { - Clear(); - } - else - { - IDNameManager::RegistryIDName(csv,typeid(*this),name_string); - } - } - - public: - - const int GetID ()const{return csv.id;} ///<获取名称ID - const SC *GetName ()const{return csv.str;} ///<获取名称字符串 - - public: - - OrderedIDName() - { - Clear(); - } - - OrderedIDName(const SC *name_string) - { - Update(name_string); - } - - void operator = (const SC *name_string) - { - Update(name_string); - } - - void operator = (const OrderedIDName &id_name) - { - hgl_cpy(csv,id_name.csv); - } - - public: - - const int Comp(const OrderedIDName &oin)const{return GetID()-oin.GetID();} - - CompOperator(const OrderedIDName &,Comp) - };//class IDName - -#define IDNameDefine(name,type) using name=OrderedIDName; //使用__COUNTER__是为了让typeid()不同 - - IDNameDefine(AnsiIDName,char) - IDNameDefine(UTF8IDName,char) -}//namespace hgl - void main() { using namespace hgl; - UTF8IDName oin_utf8("oin_utf8"); - UTF8IDName oin_u8("oin u8"); - UTF8IDName oin_u8same(oin_u8); + UTF8IDName id1("utf8_1"); + UTF8IDName id2("utf8_2"); - std::cout<<"oin_utf8: "<