CopyWrapper< T > Class Template Reference

#include <movecopywrapper.h>

Detailed Description

template<typename T>
class maxon::CopyWrapper< T >

This wrapper helps to capture objects which require CopyFrom() in a lambda. The get method will return an error if copying the object into the wrapper failed. Of course move construction and assignment are supported too.

Template Parameters
TType of object to wrapped.
JobRef EnqueueSendJob(const BaseArray<Char>& jobdata)
{
[this, copy = CopyWrapper<BaseArray<Char>>(jobdata)]() -> Result<void>
{
const BaseArray<Char>& array = copy.Get() iferr_return;
return _stream.Write(array.GetFirst(), array.GetCount());
},
_queue);
}
CopyWrapper()
Definition: movecopywrapper.h:35
JobRef & Enqueue(JobQueueInterface *queue=JOBQUEUE_CURRENT)
Definition: job.h:1369
#define iferr_scope
Definition: resultbase.h:1386
#define iferr_return
Definition: resultbase.h:1521

Public Member Functions

 CopyWrapper ()
 
 CopyWrapper (const T &src)
 
 CopyWrapper (T &&src)
 
 CopyWrapper (const CopyWrapper &src)
 
 CopyWrapper (CopyWrapper &&src)
 
CopyWrapperoperator= (const CopyWrapper &src)
 
CopyWrapperoperator= (CopyWrapper &&src)
 
ResultRef< const T > Get () const
 
ResultRef< T > Get ()
 

Private Attributes

_value
 
T * _ptr
 

Constructor & Destructor Documentation

◆ CopyWrapper() [1/5]

◆ CopyWrapper() [2/5]

CopyWrapper ( const T &  src)
explicit

Copies the source object into the wrapper. Get() will return an error if the copy failed.

Parameters
[in]srcObject to be copied into the wrapper.

◆ CopyWrapper() [3/5]

CopyWrapper ( T &&  src)
explicit

Moves the source object into the wrapper. Following Get()s will succeed because the move can't fail.

Parameters
[in]srcObject to be moved into the wrapper.

◆ CopyWrapper() [4/5]

CopyWrapper ( const CopyWrapper< T > &  src)

Copies the source wrapper. Get() will return an error if the copy failed.

Parameters
[in]srcWrapper to be copied.

◆ CopyWrapper() [5/5]

CopyWrapper ( CopyWrapper< T > &&  src)

Moves the source wrapper. Following Get()s will succeed because the move can't fail.

Parameters
[in]srcWrapper to be moved.

Member Function Documentation

◆ operator=() [1/2]

CopyWrapper& operator= ( const CopyWrapper< T > &  src)

Copy assigns the source wrapper. Get() will return an error if the copy failed.

Parameters
[in]srcWrapper to be copied.

◆ operator=() [2/2]

CopyWrapper& operator= ( CopyWrapper< T > &&  src)

Move assign the source wrapper. Following Get()s will succeed because the move can't fail.

Parameters
[in]srcWrapper to be moved.

◆ Get() [1/2]

ResultRef<const T> Get ( ) const

Returns a reference to the wrapped object if the assignment or construction of the wrapper was successful.

Returns
Reference to wrapped object on success, error on failure.

◆ Get() [2/2]

ResultRef<T> Get ( )

Returns a reference to the wrapped object if the assignment or construction of the wrapper was successful.

Returns
Reference to wrapped object on success, error on failure.

Member Data Documentation

◆ _value

T _value
mutableprivate

◆ _ptr

T* _ptr
private