openDAQ
Open data acquisition platform
IWeakRef Struct Referenceabstract

Represents a weak reference to the object. More...

+ Inheritance diagram for IWeakRef:
+ Collaboration diagram for IWeakRef:

Detailed Description

Represents a weak reference to the object.

Obtain a weak reference to the object when you want to store it to a local variable and don't want to increment the reference count. Weak reference will not prevent object destruction. Before the object is used, you must obtain a true reference by calling getRef or getRefAs.

Example

// get weak reference from obj and store it to weakRef
IWeakRef* weakRef;
auto err = obj->queryInterface(IWeakRef::ID, reinterpret_cast<void**>(&weakRef));
if (OPENDAQ_FAILED(err))
return;
// .
// .
// .
// get true reference from weak reference
// this will fail if the obj reference count dropped to zero and the object was destroyed
IBaseObject* newRefToObj;
err = weakRef->getRef(&newRefToObj);
if (OPENDAQ_FAILED(err))
return;
// do something with newRefToObj
// release it when no longer needed
newRefToObj->releaseRef()
// .
// .
// when weak reference is no longer needed, release it
weakRef->releaseRef();

Public Member Functions

virtual ErrCode INTERFACE_FUNC getRef (IBaseObject **object)=0
 Gets a true reference to the object as IBaseObject interface. More...
 
virtual ErrCode INTERFACE_FUNC getRefAs (IntfID intfID, void **object)=0
 Gets a true reference to the object with specified interface ID. More...
 
- Public Member Functions inherited from IBaseObject
virtual ErrCode INTERFACE_FUNC borrowInterface (const IntfID &intfID, void **obj) const =0
 Returns another interface which is supported by the object without incrementing the reference count. More...
 
virtual ErrCode INTERFACE_FUNC dispose ()=0
 Disposes all references held by the object. More...
 
virtual ErrCode INTERFACE_FUNC getHashCode (SizeT *hashCode)=0
 Returns hash code of the object. More...
 
virtual ErrCode INTERFACE_FUNC equals (IBaseObject *other, Bool *equal) const =0
 Compares object to another object for equality. More...
 
virtual ErrCode INTERFACE_FUNC toString (CharPtr *str)=0
 Returns a string representation of the object. More...
 
- Public Member Functions inherited from IUnknown
virtual ErrCode INTERFACE_FUNC queryInterface (const IntfID &intfID, void **obj)=0
 Returns another interface which is supported by the object and increments the reference count. More...
 
virtual int INTERFACE_FUNC addRef ()=0
 Increments the reference count for an interface on an object. More...
 
virtual int INTERFACE_FUNC releaseRef ()=0
 Decrements the reference count for an interface on an object. More...
 

Member Function Documentation

◆ getRef()

virtual ErrCode INTERFACE_FUNC getRef ( IBaseObject **  object)
pure virtual

Gets a true reference to the object as IBaseObject interface.

Parameters
[out]objectA true reference to the object.

After you get a true reference to the object, you need to call releaseRef. on object interface.

◆ getRefAs()

virtual ErrCode INTERFACE_FUNC getRefAs ( IntfID  intfID,
void **  object 
)
pure virtual

Gets a true reference to the object with specified interface ID.

Parameters
intfIDID of the requested interface
[out]objectA true reference to the object.

After you get a true reference to the object, you need to call releaseRef. on object interface.

IUnknown::queryInterface
virtual ErrCode INTERFACE_FUNC queryInterface(const IntfID &intfID, void **obj)=0
Returns another interface which is supported by the object and increments the reference count.
IWeakRef::getRef
virtual ErrCode INTERFACE_FUNC getRef(IBaseObject **object)=0
Gets a true reference to the object as IBaseObject interface.
IBaseObject
Definition: baseobject.h:117
IWeakRef
Represents a weak reference to the object.
Definition: weakref.h:64
IUnknown::releaseRef
virtual int INTERFACE_FUNC releaseRef()=0
Decrements the reference count for an interface on an object.