CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::SharedMemory Class Referencefinal

#include <CeresEngine/Foundation/SharedMemory.hpp>

Public Types

enum class  AccessMode { Read , Write }
 This is used to determine whether to create a read-only or a read-write memory mapping. More...
 
using NativeHandle = int
 A type that represents the native shared memory handle.
 
using Reference = Byte &
 A type that represents a reference in the memory mapped file.
 
using ConstReference = const Byte &
 A type that represents a reference in the memory mapped file.
 
using Pointer = Byte *
 A type that represents a pointer in the memory mapped file.
 
using ConstPointer = Byte const *
 A type that represents a pointer in the memory mapped file.
 
using SizeType = std::uintmax_t
 A type that represents the mapping length and offsets.
 

Public Member Functions

 SharedMemory ()
 Creates a new unmapped SharedMemory object.
 
 SharedMemory (const FilePath &path, AccessMode mode=AccessMode::Read)
 Creates a new SharedMemory by mapping the file given path.
 
 SharedMemory (const FilePath &path, SizeType size, AccessMode mode=AccessMode::Read)
 Creates a new SharedMemory by mapping the file given path.
 
 SharedMemory (const SharedMemory &)=delete
 Copy of a SharedMemory is not allowed.
 
SharedMemoryoperator= (const SharedMemory &)=delete
 Copy assignment of a SharedMemory is not allowed.
 
 SharedMemory (SharedMemory &&other) noexcept
 Creates a new SharedMemory by moving the contents of another.
 
SharedMemoryoperator= (SharedMemory &&other) noexcept
 Assigns the SharedMemory by moving the contents of another.
 
 ~SharedMemory () noexcept
 Unloads the mapped file (if loaded) and destroy the SharedMemory object.
 
Pointer data () noexcept
 
ConstPointer data () const noexcept
 
Reference at (const SizeType index) noexcept
 
ConstReference at (const SizeType index) const noexcept
 
Reference front () noexcept
 
ConstReference front () const noexcept
 
Reference back () noexcept
 
ConstReference back () const noexcept
 
size_t size () const noexcept
 
size_t capacity () const noexcept
 
bool empty () const noexcept
 
bool valid () const noexcept
 
void resize (SizeType newSize)
 Resizes the array to fit at least newSize elements.
 
void sync ()
 Synchronizes any dirty data not synchronized with the file.
 
void reset ()
 Closes any handle and unmaps all memory.
 
Pointer begin () noexcept
 
ConstPointer begin () const noexcept
 
ConstPointer cbegin () const noexcept
 
Pointer end () noexcept
 
ConstPointer end () const noexcept
 
ConstPointer cend () const noexcept
 
 operator bool () const noexcept
 
Reference operator[] (SizeType offset) noexcept
 
ConstReference operator[] (SizeType offset) const noexcept
 

Private Member Functions

void map (SizeType size)
 Maps the file into memory.
 
void unmap ()
 Unmaps the file into memory.
 

Private Attributes

FilePath mPath
 The path of the memory mapped file.
 
NativeHandle mHandle = NativeHandle()
 The native handle used to manage the shared memory.
 
Pointer mAddress = nullptr
 The base address to the mapped memory.
 
AccessMode mMode = AccessMode::Read
 The mode the file was mapped with.
 
SizeType mLength = 0
 

Member Typedef Documentation

◆ ConstPointer

A type that represents a pointer in the memory mapped file.

◆ ConstReference

A type that represents a reference in the memory mapped file.

◆ NativeHandle

A type that represents the native shared memory handle.

◆ Pointer

A type that represents a pointer in the memory mapped file.

◆ Reference

A type that represents a reference in the memory mapped file.

◆ SizeType

A type that represents the mapping length and offsets.

Member Enumeration Documentation

◆ AccessMode

This is used to determine whether to create a read-only or a read-write memory mapping.

Enumerator
Read 
Write 

Constructor & Destructor Documentation

◆ SharedMemory() [1/5]

CeresEngine::SharedMemory::SharedMemory ( )

Creates a new unmapped SharedMemory object.

◆ SharedMemory() [2/5]

CeresEngine::SharedMemory::SharedMemory ( const FilePath path,
AccessMode  mode = AccessMode::Read 
)
explicit

Creates a new SharedMemory by mapping the file given path.

Parameters
pathThe file path
modeThe mapping mode to be used

◆ SharedMemory() [3/5]

CeresEngine::SharedMemory::SharedMemory ( const FilePath path,
SizeType  size,
AccessMode  mode = AccessMode::Read 
)
explicit

Creates a new SharedMemory by mapping the file given path.

Parameters
pathThe file path
sizeThe mapped file initial size
modeThe mapping mode to be used

◆ SharedMemory() [4/5]

CeresEngine::SharedMemory::SharedMemory ( const SharedMemory )
delete

Copy of a SharedMemory is not allowed.

◆ SharedMemory() [5/5]

CeresEngine::SharedMemory::SharedMemory ( SharedMemory &&  other)
noexcept

Creates a new SharedMemory by moving the contents of another.

Parameters
otherThe instance to move from

◆ ~SharedMemory()

