Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Poco::Buffer< T > Class Template Reference

#include <Buffer.h>

Public Member Functions

 Buffer (std::size_t length)
 
 Buffer (T *pMem, std::size_t length)
 
 Buffer (const T *pMem, std::size_t length)
 
 Buffer (const Buffer &other)
 
 Buffer (Buffer &&other) noexcept
 
Bufferoperator= (const Buffer &other)
 Assignment operator.
 
Bufferoperator= (Buffer &&other) noexcept
 Move assignment operator.
 
 ~Buffer ()
 Destroys the Buffer.
 
void resize (std::size_t newCapacity, bool preserveContent=true)
 
void setCapacity (std::size_t newCapacity, bool preserveContent=true)
 
void assign (const T *buf, std::size_t sz)
 
void append (const T *buf, std::size_t sz)
 Resizes this buffer and appends the argument buffer.
 
void append (T val)
 Resizes this buffer by one element and appends the argument value.
 
void append (const Buffer &buf)
 Resizes this buffer and appends the argument buffer.
 
std::size_t capacity () const
 Returns the allocated memory size in elements.
 
std::size_t capacityBytes () const
 Returns the allocated memory size in bytes.
 
void swap (Buffer &other)
 Swaps the buffer with another one.
 
bool operator== (const Buffer &other) const
 Compare operator.
 
bool operator!= (const Buffer &other) const
 Compare operator.
 
void clear ()
 Sets the contents of the buffer to zero.
 
std::size_t size () const
 Returns the used size of the buffer in elements.
 
std::size_t sizeBytes () const
 Returns the used size of the buffer in bytes.
 
T * begin ()
 Returns a pointer to the beginning of the buffer.
 
const T * begin () const
 Returns a pointer to the beginning of the buffer.
 
T * end ()
 Returns a pointer to end of the buffer.
 
const T * end () const
 Returns a pointer to the end of the buffer.
 
bool empty () const
 Return true if buffer is empty.
 
T & operator[] (std::size_t index)
 
const T & operator[] (std::size_t index) const
 

Private Member Functions

 Buffer ()
 

Private Attributes

std::size_t _capacity
 
std::size_t _used
 
T * _ptr
 
bool _ownMem
 

Detailed Description

template<class T>
class Poco::Buffer< T >

A buffer class that allocates a buffer of a given type and size in the constructor and deallocates the buffer in the destructor.

This class is useful everywhere where a temporary buffer is needed.

Definition at line 31 of file Buffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/6]

template<class T >
Poco::Buffer< T >::Buffer ( std::size_t length)
inline

Definition at line 39 of file Buffer.h.

◆ Buffer() [2/6]

template<class T >
Poco::Buffer< T >::Buffer ( T * pMem,
std::size_t length )
inline

Creates the Buffer. Length argument specifies the length of the supplied memory pointed to by pMem in the number of elements of type T. Supplied pointer is considered blank and not owned by Buffer, so in this case Buffer only acts as a wrapper around externally supplied (and lifetime-managed) memory.

Definition at line 52 of file Buffer.h.

◆ Buffer() [3/6]

template<class T >
Poco::Buffer< T >::Buffer ( const T * pMem,
std::size_t length )
inline

Creates and allocates the Buffer; copies the contents of the supplied memory into the buffer. Length argument specifies the length of the supplied memory pointed to by pMem in the number of elements of type T.

Definition at line 66 of file Buffer.h.

◆ Buffer() [4/6]

template<class T >
Poco::Buffer< T >::Buffer ( const Buffer< T > & other)
inline

Definition at line 83 of file Buffer.h.

◆ Buffer() [5/6]

template<class T >
Poco::Buffer< T >::Buffer ( Buffer< T > && other)
inlinenoexcept

Definition at line 97 of file Buffer.h.

◆ ~Buffer()

template<class T >
Poco::Buffer< T >::~Buffer ( )
inline

Destroys the Buffer.

Definition at line 140 of file Buffer.h.

◆ Buffer() [6/6]

template<class T >
Poco::Buffer< T >::Buffer ( )
private

Member Function Documentation

◆ append() [1/3]

template<class T >
void Poco::Buffer< T >::append ( const Buffer< T > & buf)
inline

Resizes this buffer and appends the argument buffer.

Definition at line 233 of file Buffer.h.

◆ append() [2/3]

template<class T >
void Poco::Buffer< T >::append ( const T * buf,
std::size_t sz )
inline

Resizes this buffer and appends the argument buffer.

Definition at line 218 of file Buffer.h.

◆ append() [3/3]

template<class T >
void Poco::Buffer< T >::append ( T val)
inline

Resizes this buffer by one element and appends the argument value.

Definition at line 226 of file Buffer.h.

◆ assign()

template<class T >
void Poco::Buffer< T >::assign ( const T * buf,
std::size_t sz )
inline

Assigns the argument buffer to this buffer. If necessary, resizes the buffer.

