GenericDataTemplate< REFCOUNTED > Class Template Reference

#include <genericdata.h>

Detailed Description

template<Bool REFCOUNTED>
class maxon::GenericDataTemplate< REFCOUNTED >

GenericData wraps an object of arbitary type. Therefore it's similar to Data, but it supports less operations:

  • GenericData can be moved, but it can't be copied.
  • The destructor of the wrapped object is called properly.
  • You can obtain the wrapped object with Get, but you have to know it's exact type at compile-time.
  • You can't query the type at runtime.

The advantage is that you don't need to register the type of the wrapped object as a DataType.

Public Types

using CopyType = typename std::conditional< REFCOUNTED, GenericDataTemplate, DummyParamType >::type
 

Public Member Functions

 GenericDataTemplate ()=default
 
 GenericDataTemplate (GenericDataTemplate &&src)
 
 MAXON_OPERATOR_MOVE_ASSIGNMENT (GenericDataTemplate)
 
 GenericDataTemplate (const CopyType &src)
 
GenericDataTemplateoperator= (const CopyType &src)
 
void Reset ()
 
 ~GenericDataTemplate ()
 
template<typename T >
Result< void > Set (T &&value)
 
Bool IsEmpty () const
 
Bool IsPopulated () const
 
template<typename T >
const T & Get () const
 
template<typename T >
ConstIf< T, REFCOUNTED >::typeGet ()
 
template<typename T >
Result< typename ConstIf< T, REFCOUNTED >::type & > GetOrCreate ()
 
template<typename T >
Result< T & > Create ()
 
const void * GetPointer () const
 
void * GetPointer ()
 

Private Member Functions

void RemoveRef ()
 
void AddRef ()
 

Static Private Member Functions

template<typename T >
static void Free (GenericDataTemplate *v)
 

Private Attributes

void * _ptr
 
void(* _free )(GenericDataTemplate *)
 

Member Typedef Documentation

◆ CopyType

using CopyType = typename std::conditional<REFCOUNTED, GenericDataTemplate, DummyParamType>::type

Constructor & Destructor Documentation

◆ GenericDataTemplate() [1/3]

GenericDataTemplate ( )
default

Constructs an empty GenericData.

◆ GenericDataTemplate() [2/3]

GenericDataTemplate ( GenericDataTemplate< REFCOUNTED > &&  src)

Constructs a GenericData by moving the contents of src to the new GenericData. src will be an empty GenericData afterwards.

Parameters
[in,out]srcThe source object.

◆ GenericDataTemplate() [3/3]

GenericDataTemplate ( const CopyType src)
explicit

◆ ~GenericDataTemplate()

Destructs this GenericData. This frees any previously set value.

Member Function Documentation

◆ MAXON_OPERATOR_MOVE_ASSIGNMENT()

MAXON_OPERATOR_MOVE_ASSIGNMENT ( GenericDataTemplate< REFCOUNTED >  )

◆ operator=()

GenericDataTemplate& operator= ( const CopyType src)

◆ Reset()

void Reset ( )

Resets this GenericData to an empty object. This frees any previously set value.

◆ Set()

Result<void> Set ( T &&  value)

Initializes this GenericData with value. This frees any previously set value at first.

Parameters
[in]valueThe value to wrap.
Returns
OK on success.

◆ IsEmpty()

Bool IsEmpty ( ) const

Checks if this GenericData is empty.

Returns
True if this GenericData has no wrapped value, false otherwise.

◆ IsPopulated()

Bool IsPopulated ( ) const

Checks if this GenericData has a wrapped value.

Returns
True if this GenericData has a wrapped value, false otherwise.

◆ Get() [1/2]

const T& Get ( ) const

Returns the wrapped value. The type T has to match the exact type of the wrapped value, otherwise the behaviour is undetermined. There is no check that the type matches.

Template Parameters
TThe type of the wrapped value.
Returns
The wrapped value of type T.

◆ Get() [2/2]

ConstIf<T, REFCOUNTED>::type& Get ( )

Returns the wrapped value. The type T has to match the exact type of the wrapped value, otherwise the behaviour is undetermined. There is no check that the type matches.

Template Parameters
TThe type of the wrapped value.
Returns
The wrapped value of type T.

◆ GetOrCreate()

Result<typename ConstIf<T, REFCOUNTED>::type&> GetOrCreate ( )

◆ Create()

Result<T&> Create ( )

◆ GetPointer() [1/2]

const void* GetPointer ( ) const

Returns a pointer to the wrapped value.

Returns
Pointer to the wrapped values.

◆ GetPointer() [2/2]

void* GetPointer ( )

Returns a pointer to the wrapped value.

Returns
Pointer to the wrapped values.

◆ Free()

static void Free ( GenericDataTemplate< REFCOUNTED > *  v)
staticprivate

◆ RemoveRef()

void RemoveRef ( )
private

◆ AddRef()

void AddRef ( )
private

Member Data Documentation

◆ _ptr

void* _ptr
private

◆ _free

void(* _free) (GenericDataTemplate *)
private