From 4ca69c06f5effc9a6977f9d7a4e9d7b612a12c6c Mon Sep 17 00:00:00 2001 From: HuYingzhuo Date: Sat, 27 Apr 2019 22:02:23 +0800 Subject: [PATCH] =?UTF-8?q?map=E5=A2=9E=E5=8A=A0Check=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/type/Map.cpp | 13 +++++++++++++ inc/hgl/type/Map.h | 1 + 2 files changed, 14 insertions(+) diff --git a/inc/hgl/type/Map.cpp b/inc/hgl/type/Map.cpp index be99c48b..2e709e9a 100644 --- a/inc/hgl/type/Map.cpp +++ b/inc/hgl/type/Map.cpp @@ -218,6 +218,19 @@ namespace hgl return(true); } + template + bool _Map::Check(const F &key,const T &value) const + { + int index=Find(key); + + DataPair *obj=GetObject(data_list,index); + + if(!obj) + return(false); + + return (value==obj->right); + } + /** * 根据序号取得数据 * @param index 序号 diff --git a/inc/hgl/type/Map.h b/inc/hgl/type/Map.h index 86217b4d..c10c14ee 100644 --- a/inc/hgl/type/Map.h +++ b/inc/hgl/type/Map.h @@ -39,6 +39,7 @@ namespace hgl int FindByValue(const T &)const; ///<查找数据是否存在,返回-1表示数据不存在 bool KeyExist(const F &key)const{return(Find(key)!=-1);} ///<确认这个数据是否存在 bool ValueExist(const T &value)const{return(FindByValue(value)!=-1);} ///<确认这个数据是否存在 + bool Check(const F &key,const T &value)const; ///<确认数据是否是这个 virtual bool Get(const F &,T &)const; ///<取得数据 virtual bool Delete(const F &,T &); ///<将指定数据从列表中移除,并获得这个数据 virtual bool DeleteByKey(const F &); ///<根据索引将指定数据从列表中移除