Melon
A C++ library designed for RadishOS.
Loading...
Searching...
No Matches
Melon::Memory::Buffer< T > Class Template Reference

Container for raw memory. More...

#include <Buffer.hpp>

Public Member Functions

 Buffer (const T *data, Typing::USize size)
 Constructs the buffer from existing raw memory.
 Buffer (const Buffer< T > &other)
 Copy constructor.
 Buffer (Buffer< T > &&other)
 Move constructor.
 ~Buffer ()
 Destructor.
Buffer< T > & copy (this const Buffer< T > &self, Buffer< T > &dest, Typing::USize size)
 Copies some objects from here to another buffer.
Buffer< T > & set (this Buffer< T > &self, T c, Typing::USize size)
 Sets some objects from this buffer to a given value.
Buffer< T > & move (this const Buffer< T > &self, Buffer< T > &dest, Typing::USize size)
 Moves some objects from here to another buffer.
int compare (this const Buffer< T > &self, const Buffer< T > &other, Typing::USize size)
 Compares some objects between this buffer and another one.
const T * get (this const Buffer< T > &self)
 Gets a constant pointer to the raw memory.
Typing::USize size (this const Buffer< T > &self)
 Gets the size of the buffer.
const T * begin (this const Buffer< T > &self)
 Gets a constant pointer to the base of the raw buffer.
const T * end (this const Buffer< T > &self)
 Gets a constant pointer to the end of the raw buffer.
void resize (this Buffer< T > &self, Typing::USize new_size)
 Resizes the buffer.
bool operator== (this const Buffer< T > &self, const Buffer< T > &other)
 Checks if a buffer has same size and same content.
bool operator!= (this const Buffer< T > &self, const Buffer< T > &other)
 Checks if a buffer does not have same size or same content.
bool operator< (this const Buffer< T > &self, const Buffer< T > &other)
 Checks if this buffer is smaller than another.
bool operator> (this const Buffer< T > &self, const Buffer< T > &other)
 Checks if this buffer is bigger than another.
bool operator<= (this const Buffer< T > &self, const Buffer< T > &other)
 Checks if this buffer is smaller than or equals another.
bool operator>= (this const Buffer< T > &self, const Buffer< T > &other)
 Checks if this buffer is bigger than or equals another.
T & operator[] (this Buffer< T > &self, Typing::USize index)
 Gets an object from the buffer.
const T & operator[] (this const Buffer< T > &self, Typing::USize index)
 Gets an object from the buffer.
Buffer< T > & operator= (this Buffer< T > &self, const Buffer< T > &other)
 Copy assignment operator.
Buffer< T > & operator= (this Buffer< T > &self, Buffer< T > &&other)
 Move assignment operator.

Detailed Description

template<typename T>
class Melon::Memory::Buffer< T >

Container for raw memory.

This container stores allocated raw memory and the size of the allocated area. If T is not trivially constructible, its constructor will never be called internally.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

template<typename T>
Melon::Memory::Buffer< T >::Buffer ( const T * data,
Typing::USize size )
inline

Constructs the buffer from existing raw memory.

Parameters
datamemory to construct the buffer from
sizemaximum size of the buffer

◆ Buffer() [2/3]

template<typename T>
Melon::Memory::Buffer< T >::Buffer ( const Buffer< T > & other)
inline

Copy constructor.

Parameters
otherbuffer to copy data to

◆ Buffer() [3/3]

template<typename T>
Melon::Memory::Buffer< T >::Buffer ( Buffer< T > && other)
inline

Move constructor.

Parameters
otherbuffer to move data and size to

Member Function Documentation

◆ begin()

template<typename T>
const T * Melon::Memory::Buffer< T >::begin ( this const Buffer< T > & self)
inline

Gets a constant pointer to the base of the raw buffer.

Returns
pointer to raw buffer base

◆ compare()

template<typename T>
int Melon::Memory::Buffer< T >::compare ( this const Buffer< T > & self,
const Buffer< T > & other,
Typing::USize size )
inline

Compares some objects between this buffer and another one.

Parameters
otherbuffer to compare
sizeobject count
Returns
<0 if self < dest, 0 if self == dest and >0 if self > dest

◆ copy()

template<typename T>
Buffer< T > & Melon::Memory::Buffer< T >::copy ( this const Buffer< T > & self,
Buffer< T > & dest,
Typing::USize size )
inline

Copies some objects from here to another buffer.

