16 #ifndef DABC_Reference
17 #define DABC_Reference
24 class ReferencesVector;
145 bool IsName(
const char* name)
const;
151 inline bool null()
const {
return GetObject() ==
nullptr; }
174 bool RemoveChild(
const char* name,
bool cleanup =
true);
202 void Print(
int lvl=0,
const char* from = 0)
const;
212 std::
string ItemName(
bool compact = true) const;
222 #define DABC_REFERENCE(RefClass, ParentClass, T) \
225 RefClass(T* obj = 0) throw() : ParentClass(obj) {} \
227 RefClass(const RefClass& src) throw() : ParentClass(src) {} \
229 RefClass(const Reference& src) throw() : ParentClass() \
230 { T* res(0); if (verify_object(src(),res)) { Assign(src); } } \
232 inline T* GetObject() const { return (T*) ParentClass::GetObject(); } \
234 inline T* operator()() const { return (T*) ParentClass::GetObject(); } \
236 RefClass& operator=(const RefClass& src) throw() { ParentClass::operator=(src); return *this; } \
238 RefClass& operator=(const Reference& src) throw() \
240 Release(); T* res(0); \
241 if (verify_object(src(),res)) Assign(src); \
245 RefClass& operator=(dabc::Object* obj) throw() \
247 Release(); T* res(0); \
248 if (verify_object(obj,res)) { RefClass ref((T*)obj); *this << ref; } \
252 RefClass& operator<<(Reference& src) throw() \
255 if (verify_object(src(),res)) dabc::Reference::operator<<(src); \
256 else { Release(); src.Release(); } \
Represents command with its arguments.
Base class for most of the DABC classes.
Reference on the arbitrary object
void SetObject(Object *obj, bool withmutex=true)
Direct set of object to reference.
bool AddChild(Object *obj)
Add child to list of object children.
void Release()
Releases reference on the object.
bool operator!=(const Reference &src) const
Compare operator - return true if references refer to different object.
Object * operator()() const
Return pointer on the object.
const char * ClassName() const
Return class name of referenced object, if object not assigned, returns "---".
const char * GetName() const
Return name of referenced object, if object not assigned, returns "---".
bool operator!=(Object *obj) const
Compare operator - return true if reference refer to different objects.
Reference GetParentRef() const
Returns reference on parent object.
Object * GetObject() const
Return pointer on the object.
virtual ~Reference()
Destructor, releases reference on the object.
Reference Take()
Copy reference to output object.
bool GetAllChildRef(ReferencesVector *vect) const
Return references for all childs.
Reference FindChild(const char *name) const
Searches for child in referenced object.
bool RemoveChilds(bool cleanup=true)
Remove all childs in referenced object If cleanup true (default) and object is owner,...
void Print(int lvl=0, const char *from=0) const
Show on debug output content of reference.
bool IsName(const char *name) const
Returns true if object name is the same as specified one.
unsigned NumReferences() const
Returns number of references on the object.
bool operator!() const
Returns true if reference contains nullptr.
bool operator==(Object *obj) const
Compare operator - return true if reference refer to same object.
Reference(Object *obj=nullptr)
Constructor, creates reference on the object.
bool operator==(const Reference &src) const
Compare operator - return true if references refer to same object.
Reference GetFolder(const std::string &name, bool force=false)
Return folder of specified name, no special symbols are allowed.
bool RemoveChild(const char *name, bool cleanup=true)
Remove child with given name and return reference on that child.
Reference & operator=(const Reference &src)
Assignment operator - copy reference.
Object * GetParent() const
Returns pointer on parent object.
unsigned NumChilds() const
Return number of childs in referenced object.
std::string RelativeName(const dabc::Reference &topitem)
Produce name, which can be used to find item, calling topitem.FindChild().
Object * fObj
pointer on the object
std::string ItemName(bool compact=true) const
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call.
void Assign(const Reference &src)
Method used in copy constructor and assigned operations.
bool AcquireRefWithoutMutex(Reference &ref)
Special method, which allows to generate new reference when object mutex is locked.
bool verify_object(Object *src, T *&tgt)
Method used in reference constructor/assignments to verify is object is suitable.
void Destroy()
Release reference and starts destroyment of referenced object.
Mutex * ObjectMutex() const
Reference GetChild(unsigned n) const
Return reference on child n.
void SetAutoDestroy(bool on=true)
Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will b...
Reference & operator<<(Reference &src)
Move operator - reference moved from source to target.
Vector of dabc::Reference objects.