CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::TSharedMemory< T > Class Template Reference

A helper class that maps a file into memory and allows accessing it as a regular C++ struct. More...

#include <CeresEngine/Foundation/SharedMemory.hpp>

Public Member Functions

 TSharedMemory ()
 Creates a new unmapped TSharedMemory object.
 
 TSharedMemory (const FilePath &path, const SharedMemory::AccessMode mode=SharedMemory::AccessMode::Read)
 Creates a new TSharedMemory by mapping the file given path.
 
 TSharedMemory (const SharedMemory &)=delete
 Copy of a TSharedMemory is not allowed.
 
TSharedMemoryoperator= (const TSharedMemory &)=delete
 Copy assignment of a TSharedMemory is not allowed.
 
 TSharedMemory (TSharedMemory &&other) noexcept=default
 Creates a new TSharedMemory by moving the contents of another.
 
TSharedMemoryoperator= (TSharedMemory &&other) noexcept=default
 Assigns the TSharedMemory by moving the contents of another.
 
Tget () noexcept
 
const Tget () const noexcept
 
Tdata () noexcept
 
const Tdata () const noexcept
 
bool valid () const noexcept
 
void sync ()
 Synchronizes any dirty data not synchronized with the file.
 
void reset ()
 Closes any handle and unmaps all memory.
 
 operator bool () const noexcept
 
Toperator-> ()
 
const Toperator-> () const
 
Toperator* ()
 
const Toperator* () const
 

Public Attributes

SharedMemory sharedMemory
 The underlying shared memory object.
 

Static Public Attributes

static const constexpr size_t minimumLength = sizeof(T)
 The minimum size of the mapped file to fit an object of type T.
 

Detailed Description

template<typename T>
class CeresEngine::TSharedMemory< T >

A helper class that maps a file into memory and allows accessing it as a regular C++ struct.

Files mapped through TSharedMemory are not compatible across builds or platforms.

Template Parameters
Tthe mapped object type

Constructor & Destructor Documentation

◆ TSharedMemory() [1/4]

template<typename T >
CeresEngine::TSharedMemory< T >::TSharedMemory ( )
inline

Creates a new unmapped TSharedMemory object.

◆ TSharedMemory() [2/4]

template<typename T >
CeresEngine::TSharedMemory< T >::TSharedMemory ( const FilePath path,
const SharedMemory::AccessMode  mode = SharedMemory::AccessMode::Read 
)
inlineexplicit

Creates a new TSharedMemory by mapping the file given path.

Parameters
pathThe file path
modeThe shared memory access mode

◆ TSharedMemory() [3/4]

template<typename T >
CeresEngine::TSharedMemory< T >::TSharedMemory ( const SharedMemory )
delete

Copy of a TSharedMemory is not allowed.

◆ TSharedMemory() [4/4]

template<typename T >
CeresEngine::TSharedMemory< T >::TSharedMemory ( TSharedMemory< T > &&  other)
defaultnoexcept

Creates a new TSharedMemory by moving the contents of another.

Parameters
otherThe instance to move from

Member Function Documentation

◆ data() [1/2]

template<typename T >
const T * CeresEngine::TSharedMemory< T >::data ( ) const
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ data() [2/2]

template<typename T >
T * CeresEngine::TSharedMemory< T >::data ( )
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ get() [1/2]

template<typename T >
const T * CeresEngine::TSharedMemory< T >::get ( ) const
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ get() [2/2]

template<typename T >
T * CeresEngine::TSharedMemory< T >::get ( )
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ operator bool()

template<typename T >
CeresEngine::TSharedMemory< T >::operator bool ( ) const
inlineexplicitnoexcept
Returns
true if the SharedMemory is valid and points to a mapped file.

◆ operator*() [1/2]

template<typename T >
T & CeresEngine::TSharedMemory< T >::operator* ( )
inline
Returns
A reference to the mapped object memory.

◆ operator*() [2/2]

template<typename T >
const T & CeresEngine::TSharedMemory< T >::operator* ( ) const
inline
Returns
A reference to the mapped object memory.

◆ operator->() [1/2]

template<typename T >
T * CeresEngine::TSharedMemory< T >::operator-> ( )
inline
Returns
A pointer to the mapped object memory.

◆ operator->() [2/2]

template<typename T >
const T * CeresEngine::TSharedMemory< T >::operator-> ( ) const
inline
Returns
A pointer to the mapped object memory.

◆ operator=() [1/2]

Copy assignment of a TSharedMemory is not allowed.

◆ operator=() [2/2]

template<typename T >
TSharedMemory & CeresEngine::TSharedMemory< T >::operator= ( TSharedMemory< T > &&  other)
defaultnoexcept

Assigns the TSharedMemory by moving the contents of another.

Parameters
otherThe instance to move from
Returns
*this

◆ reset()

template<typename T >
void CeresEngine::TSharedMemory< T >::reset ( )
inline

Closes any handle and unmaps all memory.

◆ sync()

template<typename T >
void CeresEngine::TSharedMemory< T >::sync ( )
inline

Synchronizes any dirty data not synchronized with the file.

◆ valid()

template<typename T >
bool CeresEngine::TSharedMemory< T >::valid ( ) const
inlinenoexcept
Returns
true if the SharedMemory is valid and points to a mapped file.

Member Data Documentation

◆ minimumLength

template<typename T >
const constexpr size_t CeresEngine::TSharedMemory< T >::minimumLength = sizeof(T)
staticconstexpr

The minimum size of the mapped file to fit an object of type T.

◆ sharedMemory

template<typename T >
SharedMemory CeresEngine::TSharedMemory< T >::sharedMemory

The underlying shared memory object.


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