Parameters
destdestination buffer
sizeobject count
Returns
destination buffer

◆ end()

template<typename T>
const T * Melon::Memory::Buffer< T >::end ( this const Buffer< T > & self)
inline

Gets a constant pointer to the end of the raw buffer.

Returns
pointer to raw buffer end

◆ get()

template<typename T>
const T * Melon::Memory::Buffer< T >::get ( this const Buffer< T > & self)
inline

Gets a constant pointer to the raw memory.

Returns
constant raw buffer

◆ move()

template<typename T>
Buffer< T > & Melon::Memory::Buffer< T >::move ( this const Buffer< T > & self,
Buffer< T > & dest,
Typing::USize size )
inline

Moves some objects from here to another buffer.

This method is similar to copy() but it prevents both buffers from overlapping.

Parameters
destdestination buffer
sizeobject count
Returns
destination buffer

◆ operator!=()

template<typename T>
bool Melon::Memory::Buffer< T >::operator!= ( this const Buffer< T > & self,
const Buffer< T > & other )
inline

Checks if a buffer does not have same size or same content.

Parameters
otherother buffer
Returns
comparison result

◆ operator<()

template<typename T>
bool Melon::Memory::Buffer< T >::operator< ( this const Buffer< T > & self,
const Buffer< T > & other )
inline

Checks if this buffer is smaller than another.

Parameters
otherother buffer
Returns
comparison result

◆ operator<=()

template<typename T>
bool Melon::Memory::Buffer< T >::operator<= ( this const Buffer< T > & self,
const Buffer< T > & other )
inline

Checks if this buffer is smaller than or equals another.

Parameters
otherother buffer
Returns
comparison result

◆ operator=() [1/2]

template<typename T>
Buffer< T > & Melon::Memory::Buffer< T >::operator= ( this Buffer< T > & self,
Buffer< T > && other )
inline

Move assignment operator.

Parameters
otherbuffer to move data and size to

◆ operator=() [2/2]

template<typename T>
Buffer< T > & Melon::Memory::Buffer< T >::operator= ( this Buffer< T > & self,
const Buffer< T > & other )
inline

Copy assignment operator.

Parameters
otherbuffer to copy data to

◆ operator==()

template<typename T>
bool Melon::Memory::Buffer< T >::operator== ( this const Buffer< T > & self,
const Buffer< T > & other )
inline

Checks if a buffer has same size and same content.

Parameters
otherother buffer
Returns
comparison result

◆ operator>()

template<typename T>
bool Melon::Memory::Buffer< T >::operator> ( this const Buffer< T > & self,
const Buffer< T > & other )
inline

Checks if this buffer is bigger than another.

Parameters
otherother buffer
Returns
comparison result

◆ operator>=()

template<typename T>
bool Melon::Memory::Buffer< T >::operator>= ( this const Buffer< T > & self,
const Buffer< T > & other )
inline

Checks if this buffer is bigger than or equals another.

Parameters
otherother buffer
Returns
comparison result

◆ operator[]() [1/2]

template<typename T>
T & Melon::Memory::Buffer< T >::operator[] ( this Buffer< T > & self,
Typing::USize index )
inline

Gets an object from the buffer.

The object is returned by index. If the index is too high, Exceptions::OutOfRange will be thrown.

Parameters
indexposition of the object in the buffer

◆ operator[]() [2/2]

template<typename T>
const T & Melon::Memory::Buffer< T >::operator[] ( this const Buffer< T > & self,
Typing::USize index )
inline

Gets an object from the buffer.

The object is returned by index. If the index is too high, Exceptions::OutOfRange will be thrown.

Parameters
indexposition of the object in the buffer

◆ resize()

template<typename T>
void Melon::Memory::Buffer< T >::resize ( this Buffer< T > & self,
Typing::USize new_size )
inline

Resizes the buffer.

This method gives a new size to this buffer and reallocates the data to match the new size.

Parameters
new_sizenew size of the buffer

◆ set()

template<typename T>
Buffer< T > & Melon::Memory::Buffer< T >::set ( this Buffer< T > & self,
T c,
Typing::USize size )
inline

Sets some objects from this buffer to a given value.

Parameters
cvalue to set
sizeobject count
Returns
self

◆ size()

template<typename T>
Typing::USize Melon::Memory::Buffer< T >::size ( this const Buffer< T > & self)
inline

Gets the size of the buffer.

Returns
buffer size

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