WeakRawPtr< TYPE > Class Template Reference

#include <weakrawptr.h>

Detailed Description

template<typename TYPE>
class maxon::WeakRawPtr< TYPE >

WeakRawPtr allows to create weak references to all memory blocks and objects created with NewObj() or NewMem().

Note
: in multithreaded use it might happen that the destructor of the object is already called but the memory block is still linked.
WeakRawPtr<Int> link;
link.Set(rawPtr);
Int* get01 = link.Get();
DebugAssert(get01 != nullptr);
DeleteObj(rawPtr);
Int* get02 = link.Get();
DebugAssert(get02 == nullptr);

Public Member Functions

 WeakRawPtr ()=default
 
MAXON_IMPLICIT WeakRawPtr (TYPE *target)
 
 WeakRawPtr (const WeakRawPtr &c)
 
 WeakRawPtr (WeakRawPtr &&src)
 
 MAXON_OPERATOR_MOVE_ASSIGNMENT (WeakRawPtr)
 
 MAXON_OPERATOR_COPY_ASSIGNMENT (WeakRawPtr)
 
TYPE * Get () const
 
void Set (TYPE *target)
 

Private Attributes

WeakRefBase _weakRef
 

Constructor & Destructor Documentation

◆ WeakRawPtr() [1/4]

WeakRawPtr ( )
default

Default constructor.

◆ WeakRawPtr() [2/4]

MAXON_IMPLICIT WeakRawPtr ( TYPE *  target)

Explicit constructor to create the weak link with the connected target.

◆ WeakRawPtr() [3/4]

WeakRawPtr ( const WeakRawPtr< TYPE > &  c)

Copy constructor.

◆ WeakRawPtr() [4/4]

WeakRawPtr ( WeakRawPtr< TYPE > &&  src)

Move constructor.

Member Function Documentation

◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( WeakRawPtr< TYPE >  )

◆ MAXON_OPERATOR_COPY_ASSIGNMENT()

MAXON_OPERATOR_COPY_ASSIGNMENT ( WeakRawPtr< TYPE >  )

◆ Get()

TYPE* Get ( ) const

Returns the target that is linked to the weak link.

Returns
Target pointer, otherwise nullptr if the object was freed in the meanwhile.

◆ Set()

void Set ( TYPE *  target)

Sets a new target to the weak link.

Parameters
[in]targetObject to be linked.

Member Data Documentation

◆ _weakRef

WeakRefBase _weakRef
private
DeleteObj
#define DeleteObj(obj)
Definition: newobj.h:159
Int
maxon::Int Int
Definition: ge_sys_math.h:64
iferr_return
#define iferr_return
Definition: resultbase.h:1465
NewObj
#define NewObj(T,...)
Definition: newobj.h:108
DebugAssert
#define DebugAssert(condition,...)
Definition: debugdiagnostics.h:246