Merge branch 'master' of http://www.hyzgame.com:3000/hyzboy/CMCore
This commit is contained in:
commit
e3e9f91c44
@ -13,69 +13,74 @@ namespace hgl
|
|||||||
|
|
||||||
#define CompOperatorMemcmp(name) int _Comp(name data)const{return memcmp(this,&data,sizeof(name));} \
|
#define CompOperatorMemcmp(name) int _Comp(name data)const{return memcmp(this,&data,sizeof(name));} \
|
||||||
CompOperator(name,_Comp)
|
CompOperator(name,_Comp)
|
||||||
|
}//namespace hgl
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较处理模板基类
|
||||||
|
*/
|
||||||
|
template<typename T> class Comparator ///比较处理模板基类
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比较处理模板基类
|
* 比较函数,需被特例化或派生实现
|
||||||
*/
|
*/
|
||||||
template<typename T> class Comparator ///比较处理模板基类
|
virtual int compare(const T &a,const T &b)const
|
||||||
{
|
{
|
||||||
public:
|
return 0; // 如 return(a-b); ,但这个函数正确情况下不应该会被调用
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比较函数,需被特例化或派生实现
|
* 交换函数
|
||||||
*/
|
*/
|
||||||
virtual int compare(const T &a,const T &b)const
|
virtual void exchange(T &a,T &b)
|
||||||
{
|
{
|
||||||
return 0; // 如 return(a-b); ,但这个函数正确情况下不应该会被调用
|
hgl::hgl_swap(a,b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 交换函数
|
* 复制数据
|
||||||
*/
|
*/
|
||||||
virtual void exchange(T &a,T &b)
|
virtual void cpy(T *t,T *s)
|
||||||
{
|
{
|
||||||
hgl_swap(a,b);
|
memcpy(t,s,sizeof(T));
|
||||||
}
|
}
|
||||||
|
};//class Comparator
|
||||||
|
|
||||||
/**
|
//针对原生类型的特例化版本,做适当加速
|
||||||
* 复制数据
|
#define COMPARATOR_ORIGIN_TYPE(type) template<> class Comparator<type> \
|
||||||
*/
|
{ \
|
||||||
virtual void cpy(T *t,T *s)
|
public: \
|
||||||
{
|
int compare(const type &a,const type &b)const{return a-b;} \
|
||||||
memcpy(t,s,sizeof(T));
|
void exchange(type &a,type &b){type t;t=a;a=b;b=t;} \
|
||||||
}
|
void cpy(type *t,type *s){*t=*s;} \
|
||||||
};//class Comparator
|
};
|
||||||
|
|
||||||
//针对原生类型的特例化版本,做适当加速
|
COMPARATOR_ORIGIN_TYPE(hgl::int8)
|
||||||
#define COMPARATOR_ORIGIN_TYPE(type) template<> class Comparator<type> \
|
COMPARATOR_ORIGIN_TYPE(hgl::int16)
|
||||||
{ \
|
COMPARATOR_ORIGIN_TYPE(hgl::int32)
|
||||||
public: \
|
COMPARATOR_ORIGIN_TYPE(hgl::int64)
|
||||||
int compare(const type &a,const type &b)const{return a-b;} \
|
|
||||||
void exchange(type &a,type &b){type t;t=a;a=b;b=t;} \
|
|
||||||
void cpy(type *t,type *s){*t=*s;} \
|
|
||||||
};
|
|
||||||
|
|
||||||
COMPARATOR_ORIGIN_TYPE(int8)
|
COMPARATOR_ORIGIN_TYPE(hgl::uint8)
|
||||||
COMPARATOR_ORIGIN_TYPE(int16)
|
COMPARATOR_ORIGIN_TYPE(hgl::uint16)
|
||||||
COMPARATOR_ORIGIN_TYPE(int32)
|
COMPARATOR_ORIGIN_TYPE(hgl::uint32)
|
||||||
COMPARATOR_ORIGIN_TYPE(int64)
|
COMPARATOR_ORIGIN_TYPE(hgl::uint64)
|
||||||
|
|
||||||
COMPARATOR_ORIGIN_TYPE(uint8)
|
COMPARATOR_ORIGIN_TYPE(float)
|
||||||
COMPARATOR_ORIGIN_TYPE(uint16)
|
COMPARATOR_ORIGIN_TYPE(double)
|
||||||
COMPARATOR_ORIGIN_TYPE(uint32)
|
|
||||||
COMPARATOR_ORIGIN_TYPE(uint64)
|
|
||||||
|
|
||||||
COMPARATOR_ORIGIN_TYPE(float)
|
#if __cpp_char8_t
|
||||||
COMPARATOR_ORIGIN_TYPE(double)
|
COMPARATOR_ORIGIN_TYPE(char8_t)
|
||||||
|
#endif//
|
||||||
|
|
||||||
COMPARATOR_ORIGIN_TYPE(char)
|
COMPARATOR_ORIGIN_TYPE(char)
|
||||||
COMPARATOR_ORIGIN_TYPE(wchar_t)
|
COMPARATOR_ORIGIN_TYPE(wchar_t)
|
||||||
|
|
||||||
#if HGL_OS != HGL_OS_Windows
|
#if HGL_OS != HGL_OS_Windows
|
||||||
COMPARATOR_ORIGIN_TYPE(u16char)
|
COMPARATOR_ORIGIN_TYPE(u16char)
|
||||||
#endif//HGL_OS != HGL_OS_Windows
|
#endif//HGL_OS != HGL_OS_Windows
|
||||||
|
|
||||||
|
COMPARATOR_ORIGIN_TYPE(char32_t)
|
||||||
|
#undef COMPARATOR_ORIGIN_TYPE
|
||||||
|
|
||||||
COMPARATOR_ORIGIN_TYPE(char32_t)
|
|
||||||
#undef COMPARATOR_ORIGIN_TYPE
|
|
||||||
}//namespace hgl
|
|
||||||
#endif//HGL_COMP_OPERATOR_INCLUDE
|
#endif//HGL_COMP_OPERATOR_INCLUDE
|
||||||
|
@ -134,7 +134,7 @@ namespace hgl
|
|||||||
for(int i=0;i<count;i++)
|
for(int i=0;i<count;i++)
|
||||||
{
|
{
|
||||||
//if((*data_array)->value==data)
|
//if((*data_array)->value==data)
|
||||||
if(hgl_cmp(data_array[i]->value,data)==0)
|
if(hgl_cmp((*data_array)->value,data)==0)
|
||||||
return(i);
|
return(i);
|
||||||
|
|
||||||
++data_array;
|
++data_array;
|
||||||
|
@ -121,8 +121,8 @@ namespace hgl
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear (){delete_list.Clear();} ///<清除数据
|
void Clear (){data_list.Clear();} ///<清除数据
|
||||||
void ClearData (){delete_list.ClearData();} ///<清除数据,但不释放内存
|
void ClearData (){data_list.ClearData();} ///<清除数据,但不释放内存
|
||||||
|
|
||||||
bool Get (const int index,T &data) ///<根据序列号取得指定数据
|
bool Get (const int index,T &data) ///<根据序列号取得指定数据
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user