|
|
@ -154,6 +154,8 @@ class OBTypeM<Func> |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::shared_ptr<const ObjectBase> ObjPtr; |
|
|
|
|
|
|
|
|
|
|
|
// Error class
|
|
|
|
// Error class
|
|
|
|
class EXPORT ObjectError: public ObjectBase |
|
|
|
class EXPORT ObjectError: public ObjectBase |
|
|
|
{ |
|
|
|
{ |
|
|
@ -215,7 +217,6 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
// Own functions
|
|
|
|
// Own functions
|
|
|
|
T Value() const {return val;} |
|
|
|
T Value() const {return val;} |
|
|
|
void SetValue(T s) {val=s;} |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Simple objects
|
|
|
|
// Simple objects
|
|
|
@ -236,23 +237,22 @@ class EXPORT ObjectPair: public ObjectBase |
|
|
|
{ |
|
|
|
{ |
|
|
|
private: |
|
|
|
private: |
|
|
|
std::string name; |
|
|
|
std::string name; |
|
|
|
std::shared_ptr<const ObjectBase> val; |
|
|
|
ObjPtr val; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectPair(const ObjectPair* p):name(p->name),val(p->val) {} |
|
|
|
public: |
|
|
|
public: |
|
|
|
ObjectPair() {} |
|
|
|
ObjectPair() = delete; |
|
|
|
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(std::string&& n, const ObjectBase* v):name(std::move(n)) {val.reset(v);} |
|
|
|
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(const std::string& n, const ObjPtr& v):name(n),val(v) {} |
|
|
|
// Pure virtual overrides
|
|
|
|
// Pure virtual overrides
|
|
|
|
const ObjectBase* Copy() const override |
|
|
|
const ObjectBase* Copy() const override |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto ret=new ObjectPair; |
|
|
|
return new ObjectPair(this); |
|
|
|
ret->name=name; ret->val=val; |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
bool Print() const override |
|
|
|
bool Print() const override |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!Exist()) return false; |
|
|
|
|
|
|
|
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl; |
|
|
|
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl; |
|
|
|
COUT(NORMAL)<<"Name is: "<<Name()<<std::endl; |
|
|
|
COUT(NORMAL)<<"Name is: "<<Name()<<std::endl; |
|
|
|
COUT(NORMAL)<<"Value type: "<<val->Type()<<std::endl; |
|
|
|
COUT(NORMAL)<<"Value type: "<<val->Type()<<std::endl; |
|
|
@ -264,20 +264,12 @@ public: |
|
|
|
std::string Dump() const override { return Name()+"="+val->Dump(); } |
|
|
|
std::string Dump() const override { return Name()+"="+val->Dump(); } |
|
|
|
|
|
|
|
|
|
|
|
// Own functions
|
|
|
|
// Own functions
|
|
|
|
bool Exist() const {return nullptr!=val.get();} |
|
|
|
|
|
|
|
const ObjectBase* Get(const std::string& gname) const |
|
|
|
const ObjectBase* Get(const std::string& gname) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(gname==name) return val->Copy(); |
|
|
|
if(gname==name) return val->Copy(); |
|
|
|
else return new ObjectError("ObjectPair Get","pair has name "+name+" not "+gname); |
|
|
|
else return new ObjectError("ObjectPair Get","pair has name "+name+" not "+gname); |
|
|
|
} |
|
|
|
} |
|
|
|
// 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 nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::string Name() const {return name;} |
|
|
|
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();} |
|
|
|
const ObjectBase* Value() const {return val.get();} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -285,24 +277,18 @@ public: |
|
|
|
class EXPORT ObjectList: public ObjectBase |
|
|
|
class EXPORT ObjectList: public ObjectBase |
|
|
|
{ |
|
|
|
{ |
|
|
|
public: |
|
|
|
public: |
|
|
|
typedef std::deque<const ObjectBase*> ListValues; |
|
|
|
typedef std::deque<ObjPtr> ListValues; |
|
|
|
private: |
|
|
|
private: |
|
|
|
std::shared_ptr<ListValues> vals; |
|
|
|
std::shared_ptr<ListValues> vals; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ObjectList(const ObjectList* l):vals(l->vals) {} |
|
|
|
public: |
|
|
|
public: |
|
|
|
ObjectList() {vals.reset(new ListValues, [](ListValues* p){for(auto& i: *p) delete i; delete p;});} |
|
|
|
ObjectList(): vals(std::make_shared<ListValues>()) {}; |
|
|
|
ObjectList(const ObjectBase* o) {vals.reset(new ListValues, [](ListValues* p){for(auto& i: *p) delete i; delete p;}); PushBack(o);} |
|
|
|
ObjectList(const ObjectBase* o): vals(std::make_shared<ListValues>()) {vals->push_back(ObjPtr(o));} |
|
|
|
~ObjectList() {} |
|
|
|
|
|
|
|
// Pure virtual overrides
|
|
|
|
// Pure virtual overrides
|
|
|
|
const ObjectBase* Copy() const override |
|
|
|
const ObjectBase* Copy() const override {return new ObjectList(this);} |
|
|
|
{ |
|
|
|
|
|
|
|
auto ret=new ObjectList; |
|
|
|
|
|
|
|
ret->vals=vals; |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
bool Print() const override |
|
|
|
bool Print() const override |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(!Exist()) return false; |
|
|
|
|
|
|
|
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl; |
|
|
|
COUT(NORMAL)<<std::endl<<"Object type: "<<Type()<<std::endl; |
|
|
|
COUT(NORMAL)<<"Number of elements: "<<Size()<<std::endl; |
|
|
|
COUT(NORMAL)<<"Number of elements: "<<Size()<<std::endl; |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -319,31 +305,26 @@ public: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Own functions
|
|
|
|
// Own functions
|
|
|
|
const ObjectBase* At(ListValues::size_type i) const {return (*vals)[i];} |
|
|
|
const ObjectBase* At(ListValues::size_type i) const {return (*vals)[i].get();} |
|
|
|
bool Exist() const {return 0!=vals->size();} |
|
|
|
|
|
|
|
const ObjectBase* Get(const std::string& gname) const |
|
|
|
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
|
|
|
|
|
|
|
|
const ObjectBase* Find(const std::string& gname) const |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
const ObjectBase* p; |
|
|
|
const ObjectBase* p; |
|
|
|
for(auto& i: *vals) |
|
|
|
for(const auto& i: *vals) |
|
|
|
{ |
|
|
|
{ |
|
|
|
p=nullptr; |
|
|
|
p=nullptr; |
|
|
|
OBType<ObjectPair> pair(i); |
|
|
|
OBType<ObjectPair> pair(i.get()); |
|
|
|
OBType<ObjectList> list(i); |
|
|
|
OBType<ObjectList> list(i.get()); |
|
|
|
if(pair) p=pair->Find(gname); |
|
|
|
if(pair) p=pair->Get(gname); |
|
|
|
else if(list) p=list->Find(gname); |
|
|
|
else if(list) p=list->Get(gname); |
|
|
|
if(nullptr!=p) return p; |
|
|
|
if(nullptr!=p) return p; |
|
|
|
} |
|
|
|
} |
|
|
|
return nullptr; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
ListValues::size_type Size() const {return vals->size();} |
|
|
|
ListValues::size_type Size() const {return vals->size();} |
|
|
|
ObjectList* PushBack(const ObjectBase* p) {vals->push_back(p); return this;} |
|
|
|
ObjectList* PushBack(const ObjectBase* p) {vals->push_back(ObjPtr(p)); return this;} |
|
|
|
ObjectList* PushFront(const ObjectBase* p) {vals->push_front(p); return this;} |
|
|
|
ObjectList* PushBack(const ObjPtr& p) {vals->push_back(p); return this;} |
|
|
|
|
|
|
|
ObjectList* PushFront(const ObjectBase* p) {vals->push_front(ObjPtr(p)); return this;} |
|
|
|
|
|
|
|
ObjectList* PushFront(const ObjPtr& p) {vals->push_front(p); return this;} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
typedef const ObjectBase* (*Func)(const ObjectList*); |
|
|
|
typedef const ObjectBase* (*Func)(const ObjectList*); |
|
|
|