CeresEngine::SharedMemory::~SharedMemory ( )
noexcept

Unloads the mapped file (if loaded) and destroy the SharedMemory object.

Member Function Documentation

◆ at() [1/2]

ConstReference CeresEngine::SharedMemory::at ( const SizeType  index) const
inlinenoexcept
Parameters
indexThe byte index
Returns
A reference to the first element

◆ at() [2/2]

Reference CeresEngine::SharedMemory::at ( const SizeType  index)
inlinenoexcept
Parameters
indexThe byte index
Returns
A reference to the first element

◆ back() [1/2]

ConstReference CeresEngine::SharedMemory::back ( ) const
inlinenoexcept
Returns
A reference to the last element

◆ back() [2/2]

Reference CeresEngine::SharedMemory::back ( )
inlinenoexcept
Returns
A reference to the last element

◆ begin() [1/2]

ConstPointer CeresEngine::SharedMemory::begin ( ) const
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ begin() [2/2]

Pointer CeresEngine::SharedMemory::begin ( )
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ capacity()

size_t CeresEngine::SharedMemory::capacity ( ) const
noexcept
Returns
The number of elements in the mapped file.

◆ cbegin()

ConstPointer CeresEngine::SharedMemory::cbegin ( ) const
inlinenoexcept
Returns
A pointer to the beginning of the file data

◆ cend()

ConstPointer CeresEngine::SharedMemory::cend ( ) const
inlinenoexcept
Returns
A pointer to the past the end of the file data

◆ data() [1/2]

ConstPointer CeresEngine::SharedMemory::data ( ) const
noexcept
Returns
A pointer to the beginning of the file data

◆ data() [2/2]

Pointer CeresEngine::SharedMemory::data ( )
noexcept
Returns
A pointer to the beginning of the file data

◆ empty()

bool CeresEngine::SharedMemory::empty ( ) const
noexcept
Returns
Checks if the container has no elements

◆ end() [1/2]

ConstPointer CeresEngine::SharedMemory::end ( ) const
inlinenoexcept
Returns
A pointer to the past the end of the file data

◆ end() [2/2]

Pointer CeresEngine::SharedMemory::end ( )
inlinenoexcept
Returns
A pointer to the past the end of the file data

◆ front() [1/2]

ConstReference CeresEngine::SharedMemory::front ( ) const
inlinenoexcept
Returns
A reference to the first element

◆ front() [2/2]

Reference CeresEngine::SharedMemory::front ( )
inlinenoexcept
Returns
A reference to the first element

◆ map()

void CeresEngine::SharedMemory::map ( SizeType  size)
private

Maps the file into memory.

◆ operator bool()

CeresEngine::SharedMemory::operator bool ( ) const
explicitnoexcept
Returns
true if the SharedMemory is valid and points to a mapped file.

◆ operator=() [1/2]

SharedMemory & CeresEngine::SharedMemory::operator= ( const SharedMemory )
delete

Copy assignment of a SharedMemory is not allowed.

◆ operator=() [2/2]

SharedMemory & CeresEngine::SharedMemory::operator= ( SharedMemory &&  other)
noexcept

Assigns the SharedMemory by moving the contents of another.

Parameters
otherThe instance to move from
Returns
*this

◆ operator[]() [1/2]

ConstReference CeresEngine::SharedMemory::operator[] ( SizeType  offset) const
noexcept
Parameters
offsetThe amount of bytes to offset from the beginning.
Returns
A pointer to the data of the mapped file offsetted by offset.

◆ operator[]() [2/2]

Reference CeresEngine::SharedMemory::operator[] ( SizeType  offset)
noexcept
Parameters
offsetThe amount of bytes to offset from the beginning.
Returns
A pointer to the data of the mapped file offsetted by offset.

◆ reset()

void CeresEngine::SharedMemory::reset ( )

Closes any handle and unmaps all memory.

◆ resize()

void CeresEngine::SharedMemory::resize ( SizeType  newSize)

Resizes the array to fit at least newSize elements.

Parameters
newSizeThe number of elements in the array.

◆ size()

size_t CeresEngine::SharedMemory::size ( ) const
noexcept
Returns
The number of elements in the mapped file.

◆ sync()

void CeresEngine::SharedMemory::sync ( )

Synchronizes any dirty data not synchronized with the file.

◆ unmap()

void CeresEngine::SharedMemory::unmap ( )
private

Unmaps the file into memory.

◆ valid()

bool CeresEngine::SharedMemory::valid ( ) const
noexcept
Returns
true if the SharedMemory is valid and points to a mapped file.

Member Data Documentation

◆ mAddress

Pointer CeresEngine::SharedMemory::mAddress = nullptr
private

The base address to the mapped memory.

◆ mHandle

NativeHandle CeresEngine::SharedMemory::mHandle = NativeHandle()
private

The native handle used to manage the shared memory.

◆ mLength

SizeType CeresEngine::SharedMemory::mLength = 0
private

◆ mMode

AccessMode CeresEngine::SharedMemory::mMode = AccessMode::Read
private

The mode the file was mapped with.

◆ mPath

FilePath CeresEngine::SharedMemory::mPath
private

The path of the memory mapped file.


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