Fixed few <>
This commit is contained in:
parent
bf8be47d3a
commit
0dad4c5f9e
@ -129,7 +129,7 @@ namespace hgl
|
|||||||
* @param data 要删除的数据项
|
* @param data 要删除的数据项
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
virtual bool DeleteByValue(const T &data)
|
virtual bool DeleteByValue(T &data)
|
||||||
{
|
{
|
||||||
const int pos=Find(data);
|
const int pos=Find(data);
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ namespace hgl
|
|||||||
* @param n 要删除的数据个数
|
* @param n 要删除的数据个数
|
||||||
* @return 成功删除的数据个数
|
* @return 成功删除的数据个数
|
||||||
*/
|
*/
|
||||||
virtual int DeleteByValue(const T *data,int n)
|
virtual int DeleteByValue(T *data,int n)
|
||||||
{
|
{
|
||||||
int result=0;
|
int result=0;
|
||||||
|
|
||||||
@ -188,12 +188,12 @@ namespace hgl
|
|||||||
virtual void operator = (const DataArray<T> &da){data_array=da;} ///<操作符重载复制一个列表
|
virtual void operator = (const DataArray<T> &da){data_array=da;} ///<操作符重载复制一个列表
|
||||||
virtual void operator = (const std::initializer_list<T> &l){data_array=l;} ///<操作符重载复制一个列表
|
virtual void operator = (const std::initializer_list<T> &l){data_array=l;} ///<操作符重载复制一个列表
|
||||||
|
|
||||||
virtual void operator += (const T &obj){Add(obj);} ///<操作符重载添加一个数据
|
virtual void operator += (T &obj){Add(obj);} ///<操作符重载添加一个数据
|
||||||
virtual void operator << (const T &obj){Add(obj);} ///<操作符重载添加一个数据
|
virtual void operator << (T &obj){Add(obj);} ///<操作符重载添加一个数据
|
||||||
virtual void operator -= (const T &obj){DeleteByValue(obj);} ///<操作符重载删除一个数据
|
virtual void operator -= (T &obj){DeleteByValue(obj);} ///<操作符重载删除一个数据
|
||||||
|
|
||||||
T * At(const int index) {return data_array.At(index);} ///<取得指定序列号数据的索引
|
T * At(const int index) {return data_array.At(index);} ///<取得指定序列号数据的索引
|
||||||
const T * At(const int index)const{return data_array.At(index);} ///<取得指定序列号数据的索引
|
const T * At(const int index)const{return data_array.At(index);} ///<取得指定序列号数据的索引
|
||||||
|
|
||||||
bool Get(int index, T &data)const {return data_array.ReadAt (data,index);} ///<取得指定索引处的数据
|
bool Get(int index, T &data)const {return data_array.ReadAt (data,index);} ///<取得指定索引处的数据
|
||||||
virtual bool Set(int index,const T &data) {return data_array.WriteAt(data,index);} ///<设置指定索引处的数据
|
virtual bool Set(int index,const T &data) {return data_array.WriteAt(data,index);} ///<设置指定索引处的数据
|
||||||
|
@ -351,7 +351,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ObjectMap():ObjectMapTemplate(&DefaultOLM){};
|
ObjectMap():ObjectMapTemplate<K,V,KeyValue<K,V *>>(&DefaultOLM){};
|
||||||
virtual ~ObjectMap()=default;
|
virtual ~ObjectMap()=default;
|
||||||
};//template<typename K,typename V> class ObjectMap:public ObjectMapTemplate<K,V,KeyValue<K,V *>>
|
};//template<typename K,typename V> class ObjectMap:public ObjectMapTemplate<K,V,KeyValue<K,V *>>
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/type/List.h>
|
#include<hgl/type/List.h>
|
||||||
|
#include<hgl/type/LifecycleManager.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
@ -11,7 +12,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
DataLifecycleManager<T> *dlm; ///<数据生命周期回调函数
|
ObjectLifecycleManager<T> *dlm; ///<数据生命周期回调函数
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ namespace hgl
|
|||||||
|
|
||||||
public: //方法
|
public: //方法
|
||||||
|
|
||||||
ObjectListTemplate(DataLifecycleManager<T> *_dlm):List<T *>(){dlm=_dlm;}
|
ObjectListTemplate(ObjectLifecycleManager<T> *_dlm):List<T *>(){dlm=_dlm;}
|
||||||
virtual ~ObjectListTemplate(){Free();}
|
virtual ~ObjectListTemplate(){Free();}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -53,8 +54,8 @@ namespace hgl
|
|||||||
virtual bool Unlink(int index){return List<T *>::Delete(index);} ///<将指定索引处的数据与列表断开
|
virtual bool Unlink(int index){return List<T *>::Delete(index);} ///<将指定索引处的数据与列表断开
|
||||||
virtual bool UnlinkMove(int index){return List<T *>::DeleteMove(index);} ///<将指定索引处的数据与列表断开,将前移后面的数据
|
virtual bool UnlinkMove(int index){return List<T *>::DeleteMove(index);} ///<将指定索引处的数据与列表断开,将前移后面的数据
|
||||||
virtual bool Unlink(int start,int number){return List<T *>::Delete(start,number);} ///<将指定索引处的数据与列表断开
|
virtual bool Unlink(int start,int number){return List<T *>::Delete(start,number);} ///<将指定索引处的数据与列表断开
|
||||||
virtual bool UnlinkByValue(const ItemPointer &ip){return List<T *>::DeleteByValue(ip);} ///<将一个指定数据与列表断开
|
virtual bool UnlinkByValue(ItemPointer &ip){return List<T *>::DeleteByValue(ip);} ///<将一个指定数据与列表断开
|
||||||
virtual void UnlinkByValue(const ItemPointer *ip,int n){List<T *>::DeleteByValue(ip,n);} ///<将一批指定数据与列表断开
|
virtual void UnlinkByValue(ItemPointer *ip,int n){List<T *>::DeleteByValue(ip,n);} ///<将一批指定数据与列表断开
|
||||||
virtual void UnlinkAll(){List<T *>::Clear();} ///<断开所有数据
|
virtual void UnlinkAll(){List<T *>::Clear();} ///<断开所有数据
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -103,7 +104,7 @@ namespace hgl
|
|||||||
return List<T *>::DeleteMove(index,num);
|
return List<T *>::DeleteMove(index,num);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool DeleteByValue(const ItemPointer &obj) override ///<删除指定的一个数据
|
virtual bool DeleteByValue(ItemPointer &obj) override ///<删除指定的一个数据
|
||||||
{
|
{
|
||||||
if(!obj)return(false);
|
if(!obj)return(false);
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ namespace hgl
|
|||||||
return List<T *>::DeleteByValue(obj);
|
return List<T *>::DeleteByValue(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int DeleteByValue(const ItemPointer *obj_list,int num) override ///<删除指定的一批数据
|
virtual int DeleteByValue(ItemPointer *obj_list,int num) override ///<删除指定的一批数据
|
||||||
{
|
{
|
||||||
if(!obj_list||num<=0)return(-1);
|
if(!obj_list||num<=0)return(-1);
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ObjectManage():ObjectManageTemplate(&DefaultOLM){}
|
ObjectManage():ObjectManageTemplate<K,V>(&DefaultOLM){}
|
||||||
virtual ~ObjectManage()=default;
|
virtual ~ObjectManage()=default;
|
||||||
};//template<typename K,typename V> class ObjectManage:public ObjectManageTemplate<K,V>
|
};//template<typename K,typename V> class ObjectManage:public ObjectManageTemplate<K,V>
|
||||||
|
|
||||||
|
@ -63,11 +63,6 @@ namespace hgl
|
|||||||
Clear(); //有一些数据需要特别的Clear处理,所以不能依赖Active/InActive模板本身的自晰构
|
Clear(); //有一些数据需要特别的Clear处理,所以不能依赖Active/InActive模板本身的自晰构
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void SetDataLifetimeCallback(DataLifecycleManager<T> *cb) ///<设定数据生命周期回调函数
|
|
||||||
{
|
|
||||||
dlm=cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void PreAlloc(int count,bool set_to_max=false) ///<预分配空间
|
virtual void PreAlloc(int count,bool set_to_max=false) ///<预分配空间
|
||||||
{
|
{
|
||||||
Active.PreAlloc(count);
|
Active.PreAlloc(count);
|
||||||
@ -101,12 +96,10 @@ namespace hgl
|
|||||||
if(IsFull())
|
if(IsFull())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!dlm)return(false);
|
|
||||||
|
|
||||||
if(!dlm->Create(&value))
|
if(!dlm->Create(&value))
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
else if(dlm)
|
else
|
||||||
{
|
{
|
||||||
dlm->OnActive(&value);
|
dlm->OnActive(&value);
|
||||||
}
|
}
|
||||||
@ -121,8 +114,7 @@ namespace hgl
|
|||||||
if(!Idle.Pop(value))
|
if(!Idle.Pop(value))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(dlm)
|
dlm->OnActive(&value);
|
||||||
dlm->OnActive(&value);
|
|
||||||
|
|
||||||
Active.Add(value);
|
Active.Add(value);
|
||||||
return(true);
|
return(true);
|
||||||
@ -158,8 +150,7 @@ namespace hgl
|
|||||||
if(!Idle.Push(value))
|
if(!Idle.Push(value))
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(dlm)
|
dlm->OnIdle(&value);
|
||||||
dlm->OnIdle(&value);
|
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -185,8 +176,7 @@ namespace hgl
|
|||||||
|
|
||||||
virtual void ReleaseActive() ///<释放所有活跃数据
|
virtual void ReleaseActive() ///<释放所有活跃数据
|
||||||
{
|
{
|
||||||
if(dlm)
|
dlm->OnIdle(Active.GetData(),Active.GetCount());
|
||||||
dlm->OnIdle(Active.GetData(),Active.GetCount());
|
|
||||||
|
|
||||||
Idle.Push(Active.GetData(),Active.GetCount());
|
Idle.Push(Active.GetData(),Active.GetCount());
|
||||||
Active.Clear();
|
Active.Clear();
|
||||||
@ -194,15 +184,14 @@ namespace hgl
|
|||||||
|
|
||||||
virtual void ClearActive()
|
virtual void ClearActive()
|
||||||
{
|
{
|
||||||
if(dlm)
|
dlm->Clear(Active.GetData(),Active.GetCount());
|
||||||
dlm->Clear(Active.GetData(),Active.GetCount());
|
|
||||||
|
|
||||||
Active.Clear();
|
Active.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void ClearIdle() ///<清除所有非活跃数据
|
virtual void ClearIdle() ///<清除所有非活跃数据
|
||||||
{
|
{
|
||||||
Idle.Clear(dlm);
|
Idle.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Clear() ///<清除所有数据
|
virtual void Clear() ///<清除所有数据
|
||||||
@ -218,7 +207,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PoolWithDLM():PoolTemplate(&DefaultLifecycleManager){}
|
PoolWithDLM():PoolTemplate<T,AT,IT>(&DefaultLifecycleManager){}
|
||||||
virtual ~PoolWithDLM()=default;
|
virtual ~PoolWithDLM()=default;
|
||||||
};//template<typename T,typename AT,typename IT,typename DLM> class PoolWithDLM:public PoolTemplate<T,AT,IT>
|
};//template<typename T,typename AT,typename IT,typename DLM> class PoolWithDLM:public PoolTemplate<T,AT,IT>
|
||||||
|
|
||||||
|
@ -134,15 +134,12 @@ namespace hgl
|
|||||||
|
|
||||||
virtual void Clear () ///<清除所有数据
|
virtual void Clear () ///<清除所有数据
|
||||||
{
|
{
|
||||||
if(dlm)
|
if(data_array[read_index].GetCount()>read_offset) //还有没读完的,需要清掉
|
||||||
{
|
dlm->Clear( data_array[read_index].GetData()+read_offset,
|
||||||
if(data_array[read_index].GetCount()>read_offset) //还有没读完的,需要清掉
|
data_array[read_index].GetCount()-read_offset);
|
||||||
dlm->Clear(data_array[read_index].GetData()+read_offset,
|
|
||||||
data_array[read_index].GetCount()-read_offset);
|
|
||||||
|
|
||||||
dlm->Clear(data_array[write_index].GetData(),
|
dlm->Clear( data_array[write_index].GetData(),
|
||||||
data_array[write_index].GetCount());
|
data_array[write_index].GetCount());
|
||||||
}
|
|
||||||
|
|
||||||
data_array[0].Clear();
|
data_array[0].Clear();
|
||||||
data_array[1].Clear();
|
data_array[1].Clear();
|
||||||
@ -150,7 +147,7 @@ namespace hgl
|
|||||||
|
|
||||||
virtual void Free () ///<清除所有数据并释放内存
|
virtual void Free () ///<清除所有数据并释放内存
|
||||||
{
|
{
|
||||||
Clear(dlm);
|
Clear();
|
||||||
|
|
||||||
data_array[0].Free();
|
data_array[0].Free();
|
||||||
data_array[1].Free();
|
data_array[1].Free();
|
||||||
@ -165,7 +162,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Queue():QueueTemplate(&DefaultDLM){};
|
Queue():QueueTemplate<T>(&DefaultDLM){};
|
||||||
virtual ~Queue()=default;
|
virtual ~Queue()=default;
|
||||||
};//template<typename T> class Queue:public QueueTemplate<T>
|
};//template<typename T> class Queue:public QueueTemplate<T>
|
||||||
|
|
||||||
@ -175,28 +172,28 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ObjectQueue():QueueTemplate(&DefaultOLM){}
|
ObjectQueue():QueueTemplate<T *>(&DefaultOLM){}
|
||||||
virtual ~ObjectQueue() override { Free(); }
|
virtual ~ObjectQueue() override { Free(); }
|
||||||
|
|
||||||
virtual bool Push(T *obj)
|
virtual bool Push(T *obj)
|
||||||
{
|
{
|
||||||
if(!obj)return(false);
|
if(!obj)return(false);
|
||||||
|
|
||||||
return Queue<T *>::Push(obj);
|
return QueueTemplate<T *>::Push(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Push(T **obj_list,int count)
|
virtual bool Push(T **obj_list,int count)
|
||||||
{
|
{
|
||||||
if(!obj_list)return(false);
|
if(!obj_list)return(false);
|
||||||
|
|
||||||
return Queue<T *>::Push(obj_list,count);
|
return QueueTemplate<T *>::Push(obj_list,count);
|
||||||
}
|
}
|
||||||
|
|
||||||
T *Pop()
|
T *PopObject()
|
||||||
{
|
{
|
||||||
T *obj;
|
T *obj;
|
||||||
|
|
||||||
if(!Queue<T *>::Pop(obj))
|
if(!QueueTemplate<T *>::Pop(obj))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
@ -204,7 +201,7 @@ namespace hgl
|
|||||||
|
|
||||||
void Free()
|
void Free()
|
||||||
{
|
{
|
||||||
ObjectQueue<T>::Clear();
|
QueueTemplate<T *>::Clear();
|
||||||
|
|
||||||
this->data_array[0].Free();
|
this->data_array[0].Free();
|
||||||
this->data_array[1].Free();
|
this->data_array[1].Free();
|
||||||
|
@ -98,7 +98,7 @@ namespace hgl
|
|||||||
|
|
||||||
virtual void Free () ///<清除所有数据并释放内存
|
virtual void Free () ///<清除所有数据并释放内存
|
||||||
{
|
{
|
||||||
Clear(dlm);
|
Clear();
|
||||||
data_array.Free();
|
data_array.Free();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ namespace hgl
|
|||||||
data_array.WriteAt(da.GetData(),0,da.GetCount());
|
data_array.WriteAt(da.GetData(),0,da.GetCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void operator =(const Stack<T> &s){this->operator=(s.data_array);}
|
virtual void operator =(const StackTemplate<T> &s){this->operator=(s.data_array);}
|
||||||
};//template<typename T> class StackTemplate
|
};//template<typename T> class StackTemplate
|
||||||
|
|
||||||
template<typename T> class Stack:public StackTemplate<T>
|
template<typename T> class Stack:public StackTemplate<T>
|
||||||
@ -120,7 +120,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Stack():StackTemplate(&DefaultDLM){};
|
Stack():StackTemplate<T>(&DefaultDLM){};
|
||||||
virtual ~Stack()=default;
|
virtual ~Stack()=default;
|
||||||
};//template<typename T> class Stack:public StackTemplate<T>
|
};//template<typename T> class Stack:public StackTemplate<T>
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ObjectStack():StackTemplate(&DefaultOLM){}
|
ObjectStack():StackTemplate<T *>(&DefaultOLM){}
|
||||||
virtual ~ObjectStack() override {Free();}
|
virtual ~ObjectStack() override {Free();}
|
||||||
|
|
||||||
virtual bool Push(T *obj)
|
virtual bool Push(T *obj)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user