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);
maxon::Int Int
Definition: ge_sys_math.h:64
#define DebugAssert(condition,...)
Definition: debugdiagnostics.h:248
#define DeleteObj(obj)
Definition: newobj.h:159
#define NewObj(T,...)
Definition: newobj.h:108
#define iferr_return
Definition: resultbase.h:1465

Classes

struct  WeakRawPtrProxy
 

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
 
WeakRawPtrProxy GetProxy () 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 ( void  ) const

Returns the target that is linked to the weak link.

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

◆ GetProxy()

WeakRawPtrProxy GetProxy ( ) const

Returns the target that is linked to the weak link.

Returns
Proxy for the 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