Support Class Library
A set of tools providing classes and utility
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
scl::utils::RawStorage< T > Class Template Reference

Class that handles raw storage (and manual memory management) for a variable type. More...

#include "RawStorage.h"

Public Member Functions

 RawStorage ()
 
 ~RawStorage ()
 
 RawStorage (RawStorage &&other)
 
RawStorageoperator= (RawStorage &&other)
 
template<class... Args>
T & constructor (Args &&... args)
 Construct the variable in the storage. More...
 
void destructor ()
 Call the destructor on the allocated object. More...
 
template<class... Args>
T & construct (Args &&... args)
 Alias for RawStorage::constructor. More...
 
void destroy ()
 Alias for RawStorage::destructor. More...
 
RawStoragereset ()
 Alias for RawStorage::destroy. More...
 
T & get ()
 Access the underlying data. More...
 
T & operator* ()
 Access the underlying data. More...
 
T * operator-> ()
 Get a pointer to the underlying data. More...
 
const T & get () const
 Get the value from a constant RawStorage (e.g. More...
 
const T & operator* () const
 Get the value from a constant RawStorage (e.g. More...
 
const T *const operator-> () const
 Get a pointer to the value from a constant RawStorage (e.g. More...
 
bool hasValue () const
 Determine whether or not the storage holds a value. More...
 
 operator bool () const
 Implicit conversion to bool. More...
 

Protected Types

using storage_type = scl::tools::meta ::aligned_storage_t< sizeof(T), alignof(T)>
 

Protected Member Functions

storage_typerawPtr ()
 
T * ptr ()
 

Protected Attributes

bool init
 Determines whether or not the object has been constructed. More...
 
storage_type storage
 The actual memory that can hold the variable. More...
 

Detailed Description

template<class T>
class scl::utils::RawStorage< T >

Class that handles raw storage (and manual memory management) for a variable type.

Template Parameters
Tbeing the variable to allocate storage for
Warning
Before using this, you must be certain this is what you're looking for

Definition at line 14 of file RawStorage.h.

Member Typedef Documentation

◆ storage_type

template<class T>
using scl::utils::RawStorage< T >::storage_type = scl::tools::meta ::aligned_storage_t<sizeof(T), alignof(T)>
protected

Definition at line 16 of file RawStorage.h.

Constructor & Destructor Documentation

◆ RawStorage() [1/2]

template<class T>
scl::utils::RawStorage< T >::RawStorage ( )
inline

Definition at line 39 of file RawStorage.h.

◆ ~RawStorage()

template<class T>
scl::utils::RawStorage< T >::~RawStorage ( )
inline

Definition at line 42 of file RawStorage.h.

◆ RawStorage() [2/2]

template<class T>
scl::utils::RawStorage< T >::RawStorage ( RawStorage< T > &&  other)
inline

Definition at line 46 of file RawStorage.h.

Member Function Documentation

◆ construct()

template<class T>
template<class... Args>
T& scl::utils::RawStorage< T >::construct ( Args &&...  args)
inline

Alias for RawStorage::constructor.

Definition at line 89 of file RawStorage.h.

◆ constructor()

template<class T>
template<class... Args>
T& scl::utils::RawStorage< T >::constructor ( Args &&...  args)
inline

Construct the variable in the storage.

Template Parameters
Argsbeing the types of arguments passed to the constructor
Parameters
argsbeing the arguments passed to the constructor
Returns
a mutable reference to the constructed object
Warning
Uses placement new
Cleans the memory if there was data (calls the destrutor)

Definition at line 67 of file RawStorage.h.

◆ destroy()

template<class T>
void scl::utils::RawStorage< T >::destroy ( )
inline

Alias for RawStorage::destructor.

Definition at line 96 of file RawStorage.h.

◆ destructor()

template<class T>
void scl::utils::RawStorage< T >::destructor ( )
inline

Call the destructor on the allocated object.

Warning
If non initialized, it is a no-op

Definition at line 78 of file RawStorage.h.

◆ get() [1/2]

template<class T>
T& scl::utils::RawStorage< T >::get ( )
inline

Access the underlying data.

Returns
a mutable reference to the underlying data
Exceptions
scl::exceptions::UninitializedMemoryAccess

Definition at line 114 of file RawStorage.h.

◆ get() [2/2]

template<class T>
const T& scl::utils::RawStorage< T >::get ( ) const
inline

Get the value from a constant RawStorage (e.g.

w/ a constant class that uses the storage)

Returns
an immutable reference to the underlying value

Definition at line 143 of file RawStorage.h.

◆ hasValue()

template<class T>
bool scl::utils::RawStorage< T >::hasValue ( ) const
inline

Determine whether or not the storage holds a value.

Returns
TRUE if it does, FALSE otherwise

Definition at line 170 of file RawStorage.h.

◆ operator bool()

template<class T>
scl::utils::RawStorage< T >::operator bool ( ) const
inline

Implicit conversion to bool.

Returns
TRUE if the storage holds a value, FALSE otherwise

Definition at line 178 of file RawStorage.h.

◆ operator*() [1/2]

template<class T>
T& scl::utils::RawStorage< T >::operator* ( )
inline

Access the underlying data.

Returns
a mutable reference to the underlying data
Exceptions
scl::exceptions::UninitializedMemoryAccess

Definition at line 126 of file RawStorage.h.

◆ operator*() [2/2]

template<class T>
const T& scl::utils::RawStorage< T >::operator* ( ) const
inline

Get the value from a constant RawStorage (e.g.

w/ a constant class that uses the storage)

Returns
an immutable reference to the underlying value

Definition at line 154 of file RawStorage.h.

◆ operator->() [1/2]

template<class T>
T* scl::utils::RawStorage< T >::operator-> ( )
inline

Get a pointer to the underlying data.

Returns
a mutable pointer to the underlying data
Exceptions
scl::exceptions::UninitializedMemoryAccess

Definition at line 135 of file RawStorage.h.

◆ operator->() [2/2]

template<class T>
const T* const scl::utils::RawStorage< T >::operator-> ( ) const
inline

Get a pointer to the value from a constant RawStorage (e.g.

w/ a constant class that uses the storage)

Returns
an immutable pointer to the underlying value

Definition at line 162 of file RawStorage.h.

◆ operator=()

template<class T>
RawStorage& scl::utils::RawStorage< T >::operator= ( RawStorage< T > &&  other)
inline

Definition at line 50 of file RawStorage.h.

◆ ptr()

template<class T>
T* scl::utils::RawStorage< T >::ptr ( )
inlineprotected

Definition at line 34 of file RawStorage.h.

◆ rawPtr()

template<class T>
storage_type* scl::utils::RawStorage< T >::rawPtr ( )
inlineprotected

Definition at line 30 of file RawStorage.h.

◆ reset()

template<class T>
RawStorage& scl::utils::RawStorage< T >::reset ( )
inline

Alias for RawStorage::destroy.

Returns
a reference to this RawStorage

Definition at line 104 of file RawStorage.h.

Member Data Documentation

◆ init

template<class T>
scl::utils::RawStorage< T >::init
protected

Determines whether or not the object has been constructed.

Definition at line 22 of file RawStorage.h.

◆ storage

template<class T>
scl::utils::RawStorage< T >::storage
protected

The actual memory that can hold the variable.

Definition at line 28 of file RawStorage.h.


The documentation for this class was generated from the following file: