Browse Source

New function Find() for ObjectPair and ObjectList. Same as Get() but return constant pointer on already existing object.

ObjPtr
Michael Uleysky 9 years ago
parent
commit
176bdb2be0
  1. 18
      include/common.h

18
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<ObjectPair> pair(i);
OBType<ObjectList> 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;

Loading…
Cancel
Save