added GetPointer in Map<>
This commit is contained in:
@@ -179,6 +179,23 @@ namespace hgl
|
||||
data_list.Insert(FindPos(obj->key),obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据索引取得指定数据的指针<Br>
|
||||
* 比如定义了Map<int ID,struct DATA>,直接返回DATA需要复制会消耗一些时间,直接返回DATA *会更好一些
|
||||
*/
|
||||
template<typename K,typename V,typename KVData>
|
||||
V *_Map<K,V,KVData>::GetPointer(const K &key)const
|
||||
{
|
||||
int index=Find(key);
|
||||
|
||||
if(index==-1)
|
||||
return(nullptr);
|
||||
|
||||
KVData *obj=GetListObject(data_list,index);
|
||||
|
||||
return &(obj->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据索引取得数据与序号
|
||||
* @param flag 数据索引
|
||||
|
@@ -50,6 +50,7 @@ namespace hgl
|
||||
bool KeyExist(const K &key)const{return(Find(key)!=-1);} ///<确认这个数据是否存在
|
||||
bool ValueExist(const V &value)const{return(FindByValue(value)!=-1);} ///<确认这个数据是否存在
|
||||
bool Check(const K &key,const V &value)const; ///<确认数据是否是这个
|
||||
virtual V * GetPointer(const K &key)const; ///<取得数据指针
|
||||
virtual int GetValueAndSerial(const K &,V &) const; ///<取得数据与索引
|
||||
bool Get(const K &key,V &value)const{return(GetValueAndSerial(key,value)>=0);} ///<取得数据
|
||||
virtual bool Delete(const K &,V &); ///<将指定数据从列表中移除,并获得这个数据
|
||||
@@ -124,7 +125,6 @@ namespace hgl
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
KVData *GetItem(int n){return GetListObject(data_list,n);} ///<取指定序号的数据
|
||||
bool GetBySerial(int,K &,V &) const; ///<取指定序号的数据
|
||||
bool GetKey(int,K &); ///<取指定序号的索引
|
||||
|
Reference in New Issue
Block a user