Cogs.Core
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Cogs::Memory::MemoryBuffer Class Reference
Inheritance diagram for Cogs::Memory::MemoryBuffer:
Cogs::Network::Message

Public Types

enum class  Anchor { Start , Current , End }
 

Public Member Functions

 MemoryBuffer (MemBlockType type)
 
 MemoryBuffer (size_t size, MemBlockType type)
 
 MemoryBuffer (size_t size, bool onlyReserve=false, MemBlockType type=MemBlockType::Block)
 
 MemoryBuffer (Allocator *allocator, MemBlockType type=MemBlockType::Block)
 
 MemoryBuffer (size_t size, Allocator *allocator, MemBlockType type=MemBlockType::Block)
 
 MemoryBuffer (const void *memory, size_t size)
 
 MemoryBuffer (MemoryBuffer &&other) noexcept
 
MemoryBufferoperator= (MemoryBuffer &&other) noexcept
 
 MemoryBuffer (const MemoryBuffer &)=delete
 
MemoryBufferoperator= (const MemoryBuffer &)=delete
 
void changeType (MemBlockType newType)
 
void reset (size_t size, Allocator *allocator)
 
bool resize (size_t size, bool keep=true, bool forceRealloc=false)
 
bool reserve (size_t size)
 
void copy (const MemoryBuffer &other)
 
void clear ()
 
void * data ()
 
const void * data () const
 
void * dataFromPos ()
 
const void * dataFromPos () const
 
size_t size () const
 
bool empty () const
 
void * grow (size_t bytes)
 
void swap (MemoryBuffer &other)
 
const AllocatorgetAllocator () const
 
size_t read (void *buffer, size_t noofbytes)
 
uint8_t read8 ()
 
uint16_t read16 ()
 
uint32_t read32 ()
 
uint64_t read64 ()
 
float readFloat ()
 
double readDouble ()
 
glm::vec2 readFloat2 ()
 
glm::vec3 readFloat3 ()
 
glm::vec4 readFloat4 ()
 
glm::quat readQuaternion ()
 
glm::mat4 readMatrix ()
 
std::string readString ()
 
bool write (const void *buffer, size_t noofbytes)
 
bool write8 (uint8_t value)
 
bool write16 (uint16_t value)
 
bool write32 (uint32_t value)
 
bool write64 (uint64_t value)
 
bool writeFloat (float value)
 
bool writeDouble (double value)
 
bool writeFloat2 (const glm::vec2 &value)
 
bool writeFloat3 (const glm::vec3 &value)
 
bool writeFloat4 (const glm::vec4 &value)
 
bool writeQuaternion (const glm::quat &value)
 
bool writeMatrix (const glm::mat4 &value)
 
bool writeString (const StringView &str)
 
void seek (int64_t offset, Anchor from)
 
size_t pos () const
 
size_t unreadSize () const
 
bool areContentsEqual (const MemoryBuffer &rhs) const
 

Private Member Functions

void release ()
 
template<typename T >
readImpl ()
 

Private Attributes

void * buffer = nullptr
 
size_t currentSize = 0
 
size_t storageSize = 0
 
size_t currentPos = 0
 
Allocatorallocator = Allocator::defaultAllocator()
 
MemBlockType type = MemBlockType::Block
 

Detailed Description

Definition at line 22 of file MemoryBuffer.h.

Member Enumeration Documentation

◆ Anchor

enum class Cogs::Memory::MemoryBuffer::Anchor
strong

Definition at line 25 of file MemoryBuffer.h.

Constructor & Destructor Documentation

