|
|
|
@ -18,7 +18,33 @@ EXPORT std::ostream& COUT(debug_level dl);
|
|
|
|
|
|
|
|
|
|
typedef std::set<std::string> UsedType; |
|
|
|
|
|
|
|
|
|
class EXPORT ObjectBase; |
|
|
|
|
|
|
|
|
|
// Base class for all objects
|
|
|
|
|
class EXPORT ObjectBase |
|
|
|
|
{ |
|
|
|
|
protected: |
|
|
|
|
// No save by default
|
|
|
|
|
virtual const int8_t* Blob(size_t* size) const { *size=0; return 0; } |
|
|
|
|
virtual void DeallocBlob(const int8_t* ptr) const {}; |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
ObjectBase() = default; |
|
|
|
|
ObjectBase(const ObjectBase&) = delete; |
|
|
|
|
bool Save(const char* fname) const; |
|
|
|
|
// Pure virtual api
|
|
|
|
|
virtual ~ObjectBase(){} |
|
|
|
|
virtual ObjectBase* Copy() const=0; |
|
|
|
|
virtual bool Print() const=0; |
|
|
|
|
virtual std::string Type() const=0; |
|
|
|
|
|
|
|
|
|
// Virtual api with default functions. Modules types must not override them.
|
|
|
|
|
virtual std::string Dump() const {return "%"+Type()+"%";} |
|
|
|
|
virtual ObjectBase* Evaluate(bool* err) {*err=false; return 0;} |
|
|
|
|
virtual ObjectBase* ReplaceVar(const std::string& vname, ObjectBase* ob) {return 0;} |
|
|
|
|
virtual void UsedFuncs(UsedType& funcs) const {} |
|
|
|
|
virtual void UsedIdents(UsedType& ids) const {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Template for checking and using ObjectBase derivative classes
|
|
|
|
|
// Checking if arg is pointer on Derived: if(OBType<Derived>(arg))
|
|
|
|
@ -31,9 +57,10 @@ class OBType
|
|
|
|
|
OBType() = delete; |
|
|
|
|
OBType(OBType&&) = delete; |
|
|
|
|
OBType(OBType&) = delete; |
|
|
|
|
OBType(const ObjectBase* arg) {if(typeid(*arg)==typeid(O)) p=dynamic_cast<const O*>(arg); else p=0;} |
|
|
|
|
OBType(const ObjectBase* arg) {if(0==arg) p=0; else if(typeid(*arg)==typeid(O)) p=dynamic_cast<const O*>(arg); else p=0;} |
|
|
|
|
const O* operator->() const {return p;} |
|
|
|
|
operator bool() const {return 0!=p;} |
|
|
|
|
operator const O*() const {return p;} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,7 +94,7 @@ class OBTypeM<Func,O1,O...>: public OBTypeM<Func,O...>
|
|
|
|
|
else return OBTypeM<Func,O...>::template F<Res,Args...>(args...); |
|
|
|
|
} |
|
|
|
|
public: |
|
|
|
|
OBTypeM(const ObjectBase* arg):OBTypeM<Func,O...>(arg) {right=(typeid(*arg)==typeid(O1));} |
|
|
|
|
OBTypeM(const ObjectBase* arg):OBTypeM<Func,O...>(arg) {if(0==arg) right=false; else right=(typeid(*arg)==typeid(O1));} |
|
|
|
|
operator bool() const {return right || OBTypeM<Func,O...>::operator bool();} |
|
|
|
|
template<class Res, class... Args> |
|
|
|
|
bool Apply(Res& res, Args... args) const |
|
|
|
@ -106,33 +133,6 @@ class OBTypeM<Func>
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Base class for all objects
|
|
|
|
|
class EXPORT ObjectBase |
|
|
|
|
{ |
|
|
|
|
protected: |
|
|
|
|
// No save by default
|
|
|
|
|
virtual const int8_t* Blob(size_t* size) const { *size=0; return 0; } |
|
|
|
|
virtual void DeallocBlob(const int8_t* ptr) const {}; |
|
|
|
|
public: |
|
|
|
|
|
|
|
|
|
ObjectBase() = default; |
|
|
|
|
ObjectBase(const ObjectBase&) = delete; |
|
|
|
|
bool Save(const char* fname) const; |
|
|
|
|
// Pure virtual api
|
|
|
|
|
virtual ~ObjectBase(){} |
|
|
|
|
virtual ObjectBase* Copy() const=0; |
|
|
|
|
virtual bool Print() const=0; |
|
|
|
|
virtual std::string Type() const=0; |
|
|
|
|
|
|
|
|
|
// Virtual api with default functions. Modules types must not override them.
|
|
|
|
|
virtual std::string Dump() const {return "%"+Type()+"%";} |
|
|
|
|
virtual ObjectBase* Evaluate(bool* err) {*err=false; return 0;} |
|
|
|
|
virtual ObjectBase* ReplaceVar(const std::string& vname, ObjectBase* ob) {return 0;} |
|
|
|
|
virtual void UsedFuncs(UsedType& funcs) const {} |
|
|
|
|
virtual void UsedIdents(UsedType& ids) const {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Template for objects without specific constructor/destructor
|
|
|
|
|
template<class T> |
|
|
|
|
class EXPORT ObjectSimple: public ObjectBase |
|
|
|
|