Definition at line 208 of file Buffer.h.

◆ begin() [1/2]

template<class T >
T * Poco::Buffer< T >::begin ( )
inline

Returns a pointer to the beginning of the buffer.

Definition at line 305 of file Buffer.h.

◆ begin() [2/2]

template<class T >
const T * Poco::Buffer< T >::begin ( ) const
inline

Returns a pointer to the beginning of the buffer.

Definition at line 311 of file Buffer.h.

◆ capacity()

template<class T >
std::size_t Poco::Buffer< T >::capacity ( ) const
inline

Returns the allocated memory size in elements.

Definition at line 239 of file Buffer.h.

◆ capacityBytes()

template<class T >
std::size_t Poco::Buffer< T >::capacityBytes ( ) const
inline

Returns the allocated memory size in bytes.

Definition at line 245 of file Buffer.h.

◆ clear()

template<class T >
void Poco::Buffer< T >::clear ( )
inline

Sets the contents of the buffer to zero.

Definition at line 287 of file Buffer.h.

◆ empty()

template<class T >
bool Poco::Buffer< T >::empty ( ) const
inline

Return true if buffer is empty.

Definition at line 329 of file Buffer.h.

◆ end() [1/2]

template<class T >
T * Poco::Buffer< T >::end ( )
inline

Returns a pointer to end of the buffer.

Definition at line 317 of file Buffer.h.

◆ end() [2/2]

template<class T >
const T * Poco::Buffer< T >::end ( ) const
inline

Returns a pointer to the end of the buffer.

Definition at line 323 of file Buffer.h.

◆ operator!=()

template<class T >
bool Poco::Buffer< T >::operator!= ( const Buffer< T > & other) const
inline

Compare operator.

Definition at line 281 of file Buffer.h.

◆ operator=() [1/2]

template<class T >
Buffer & Poco::Buffer< T >::operator= ( Buffer< T > && other)
inlinenoexcept

Move assignment operator.

Definition at line 122 of file Buffer.h.

◆ operator=() [2/2]

template<class T >
Buffer & Poco::Buffer< T >::operator= ( const Buffer< T > & other)
inline

Assignment operator.

Definition at line 110 of file Buffer.h.

◆ operator==()

template<class T >
bool Poco::Buffer< T >::operator== ( const Buffer< T > & other) const
inline

Compare operator.

Definition at line 262 of file Buffer.h.

◆ operator[]() [1/2]

template<class T >
T & Poco::Buffer< T >::operator[] ( std::size_t index)
inline

Definition at line 335 of file Buffer.h.

◆ operator[]() [2/2]

template<class T >
const T & Poco::Buffer< T >::operator[] ( std::size_t index) const
inline

Definition at line 342 of file Buffer.h.

◆ resize()

template<class T >
void Poco::Buffer< T >::resize ( std::size_t newCapacity,
bool preserveContent = true )
inline

Resizes the buffer capacity and size. If preserveContent is true, the content of the old buffer is copied over to the new buffer. The new capacity can be larger or smaller than the current one; if it is smaller, capacity will remain intact. Size will always be set to the new capacity.

Buffers only wrapping externally owned storage can not be resized. If resize is attempted on those, IllegalAccessException is thrown.

Definition at line 146 of file Buffer.h.

◆ setCapacity()

template<class T >
void Poco::Buffer< T >::setCapacity ( std::size_t newCapacity,
bool preserveContent = true )
inline

Sets the buffer capacity. If preserveContent is true, the content of the old buffer is copied over to the new buffer. The new capacity can be larger or smaller than the current one; size will be set to the new capacity only if new capacity is smaller than the current size, otherwise it will remain intact.

Buffers only wrapping externally owned storage can not be resized. If resize is attempted on those, IllegalAccessException is thrown.

Definition at line 174 of file Buffer.h.

◆ size()

template<class T >
std::size_t Poco::Buffer< T >::size ( ) const
inline

Returns the used size of the buffer in elements.

Definition at line 293 of file Buffer.h.

◆ sizeBytes()

template<class T >
std::size_t Poco::Buffer< T >::sizeBytes ( ) const
inline

Returns the used size of the buffer in bytes.

Definition at line 299 of file Buffer.h.

◆ swap()

template<class T >
void Poco::Buffer< T >::swap ( Buffer< T > & other)
inline

Swaps the buffer with another one.

Definition at line 251 of file Buffer.h.

Member Data Documentation

◆ _capacity

template<class T >
std::size_t Poco::Buffer< T >::_capacity
private

Definition at line 352 of file Buffer.h.

◆ _ownMem

template<class T >
bool Poco::Buffer< T >::_ownMem
private

Definition at line 355 of file Buffer.h.

◆ _ptr

template<class T >
T* Poco::Buffer< T >::_ptr
private

Definition at line 354 of file Buffer.h.

◆ _used

template<class T >
std::size_t Poco::Buffer< T >::_used
private

Definition at line 353 of file Buffer.h.


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