◆ MemoryBuffer() [1/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( MemBlockType  type)
inline

Definition at line 34 of file MemoryBuffer.h.

◆ MemoryBuffer() [2/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( size_t  size,
MemBlockType  type 
)
inline

Definition at line 36 of file MemoryBuffer.h.

◆ MemoryBuffer() [3/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( size_t  size,
bool  onlyReserve = false,
MemBlockType  type = MemBlockType::Block 
)
inline

Definition at line 38 of file MemoryBuffer.h.

◆ MemoryBuffer() [4/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( Allocator allocator,
MemBlockType  type = MemBlockType::Block 
)
inline

Definition at line 49 of file MemoryBuffer.h.

◆ MemoryBuffer() [5/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( size_t  size,
Allocator allocator,
MemBlockType  type = MemBlockType::Block 
)
inline

Definition at line 53 of file MemoryBuffer.h.

◆ MemoryBuffer() [6/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( const void *  memory,
size_t  size 
)

Definition at line 54 of file MemoryBuffer.cpp.

◆ MemoryBuffer() [7/7]

Cogs::Memory::MemoryBuffer::MemoryBuffer ( MemoryBuffer &&  other)
inlinenoexcept

Definition at line 61 of file MemoryBuffer.h.

◆ ~MemoryBuffer()

Cogs::Memory::MemoryBuffer::~MemoryBuffer ( )
inline

Definition at line 99 of file MemoryBuffer.h.

Member Function Documentation

◆ areContentsEqual()

bool Cogs::Memory::MemoryBuffer::areContentsEqual ( const MemoryBuffer rhs) const

Definition at line 292 of file MemoryBuffer.cpp.

◆ changeType()

void Cogs::Memory::MemoryBuffer::changeType ( MemBlockType  newType)

Definition at line 310 of file MemoryBuffer.cpp.

◆ clear()

void Cogs::Memory::MemoryBuffer::clear ( )
inline

Definition at line 113 of file MemoryBuffer.h.

◆ copy()

void Cogs::Memory::MemoryBuffer::copy ( const MemoryBuffer other)

Definition at line 123 of file MemoryBuffer.cpp.

◆ data() [1/2]

void * Cogs::Memory::MemoryBuffer::data ( )
inline

Definition at line 115 of file MemoryBuffer.h.

◆ data() [2/2]

const void * Cogs::Memory::MemoryBuffer::data ( ) const
inline

Definition at line 116 of file MemoryBuffer.h.

◆ dataFromPos() [1/2]

void * Cogs::Memory::MemoryBuffer::dataFromPos ( )
inline

Definition at line 118 of file MemoryBuffer.h.

◆ dataFromPos() [2/2]

const void * Cogs::Memory::MemoryBuffer::dataFromPos ( ) const
inline

Definition at line 119 of file MemoryBuffer.h.

◆ empty()

bool Cogs::Memory::MemoryBuffer::empty ( ) const
inline

Definition at line 122 of file MemoryBuffer.h.

◆ getAllocator()

const Allocator * Cogs::Memory::MemoryBuffer::getAllocator ( ) const
inline

Definition at line 139 of file MemoryBuffer.h.

◆ grow()

void * Cogs::Memory::MemoryBuffer::grow ( size_t  bytes)
inline

Grows buffer by n bytes using a growth strategy, returns pointer to new region.

Definition at line 126 of file MemoryBuffer.h.

◆ operator=()

MemoryBuffer & Cogs::Memory::MemoryBuffer::operator= ( MemoryBuffer &&  other)
inlinenoexcept

Definition at line 77 of file MemoryBuffer.h.

◆ pos()

size_t Cogs::Memory::MemoryBuffer::pos ( ) const
inline

Definition at line 171 of file MemoryBuffer.h.

◆ read()

size_t Cogs::Memory::MemoryBuffer::read ( void *  buffer,
size_t  noofbytes 
)

Definition at line 141 of file MemoryBuffer.cpp.

◆ read16()

uint16_t Cogs::Memory::MemoryBuffer::read16 ( )
inline

Definition at line 143 of file MemoryBuffer.h.

◆ read32()

uint32_t Cogs::Memory::MemoryBuffer::read32 ( )
inline

Definition at line 144 of file MemoryBuffer.h.

◆ read64()

uint64_t Cogs::Memory::MemoryBuffer::read64 ( )
inline

Definition at line 145 of file MemoryBuffer.h.

◆ read8()

uint8_t Cogs::Memory::MemoryBuffer::read8 ( )
inline

Definition at line 142 of file MemoryBuffer.h.

◆ readDouble()

double Cogs::Memory::MemoryBuffer::readDouble ( )
inline

Definition at line 147 of file MemoryBuffer.h.

◆ readFloat()

float Cogs::Memory::MemoryBuffer::readFloat ( )
inline

Definition at line 146 of file MemoryBuffer.h.

◆ readFloat2()

glm::vec2 Cogs::Memory::MemoryBuffer::readFloat2 ( )

Definition at line 150 of file MemoryBuffer.cpp.

◆ readFloat3()

glm::vec3 Cogs::Memory::MemoryBuffer::readFloat3 ( )

Definition at line 158 of file MemoryBuffer.cpp.

◆ readFloat4()

glm::vec4 Cogs::Memory::MemoryBuffer::readFloat4 ( )

Definition at line 167 of file MemoryBuffer.cpp.

◆ readImpl()

template<typename T >
T Cogs::Memory::MemoryBuffer::readImpl ( )
inlineprivate

Definition at line 186 of file MemoryBuffer.h.

◆ readMatrix()

glm::mat4 Cogs::Memory::MemoryBuffer::readMatrix ( )

Definition at line 185 of file MemoryBuffer.cpp.

◆ readQuaternion()

glm::quat Cogs::Memory::MemoryBuffer::readQuaternion ( )

Definition at line 176 of file MemoryBuffer.cpp.

◆ readString()

std::string Cogs::Memory::MemoryBuffer::readString ( )

Definition at line 194 of file MemoryBuffer.cpp.

◆ release()

void Cogs::Memory::MemoryBuffer::release ( )
private

Definition at line 299 of file MemoryBuffer.cpp.

◆ reserve()

bool Cogs::Memory::MemoryBuffer::reserve ( size_t  size)

Definition at line 104 of file MemoryBuffer.cpp.

◆ reset()

void Cogs::Memory::MemoryBuffer::reset ( size_t  size,
Allocator allocator 
)

Definition at line 62 of file MemoryBuffer.cpp.

◆ resize()

bool Cogs::Memory::MemoryBuffer::resize ( size_t  size,
bool  keep = true,
bool  forceRealloc = false 
)

Definition at line 74 of file MemoryBuffer.cpp.

◆ seek()

void Cogs::Memory::MemoryBuffer::seek ( int64_t  offset,
Anchor  from 
)

Definition at line 283 of file MemoryBuffer.cpp.

◆ size()

size_t Cogs::Memory::MemoryBuffer::size ( ) const
inline

Definition at line 121 of file MemoryBuffer.h.

◆ swap()

void Cogs::Memory::MemoryBuffer::swap ( MemoryBuffer other)

Definition at line 132 of file MemoryBuffer.cpp.

◆ unreadSize()

size_t Cogs::Memory::MemoryBuffer::unreadSize ( ) const
inline

Definition at line 172 of file MemoryBuffer.h.

◆ write()

bool Cogs::Memory::MemoryBuffer::write ( const void *  buffer,
size_t  noofbytes 
)

Definition at line 210 of file MemoryBuffer.cpp.

◆ write16()

bool Cogs::Memory::MemoryBuffer::write16 ( uint16_t  value)
inline

Definition at line 157 of file MemoryBuffer.h.

◆ write32()

bool Cogs::Memory::MemoryBuffer::write32 ( uint32_t  value)
inline

Definition at line 158 of file MemoryBuffer.h.

◆ write64()

bool Cogs::Memory::MemoryBuffer::write64 ( uint64_t  value)
inline

Definition at line 159 of file MemoryBuffer.h.

◆ write8()

bool Cogs::Memory::MemoryBuffer::write8 ( uint8_t  value)
inline

Definition at line 156 of file MemoryBuffer.h.

◆ writeDouble()

bool Cogs::Memory::MemoryBuffer::writeDouble ( double  value)
inline

Definition at line 161 of file MemoryBuffer.h.

◆ writeFloat()

bool Cogs::Memory::MemoryBuffer::writeFloat ( float  value)
inline

Definition at line 160 of file MemoryBuffer.h.

◆ writeFloat2()

bool Cogs::Memory::MemoryBuffer::writeFloat2 ( const glm::vec2 &  value)

Definition at line 225 of file MemoryBuffer.cpp.

◆ writeFloat3()

bool Cogs::Memory::MemoryBuffer::writeFloat3 ( const glm::vec3 &  value)

Definition at line 234 of file MemoryBuffer.cpp.

◆ writeFloat4()

bool Cogs::Memory::MemoryBuffer::writeFloat4 ( const glm::vec4 &  value)

Definition at line 243 of file MemoryBuffer.cpp.

◆ writeMatrix()

bool Cogs::Memory::MemoryBuffer::writeMatrix ( const glm::mat4 &  value)

Definition at line 261 of file MemoryBuffer.cpp.

◆ writeQuaternion()

bool Cogs::Memory::MemoryBuffer::writeQuaternion ( const glm::quat &  value)

Definition at line 252 of file MemoryBuffer.cpp.

◆ writeString()

bool Cogs::Memory::MemoryBuffer::writeString ( const StringView str)

Definition at line 270 of file MemoryBuffer.cpp.

Member Data Documentation

◆ allocator

Allocator* Cogs::Memory::MemoryBuffer::allocator = Allocator::defaultAllocator()
private

Definition at line 181 of file MemoryBuffer.h.

◆ buffer

void* Cogs::Memory::MemoryBuffer::buffer = nullptr
private

Definition at line 177 of file MemoryBuffer.h.

◆ currentPos

size_t Cogs::Memory::MemoryBuffer::currentPos = 0
private

Definition at line 180 of file MemoryBuffer.h.

◆ currentSize

size_t Cogs::Memory::MemoryBuffer::currentSize = 0
private

Definition at line 178 of file MemoryBuffer.h.

◆ storageSize

size_t Cogs::Memory::MemoryBuffer::storageSize = 0
private

Definition at line 179 of file MemoryBuffer.h.

◆ type

MemBlockType Cogs::Memory::MemoryBuffer::type = MemBlockType::Block
private

Definition at line 182 of file MemoryBuffer.h.


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