From 176bdb2be02121408befb4186138ed2002bbc964 Mon Sep 17 00:00:00 2001 From: Michael Uleysky Date: Mon, 15 Feb 2016 22:17:14 +1000 Subject: [PATCH] New function Find() for ObjectPair and ObjectList. Same as Get() but return constant pointer on already existing object. --- include/common.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/include/common.h b/include/common.h index 27f5844..b9479d3 100644 --- a/include/common.h +++ b/include/common.h @@ -265,6 +265,12 @@ public: if(gname==name) return val->Copy(); else return 0; } + // This function is same as Get but return pointer on constant object + const ObjectBase* Find(const std::string& gname) const + { + if(gname==name) return val.get(); + else return 0; + } std::string Name() const {return name;} void SetPair(const std::string& n, ObjectBase* v) {if(!Exist()) {name=n; val.reset(v);}} const ObjectBase* Value() const {return val.get();} @@ -347,14 +353,20 @@ public: bool Exist() const {return 0!=vals->size();} ObjectBase* Get(const std::string& gname) const { - ObjectBase* p; + const ObjectBase* p=Find(gname); + return (0==p)?0:p->Copy(); + } + // This function is same as Get but return pointer on constant object + const ObjectBase* Find(const std::string& gname) const + { + const ObjectBase* p; for(auto& i: *vals) { p=0; OBType pair(i); OBType list(i); - if(pair) p=pair->Get(gname); - else if(list) p=list->Get(gname); + if(pair) p=pair->Find(gname); + else if(list) p=list->Find(gname); if(0!=p) return p; } return 0;