soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SAutoBuf Class Reference

A smart buffer management class that automatically handles memory allocation and deallocation. More...

#include <SAutoBuf.h>

Public Member Functions

 SAutoBuf ()
 Default constructor. Initializes an empty buffer.
 
 SAutoBuf (size_t nElements)
 Constructor with initial buffer size. Allocates a buffer of the specified size.
 
 ~SAutoBuf ()
 Destructor. Frees the allocated buffer if it was not externally attached.
 
 operator char * () const
 Conversion operator to char*.
 
char * operator-> () const
 Arrow operator to access members of the managed buffer.
 
const char & operator[] (int i) const
 Const array subscript operator.
 
char & operator[] (int i)
 Array subscript operator.
 
void Attach (char *pBuf, size_t size)
 Attaches an external buffer to the SAutoBuf object. The buffer will not be freed by the SAutoBuf object.
 
char * Detach ()
 Detaches the managed buffer from the SAutoBuf object. The caller is responsible for freeing the buffer using soui_mem_wrapper::SouiFree.
 
char * Allocate (size_t nElements)
 Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first.
 
size_t size ()
 Returns the size of the managed buffer.
 
void Free ()
 Frees the managed buffer. The buffer will be set to nullptr after being freed.
 

Detailed Description

A smart buffer management class that automatically handles memory allocation and deallocation.

Definition at line 17 of file SAutoBuf.h.

Constructor & Destructor Documentation

◆ SAutoBuf() [1/2]

SAutoBuf::SAutoBuf ( )

Default constructor. Initializes an empty buffer.

Definition at line 16 of file SAutoBuf.cpp.

◆ SAutoBuf() [2/2]

SNSBEGIN SAutoBuf::SAutoBuf ( size_t nElements)

Constructor with initial buffer size. Allocates a buffer of the specified size.

Parameters
nElementsThe number of elements (bytes) to allocate.

Definition at line 8 of file SAutoBuf.cpp.

◆ ~SAutoBuf()

SAutoBuf::~SAutoBuf ( )

Destructor. Frees the allocated buffer if it was not externally attached.

Definition at line 21 of file SAutoBuf.cpp.

Member Function Documentation

◆ Allocate()

char * SAutoBuf::Allocate ( size_t nElements)

Allocates a buffer of the specified size. If a buffer is already allocated, it will be freed first.

Parameters
nElementsThe number of elements (bytes) to allocate.
Returns
Pointer to the newly allocated buffer.

Definition at line 40 of file SAutoBuf.cpp.

◆ Attach()

void SAutoBuf::Attach ( char * pBuf,
size_t size )

Attaches an external buffer to the SAutoBuf object. The buffer will not be freed by the SAutoBuf object.

Parameters
pBufPointer to the external buffer.
sizeSize of the external buffer.

Definition at line 54 of file SAutoBuf.cpp.

◆ Detach()

char * SAutoBuf::Detach ( )

Detaches the managed buffer from the SAutoBuf object. The caller is responsible for freeing the buffer using soui_mem_wrapper::SouiFree.

Returns
Pointer to the detached buffer.

Definition at line 62 of file SAutoBuf.cpp.

◆ Free()

void SAutoBuf::Free ( )

Frees the managed buffer. The buffer will be set to nullptr after being freed.

Definition at line 26 of file SAutoBuf.cpp.

◆ operator char *()

SAutoBuf::operator char * ( ) const

Conversion operator to char*.

Returns
Pointer to the managed buffer.

Definition at line 89 of file SAutoBuf.cpp.

◆ operator->()

char * SAutoBuf::operator-> ( ) const

Arrow operator to access members of the managed buffer.

Returns
Pointer to the managed buffer.

Definition at line 83 of file SAutoBuf.cpp.

◆ operator[]() [1/2]

char & SAutoBuf::operator[] ( int i)

Array subscript operator.

Parameters
iIndex of the element to access.
Returns
Reference to the element at the specified index.

Definition at line 71 of file SAutoBuf.cpp.

◆ operator[]() [2/2]

const char & SAutoBuf::operator[] ( int i) const

Const array subscript operator.

Parameters
iIndex of the element to access.
Returns
Const reference to the element at the specified index.

Definition at line 77 of file SAutoBuf.cpp.

◆ size()

size_t SAutoBuf::size ( )

Returns the size of the managed buffer.

Returns
The size of the managed buffer.

Definition at line 35 of file SAutoBuf.cpp.


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