Browse Source

Remove unneeded functions from ObjectPair and ObjectList classes.

template_comparator
Michael Uleysky 8 years ago
parent
commit
b2a7e3627c
  1. 37
      include/common.h

37
include/common.h

@ -189,6 +189,7 @@ private:
const int8_t* Blob(size_t* size) const override {*size=sizeof(T); return reinterpret_cast<const int8_t*>(&val);}
public:
ObjectSimple() = delete;
ObjectSimple(T t):val(t) {}
ObjectSimple(const T* t):val(*t) {}
~ObjectSimple() {}
@ -215,7 +216,6 @@ public:
// Own functions
T Value() const {return val;}
void SetValue(T s) {val=s;}
};
// Simple objects
@ -238,21 +238,15 @@ private:
std::string name;
std::shared_ptr<const ObjectBase> val;
ObjectPair(const ObjectPair* p):name(p->name),val(p->val) {}
public:
ObjectPair() {}
ObjectPair(const std::string& n, const ObjectBase* v):name(n) {val.reset(v);}
ObjectPair(const std::string* n, const ObjectBase* v):name(*n) {val.reset(v);}
~ObjectPair() {}
ObjectPair() = delete;
ObjectPair(const std::string& n, const ObjectBase* v):name(n),val(v) {}
ObjectPair(const std::string* n, const ObjectBase* v):name(*n),val(v) {}
// Pure virtual overrides
const ObjectBase* Copy() const override
{
auto ret=new ObjectPair;
ret->name=name; ret->val=val;
return ret;
}
const ObjectBase* Copy() const override {return new ObjectPair(this);}
bool Print() const override
{
if(!Exist()) return false;
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl;
COUT(NORMAL)<<"Name is: "<<Name()<<std::endl;
COUT(NORMAL)<<"Value type: "<<val->Type()<<std::endl;
@ -264,20 +258,18 @@ public:
std::string Dump() const override { return Name()+"="+val->Dump(); }
// Own functions
bool Exist() const {return nullptr!=val.get();}
const ObjectBase* Get(const std::string& gname) const
{
if(gname==name) return val->Copy();
else return new ObjectError("ObjectPair Get","pair has name "+name+" not "+gname);
}
// This function is same as Get but return pointer on constant object
// This function is same as Get but return pointer on non-copied object (this pointer must not be deleted)
const ObjectBase* Find(const std::string& gname) const
{
if(gname==name) return val.get();
else return nullptr;
}
std::string Name() const {return name;}
void SetPair(const std::string& n, const ObjectBase* v) {if(!Exist()) {name=n; val.reset(v);}}
const ObjectBase* Value() const {return val.get();}
};
@ -289,20 +281,14 @@ public:
private:
std::shared_ptr<ListValues> vals;
ObjectList(const ObjectList* o):vals(o->vals) {}
public:
ObjectList() {vals.reset(new ListValues, [](ListValues* p){for(auto& i: *p) delete i; delete p;});}
ObjectList(const ObjectBase* o) {vals.reset(new ListValues, [](ListValues* p){for(auto& i: *p) delete i; delete p;}); PushBack(o);}
~ObjectList() {}
// Pure virtual overrides
const ObjectBase* Copy() const override
{
auto ret=new ObjectList;
ret->vals=vals;
return ret;
}
const ObjectBase* Copy() const override {return new ObjectList(this);}
bool Print() const override
{
if(!Exist()) return false;
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl;
COUT(NORMAL)<<"Number of elements: "<<Size()<<std::endl;
return true;
@ -320,17 +306,16 @@ public:
// Own functions
const ObjectBase* At(ListValues::size_type i) const {return (*vals)[i];}
bool Exist() const {return 0!=vals->size();}
const ObjectBase* Get(const std::string& gname) const
{
const ObjectBase* p=Find(gname);
return (nullptr==p)?new ObjectError("ObjectList Get","name "+gname+" not found in list"):p->Copy();
}
// This function is same as Get but return pointer on constant object
// This function is same as Get but return pointer on non-copied object (this pointer must not be deleted)
const ObjectBase* Find(const std::string& gname) const
{
const ObjectBase* p;
for(auto& i: *vals)
for(const auto& i: *vals)
{
p=nullptr;
OBType<ObjectPair> pair(i);

Loading…
Cancel
Save