DABC (Data Acquisition Backbone Core)
2.9.9
|
Reference on the arbitrary object More...
#include <dabc/Reference.h>
Public Member Functions | |
bool | AddChild (Object *obj) |
Add child to list of object children. More... | |
const char * | ClassName () const |
Return class name of referenced object, if object not assigned, returns "---". More... | |
void | Destroy () throw () |
Release reference and starts destroyment of referenced object. More... | |
Reference | FindChild (const char *name) const |
Searches for child in referenced object. More... | |
bool | GetAllChildRef (ReferencesVector *vect) const |
Return references for all childs. More... | |
Reference | GetChild (unsigned n) const |
Return reference on child n. More... | |
Reference | GetFolder (const std::string &name, bool force=false) throw () |
Return folder of specified name, no special symbols are allowed. More... | |
const char * | GetName () const |
Return name of referenced object, if object not assigned, returns "---". More... | |
Object * | GetObject () const |
Return pointer on the object. More... | |
Object * | GetParent () const |
Returns pointer on parent object. More... | |
Reference | GetParentRef () const |
Returns reference on parent object. More... | |
bool | IsName (const char *name) const |
Returns true if object name is the same as specified one. More... | |
std::string | ItemName (bool compact=true) const |
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call. More... | |
bool | null () const |
Returns true if reference contains nullptr. More... | |
unsigned | NumChilds () const |
Return number of childs in referenced object. More... | |
unsigned | NumReferences () const |
Returns number of references on the object. More... | |
bool | operator! () const |
Returns true if reference contains nullptr. More... | |
bool | operator!= (const Reference &src) const |
Compare operator - return true if references refer to different object. More... | |
bool | operator!= (Object *obj) const |
Compare operator - return true if reference refer to different objects. More... | |
Object * | operator() () const |
Return pointer on the object. More... | |
Reference & | operator<< (Reference &src) throw () |
Move operator - reference moved from source to target. More... | |
Reference & | operator= (const Reference &src) throw () |
Assignment operator - copy reference. More... | |
Reference & | operator= (Object *obj) throw () |
Assignment operator - copy reference. More... | |
bool | operator== (const Reference &src) const |
Compare operator - return true if references refer to same object. More... | |
bool | operator== (Object *obj) const |
Compare operator - return true if reference refer to same object. More... | |
void | Print (int lvl=0, const char *from=0) const |
Show on debug output content of reference. More... | |
Reference (const Reference &src) throw () | |
Copy constructor, if source is transient than source reference will be emptied. More... | |
Reference (Object *obj=nullptr) | |
Constructor, creates reference on the object. More... | |
std::string | RelativeName (const dabc::Reference &topitem) |
Produce name, which can be used to find item, calling topitem.FindChild(). More... | |
void | Release () throw () |
Releases reference on the object. More... | |
bool | RemoveChild (const char *name, bool cleanup=true) |
Remove child with given name and return reference on that child. More... | |
bool | RemoveChilds (bool cleanup=true) |
Remove all childs in referenced object If cleanup true (default) and object is owner, all objects will be destroyed. More... | |
void | SetAutoDestroy (bool on=true) |
Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared. More... | |
void | SetObject (Object *obj, bool withmutex=true) |
Direct set of object to reference. More... | |
Reference | Take () |
Copy reference to output object. More... | |
virtual | ~Reference () |
Destructor, releases reference on the object. More... | |
Protected Member Functions | |
bool | AcquireRefWithoutMutex (Reference &ref) |
Special method, which allows to generate new reference when object mutex is locked. More... | |
void | Assign (const Reference &src) |
Method used in copy constructor and assigned operations. More... | |
Mutex * | ObjectMutex () const |
template<class T > | |
bool | verify_object (Object *src, T *&tgt) |
Method used in reference constructor/assignments to verify is object is suitable. More... | |
Protected Attributes | |
Object * | fObj |
pointer on the object More... | |
Friends | |
class | Command |
class | Object |
Reference on the arbitrary object
Ensure that object on which reference is pointing on is not disappear until reference is existing. In normal situation one should use reference in form:
void func(Object* obj) { dabc::Reference ref(new Object); ref.SetAutoDestroy(true); ref()->Print(); }
When function is finishing its work, reference will be automatically released. If autodestroy flag was specified, object also will be destroyed.
Reference object cannot be used from several threads simultaneously, one should create new reference to work such way
When derived class should be created, DABC_REFERENCE macro could be used. For instance:
class WorkerRef : public Reference { DABC_REFERENCE(WorkerRef, Reference, Worker)
public: bool Execute(const std::string &cmdname) { return GetObject() ? GetObject()->Execute(cmdname) : false; } };
Macro defines all nice-to-have methods which should be presented in the reference class - default constructor, copy constructor, assignment operator, shift operator, some other.
Typically such reference class should be a friend for object class to have access to the object protected-private methods and members.
Main motivation for such class is to provide thread-safe methods via references. Once user acquire reference on the object, it can use any methods referenced object has. Methods, implemented in object class, generally should be protected and only can be used from class itself.
Definition at line 73 of file Reference.h.
dabc::Reference::Reference | ( | Object * | obj = nullptr | ) |
Constructor, creates reference on the object.
If not possible, exception is thrown
Definition at line 25 of file Reference.cxx.
dabc::Reference::Reference | ( | const Reference & | src | ) | |
throw | ( | ||||
) |
Copy constructor, if source is transient than source reference will be emptied.
Definition at line 58 of file Reference.cxx.
|
virtual |
Destructor, releases reference on the object.
Definition at line 133 of file Reference.cxx.
|
protected |
Definition at line 183 of file Reference.cxx.
|
protected |
Method used in copy constructor and assigned operations.
Definition at line 50 of file Reference.cxx.
|
protected |
Special method, which allows to generate new reference when object mutex is locked.
It may be necessary when non-recursive mutexes are used.
Definition at line 123 of file Reference.cxx.
|
inlineprotected |
Method used in reference constructor/assignments to verify is object is suitable.
Definition at line 93 of file Reference.h.
void dabc::Reference::SetAutoDestroy | ( | bool | on = true | ) |
Set autodestroy flag for the object Once enabled, object will be destroyed when last reference will be cleared.
Definition at line 118 of file Reference.cxx.
void dabc::Reference::SetObject | ( | Object * | obj, |
bool | withmutex = true |
||
) |
Direct set of object to reference.
withmutex = false means that user already lock object mutex
Definition at line 37 of file Reference.cxx.
unsigned dabc::Reference::NumReferences | ( | ) | const |
Returns number of references on the object.
Definition at line 112 of file Reference.cxx.
void dabc::Reference::Release | ( | ) | ||
throw | ( | |||
) |
Releases reference on the object.
Definition at line 138 of file Reference.cxx.
dabc::Reference dabc::Reference::Take | ( | ) |
Copy reference to output object.
Source reference will be empty after the call. One probably could use left shift operator - this will save many intermediate operations
Definition at line 102 of file Reference.cxx.
void dabc::Reference::Destroy | ( | ) | ||
throw | ( | |||
) |
Release reference and starts destroyment of referenced object.
Definition at line 148 of file Reference.cxx.
|
inline |
Return pointer on the object.
Definition at line 129 of file Reference.h.
dabc::Object * dabc::Reference::GetParent | ( | ) | const |
Returns pointer on parent object.
Definition at line 162 of file Reference.cxx.
|
inline |
Returns reference on parent object.
Definition at line 135 of file Reference.h.
const char * dabc::Reference::GetName | ( | ) | const |
Return name of referenced object, if object not assigned, returns "---".
Definition at line 167 of file Reference.cxx.
const char * dabc::Reference::ClassName | ( | ) | const |
Return class name of referenced object, if object not assigned, returns "---".
Definition at line 172 of file Reference.cxx.
bool dabc::Reference::IsName | ( | const char * | name | ) | const |
Returns true if object name is the same as specified one.
If object not assigned, always return false.
Definition at line 177 of file Reference.cxx.
|
inline |
Return pointer on the object.
Definition at line 148 of file Reference.h.
|
inline |
Returns true if reference contains nullptr.
Definition at line 151 of file Reference.h.
|
inline |
Returns true if reference contains nullptr.
Definition at line 154 of file Reference.h.
bool dabc::Reference::AddChild | ( | Object * | obj | ) |
Add child to list of object children.
Definition at line 188 of file Reference.cxx.
unsigned dabc::Reference::NumChilds | ( | ) | const |
Return number of childs in referenced object.
If object null, always return 0
Definition at line 194 of file Reference.cxx.
dabc::Reference dabc::Reference::GetChild | ( | unsigned | n | ) | const |
Return reference on child n.
Definition at line 199 of file Reference.cxx.
bool dabc::Reference::GetAllChildRef | ( | ReferencesVector * | vect | ) | const |
Return references for all childs.
Definition at line 204 of file Reference.cxx.
dabc::Reference dabc::Reference::FindChild | ( | const char * | name | ) | const |
Searches for child in referenced object.
If object null, always return null reference
Definition at line 210 of file Reference.cxx.
bool dabc::Reference::RemoveChild | ( | const char * | name, |
bool | cleanup = true |
||
) |
Remove child with given name and return reference on that child.
Definition at line 215 of file Reference.cxx.
bool dabc::Reference::RemoveChilds | ( | bool | cleanup = true | ) |
Remove all childs in referenced object If cleanup true (default) and object is owner, all objects will be destroyed.
Definition at line 223 of file Reference.cxx.
dabc::Reference & dabc::Reference::operator= | ( | const Reference & | src | ) | |
throw | ( | ||||
) |
Assignment operator - copy reference.
Definition at line 64 of file Reference.cxx.
dabc::Reference & dabc::Reference::operator= | ( | Object * | obj | ) | |
throw | ( | ||||
) |
Assignment operator - copy reference.
Definition at line 75 of file Reference.cxx.
dabc::Reference & dabc::Reference::operator<< | ( | Reference & | src | ) | |
throw | ( | ||||
) |
Move operator - reference moved from source to target.
Definition at line 88 of file Reference.cxx.
|
inline |
Compare operator - return true if references refer to same object.
Definition at line 190 of file Reference.h.
|
inline |
Compare operator - return true if references refer to different object.
Definition at line 193 of file Reference.h.
|
inline |
Compare operator - return true if reference refer to same object.
Definition at line 196 of file Reference.h.
|
inline |
Compare operator - return true if reference refer to different objects.
Definition at line 199 of file Reference.h.
void dabc::Reference::Print | ( | int | lvl = 0 , |
const char * | from = 0 |
||
) | const |
Show on debug output content of reference.
Definition at line 229 of file Reference.cxx.
dabc::Reference dabc::Reference::GetFolder | ( | const std::string & | name, |
bool | force = false |
||
) | |||
throw | ( | ||
) |
Return folder of specified name, no special symbols are allowed.
[in] | name | requested folder name |
[in] | force | if true, missing folder will be created |
Definition at line 234 of file Reference.cxx.
std::string dabc::Reference::ItemName | ( | bool | compact = true | ) | const |
Produce string, which can be used as name argument in dabc::mgr.FindItem(name) call.
Definition at line 241 of file Reference.cxx.
std::string dabc::Reference::RelativeName | ( | const dabc::Reference & | topitem | ) |
Produce name, which can be used to find item, calling topitem.FindChild().
topitem should be one of the parent TODO: one should be able to calculate relative name with any pairs of objects
Definition at line 248 of file Reference.cxx.
|
friend |
Definition at line 75 of file Reference.h.
|
friend |
Definition at line 76 of file Reference.h.
|
protected |
pointer on the object
Definition at line 80 of file Reference.h.