DABC (Data Acquisition Backbone Core)  2.9.9
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
dabc::Reference Class Reference

Reference on the arbitrary object More...

#include <dabc/Reference.h>

Inheritance diagram for dabc::Reference:
dabc::Buffer dabc::EventsIteratorRef dabc::EventsProducerRef dabc::History dabc::LocalTransportRef dabc::LocalWorkerRef dabc::Record dabc::ThreadRef dabc::WorkerAddonRef dabc::WorkerRef verbs::ContextRef verbs::PoolRegistryRef

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...
 
ObjectGetObject () const
 Return pointer on the object. More...
 
ObjectGetParent () 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...
 
Objectoperator() () const
 Return pointer on the object. More...
 
Referenceoperator<< (Reference &src) throw ()
 Move operator - reference moved from source to target. More...
 
Referenceoperator= (const Reference &src) throw ()
 Assignment operator - copy reference. More...
 
Referenceoperator= (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...
 
MutexObjectMutex () 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

ObjectfObj
 pointer on the object More...
 

Friends

class Command
 
class Object
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Reference() [1/2]

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.

◆ Reference() [2/2]

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.

◆ ~Reference()

dabc::Reference::~Reference ( )
virtual

Destructor, releases reference on the object.

Definition at line 133 of file Reference.cxx.

Member Function Documentation

◆ ObjectMutex()

dabc::Mutex * dabc::Reference::ObjectMutex ( ) const
protected

Definition at line 183 of file Reference.cxx.

◆ Assign()

void dabc::Reference::Assign ( const Reference src)
protected

Method used in copy constructor and assigned operations.

Definition at line 50 of file Reference.cxx.

◆ AcquireRefWithoutMutex()

bool dabc::Reference::AcquireRefWithoutMutex ( Reference ref)
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.

◆ verify_object()

template<class T >
bool dabc::Reference::verify_object ( Object src,
T *&  tgt 
)
inlineprotected

Method used in reference constructor/assignments to verify is object is suitable.

Definition at line 93 of file Reference.h.

◆ SetAutoDestroy()

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.

◆ SetObject()

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.

◆ NumReferences()

unsigned dabc::Reference::NumReferences ( ) const

Returns number of references on the object.

Definition at line 112 of file Reference.cxx.

◆ Release()

void dabc::Reference::Release ( )
throw (
)

Releases reference on the object.

Definition at line 138 of file Reference.cxx.

◆ Take()

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.

◆ Destroy()

void dabc::Reference::Destroy ( )
throw (
)

Release reference and starts destroyment of referenced object.

Definition at line 148 of file Reference.cxx.

◆ GetObject()

Object* dabc::Reference::GetObject ( ) const
inline

Return pointer on the object.

Definition at line 129 of file Reference.h.

◆ GetParent()

dabc::Object * dabc::Reference::GetParent ( ) const

Returns pointer on parent object.

Definition at line 162 of file Reference.cxx.

◆ GetParentRef()

Reference dabc::Reference::GetParentRef ( ) const
inline

Returns reference on parent object.

Definition at line 135 of file Reference.h.

◆ GetName()

const char * dabc::Reference::GetName ( ) const

Return name of referenced object, if object not assigned, returns "---".

Definition at line 167 of file Reference.cxx.

◆ ClassName()

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.

◆ IsName()

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.

◆ operator()()

Object* dabc::Reference::operator() ( ) const
inline

Return pointer on the object.

Definition at line 148 of file Reference.h.

◆ null()

bool dabc::Reference::null ( ) const
inline

Returns true if reference contains nullptr.

Definition at line 151 of file Reference.h.

◆ operator!()

bool dabc::Reference::operator! ( ) const
inline

Returns true if reference contains nullptr.

Definition at line 154 of file Reference.h.

◆ AddChild()

bool dabc::Reference::AddChild ( Object obj)

Add child to list of object children.

Definition at line 188 of file Reference.cxx.

◆ NumChilds()

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.

◆ GetChild()

dabc::Reference dabc::Reference::GetChild ( unsigned  n) const

Return reference on child n.

Definition at line 199 of file Reference.cxx.

◆ GetAllChildRef()

bool dabc::Reference::GetAllChildRef ( ReferencesVector vect) const

Return references for all childs.

Definition at line 204 of file Reference.cxx.

◆ FindChild()

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.

◆ RemoveChild()

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.

◆ RemoveChilds()

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.

◆ operator=() [1/2]

dabc::Reference & dabc::Reference::operator= ( const Reference src)
throw (
)

Assignment operator - copy reference.

Definition at line 64 of file Reference.cxx.

◆ operator=() [2/2]

dabc::Reference & dabc::Reference::operator= ( Object obj)
throw (
)

Assignment operator - copy reference.

Definition at line 75 of file Reference.cxx.

◆ operator<<()

dabc::Reference & dabc::Reference::operator<< ( Reference src)
throw (
)

Move operator - reference moved from source to target.

Definition at line 88 of file Reference.cxx.

◆ operator==() [1/2]

bool dabc::Reference::operator== ( const Reference src) const
inline

Compare operator - return true if references refer to same object.

Definition at line 190 of file Reference.h.

◆ operator!=() [1/2]

bool dabc::Reference::operator!= ( const Reference src) const
inline

Compare operator - return true if references refer to different object.

Definition at line 193 of file Reference.h.

◆ operator==() [2/2]

bool dabc::Reference::operator== ( Object obj) const
inline

Compare operator - return true if reference refer to same object.

Definition at line 196 of file Reference.h.

◆ operator!=() [2/2]

bool dabc::Reference::operator!= ( Object obj) const
inline

Compare operator - return true if reference refer to different objects.

Definition at line 199 of file Reference.h.

◆ Print()

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.

◆ GetFolder()

dabc::Reference dabc::Reference::GetFolder ( const std::string &  name,
bool  force = false 
)
throw (
)

Return folder of specified name, no special symbols are allowed.

Parameters
[in]namerequested folder name
[in]forceif true, missing folder will be created
Returns
reference on the folder

Definition at line 234 of file Reference.cxx.

◆ ItemName()

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.

◆ RelativeName()

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.

Friends And Related Function Documentation

◆ Object

friend class Object
friend

Definition at line 75 of file Reference.h.

◆ Command

friend class Command
friend

Definition at line 76 of file Reference.h.

Field Documentation

◆ fObj

Object* dabc::Reference::fObj
protected

pointer on the object

Definition at line 80 of file Reference.h.


The documentation for this class was generated from the following files: