|
|
@ -39,7 +39,7 @@ class EXPORT ObjectBase |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
bool err; |
|
|
|
bool err; |
|
|
|
// No save by default
|
|
|
|
// No save by default
|
|
|
|
virtual const int8_t* Blob(size_t* size) const { *size=0; return 0; } |
|
|
|
virtual const int8_t* Blob(size_t* size) const { *size=0; return nullptr; } |
|
|
|
virtual void DeallocBlob(const int8_t* ptr) const {}; |
|
|
|
virtual void DeallocBlob(const int8_t* ptr) const {}; |
|
|
|
ObjectBase():err(false) {} |
|
|
|
ObjectBase():err(false) {} |
|
|
|
public: |
|
|
|
public: |
|
|
@ -57,6 +57,7 @@ class EXPORT ObjectBase |
|
|
|
virtual std::string Dump() const {return "%"+Type()+"%";} |
|
|
|
virtual std::string Dump() const {return "%"+Type()+"%";} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum class OBTypeErr {OK,NULLPTR,TYPEMISMATCH}; |
|
|
|
|
|
|
|
|
|
|
|
// Template for checking and using ObjectBase derivative classes
|
|
|
|
// Template for checking and using ObjectBase derivative classes
|
|
|
|
// Checking if arg is non-zero: if(OBType<Derived>(arg).Exist())
|
|
|
|
// Checking if arg is non-zero: if(OBType<Derived>(arg).Exist())
|
|
|
@ -71,11 +72,12 @@ class OBType |
|
|
|
OBType() = delete; |
|
|
|
OBType() = delete; |
|
|
|
OBType(OBType&&) = delete; |
|
|
|
OBType(OBType&&) = delete; |
|
|
|
OBType(OBType&) = delete; |
|
|
|
OBType(OBType&) = delete; |
|
|
|
OBType(const ObjectBase* arg):iszero(0==arg) {if(0==arg) p=0; else if(typeid(*arg)==typeid(O)) p=dynamic_cast<const O*>(arg); else p=0;} |
|
|
|
OBType(const ObjectBase* arg):iszero(nullptr==arg) {if(nullptr==arg) p=nullptr; else if(typeid(*arg)==typeid(O)) p=dynamic_cast<const O*>(arg); else p=nullptr;} |
|
|
|
const O* operator->() const {return p;} |
|
|
|
const O* operator->() const {return p;} |
|
|
|
operator bool() const {return 0!=p;} |
|
|
|
operator bool() const {return nullptr!=p;} |
|
|
|
operator const O*() const {return p;} |
|
|
|
operator const O*() const {return p;} |
|
|
|
bool Exist() const {return !iszero;} |
|
|
|
bool Exist() const {return !iszero;} |
|
|
|
|
|
|
|
OBTypeErr Error() const {if(iszero) return OBTypeErr::NULLPTR; else if(nullptr==p) return OBTypeErr::TYPEMISMATCH; else return OBTypeErr::OK;} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -110,7 +112,7 @@ class OBTypeM<Func,O1,O...>: public OBTypeM<Func,O...> |
|
|
|
else return OBTypeM<Func,O...>::template F<Res,Args...>(args...); |
|
|
|
else return OBTypeM<Func,O...>::template F<Res,Args...>(args...); |
|
|
|
} |
|
|
|
} |
|
|
|
public: |
|
|
|
public: |
|
|
|
OBTypeM(const ObjectBase* arg):OBTypeM<Func,O...>(arg) {if(0==arg) right=false; else right=(typeid(*arg)==typeid(O1));} |
|
|
|
OBTypeM(const ObjectBase* arg):OBTypeM<Func,O...>(arg) {if(nullptr==arg) right=false; else right=(typeid(*arg)==typeid(O1));} |
|
|
|
operator bool() const {return right || OBTypeM<Func,O...>::operator bool();} |
|
|
|
operator bool() const {return right || OBTypeM<Func,O...>::operator bool();} |
|
|
|
template<class Res, class... Args> |
|
|
|
template<class Res, class... Args> |
|
|
|
bool Apply(Res& res, Args... args) const |
|
|
|
bool Apply(Res& res, Args... args) const |
|
|
@ -127,6 +129,7 @@ class OBTypeM<Func,O1,O...>: public OBTypeM<Func,O...> |
|
|
|
else return OBTypeM<Func,O...>::template F<T,Args...>(args...); |
|
|
|
else return OBTypeM<Func,O...>::template F<T,Args...>(args...); |
|
|
|
} |
|
|
|
} |
|
|
|
bool Exist() const {return OBTypeM<Func,O...>::Exist();} |
|
|
|
bool Exist() const {return OBTypeM<Func,O...>::Exist();} |
|
|
|
|
|
|
|
OBTypeErr Error() const {if(!Exist()) return OBTypeErr::NULLPTR; else if(!operator bool()) return OBTypeErr::TYPEMISMATCH; else return OBTypeErr::OK;} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Partial instantiation of the bottom of recursion
|
|
|
|
// Partial instantiation of the bottom of recursion
|
|
|
@ -147,7 +150,7 @@ class OBTypeM<Func> |
|
|
|
void operator ()(Args... args) const {} |
|
|
|
void operator ()(Args... args) const {} |
|
|
|
template<class Res, class... Args> |
|
|
|
template<class Res, class... Args> |
|
|
|
Res F(Args... args) const {return Res();} |
|
|
|
Res F(Args... args) const {return Res();} |
|
|
|
bool Exist() const {return 0!=p;} |
|
|
|
bool Exist() const {return nullptr!=p;} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -261,17 +264,17 @@ 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 0!=val.get();} |
|
|
|
bool Exist() const {return nullptr!=val.get();} |
|
|
|
ObjectBase* Get(const std::string& gname) const |
|
|
|
ObjectBase* Get(const std::string& gname) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(gname==name) return val->Copy(); |
|
|
|
if(gname==name) return val->Copy(); |
|
|
|
else return 0; |
|
|
|
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 constant object
|
|
|
|
const ObjectBase* Find(const std::string& gname) const |
|
|
|
const ObjectBase* Find(const std::string& gname) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(gname==name) return val.get(); |
|
|
|
if(gname==name) return val.get(); |
|
|
|
else return 0; |
|
|
|
else return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
std::string Name() const {return name;} |
|
|
|
std::string Name() const {return name;} |
|
|
|
void SetPair(const std::string& n, ObjectBase* v) {if(!Exist()) {name=n; val.reset(v);}} |
|
|
|
void SetPair(const std::string& n, ObjectBase* v) {if(!Exist()) {name=n; val.reset(v);}} |
|
|
@ -321,7 +324,7 @@ public: |
|
|
|
ObjectBase* Get(const std::string& gname) const |
|
|
|
ObjectBase* Get(const std::string& gname) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
const ObjectBase* p=Find(gname); |
|
|
|
const ObjectBase* p=Find(gname); |
|
|
|
return (0==p)?0:p->Copy(); |
|
|
|
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 constant object
|
|
|
|
const ObjectBase* Find(const std::string& gname) const |
|
|
|
const ObjectBase* Find(const std::string& gname) const |
|
|
@ -329,14 +332,14 @@ public: |
|
|
|
const ObjectBase* p; |
|
|
|
const ObjectBase* p; |
|
|
|
for(auto& i: *vals) |
|
|
|
for(auto& i: *vals) |
|
|
|
{ |
|
|
|
{ |
|
|
|
p=0; |
|
|
|
p=nullptr; |
|
|
|
OBType<ObjectPair> pair(i); |
|
|
|
OBType<ObjectPair> pair(i); |
|
|
|
OBType<ObjectList> list(i); |
|
|
|
OBType<ObjectList> list(i); |
|
|
|
if(pair) p=pair->Find(gname); |
|
|
|
if(pair) p=pair->Find(gname); |
|
|
|
else if(list) p=list->Find(gname); |
|
|
|
else if(list) p=list->Find(gname); |
|
|
|
if(0!=p) return p; |
|
|
|
if(nullptr!=p) return p; |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
ListValues::size_type Size() const {return vals->size();} |
|
|
|
ListValues::size_type Size() const {return vals->size();} |
|
|
|
ObjectList* PushBack(ObjectBase* p) {vals->push_back(p); return this;} |
|
|
|
ObjectList* PushBack(ObjectBase* p) {vals->push_back(p); return this;} |
|
|
@ -354,10 +357,11 @@ EXPORT int LoadModule(const std::string& name, const void* p, const std::string& |
|
|
|
template<class T> |
|
|
|
template<class T> |
|
|
|
ObjectBase* Get(const ObjectList* input) |
|
|
|
ObjectBase* Get(const ObjectList* input) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(input->Size()!=2) return 0; |
|
|
|
if(input->Size()!=2) return new ObjectError("GET","incorrect number of arguments"); |
|
|
|
OBType<T> ob(input->At(0)); |
|
|
|
OBType<T> ob(input->At(0)); |
|
|
|
OBType<ObjectString> name(input->At(1)); |
|
|
|
OBType<ObjectString> name(input->At(1)); |
|
|
|
if(!(ob && name)) return 0; |
|
|
|
if(!name) return new ObjectError("GET","second argument is not ObjectString"); |
|
|
|
|
|
|
|
if(!ob) return new ObjectError("GET","incorrect type of first argument"); |
|
|
|
|
|
|
|
|
|
|
|
return ob->Get(name->Value()); |
|
|
|
return ob->Get(name->Value()); |
|
|
|
} |
|
|
|
} |
|
|
|