diff --git a/include/common.h b/include/common.h index d62e9dc..5d9b4b3 100644 --- a/include/common.h +++ b/include/common.h @@ -189,6 +189,7 @@ private: const int8_t* Blob(size_t* size) const override {*size=sizeof(T); return reinterpret_cast(&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 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)<Type()< 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)<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 pair(i);