IniFile
Loading...
Searching...
No Matches
eut::Blob Class Reference

This class allows to edit a blob (insert, copy, search etc.). More...

#include <EuBlob.h>

Public Member Functions

 Blob ()
 
 Blob (char *pData, std::size_t nDataSize, bool bCopy=true)
 
 Blob (const Blob &rBlob)
 
virtual ~Blob ()
 
int swap (Blob &rSwapBlob)
 
int setData (char *pData, std::size_t nDataSize, bool bCopy=true)
 
void setMemResponsible (bool bActiv=true)
 
bool isMemResponsible ()
 
void clear ()
 
void setNULL ()
 
virtual std::size_t getData (char *&prBlob, bool bCopy=true)
 
int getData (char *&prBlob, std::size_t nStartPosition, std::size_t nSize)
 
int getBlob (Blob *&prBlob, std::size_t nStartPosition, std::size_t nSize)
 
char getChar (std::size_t nPosition)
 
std::size_t getSize () const
 
bool findForward (std::size_t &nFoundPosition, const char *pSearchMask, std::size_t nSearchMaskSize, bool bSearchAtTheBeginning)
 
bool findForward (std::size_t &nFoundPosition, const char *pSearchMask, std::size_t nSearchMaskSize)
 
bool findForwardNext (std::size_t &nFoundPosition, const char *pSearchMask, std::size_t nSearchMaskSize)
 
bool findBackward (std::size_t &nFoundPosition, const char *pSearchMask, std::size_t nSearchMaskSize, bool bSearchAtTheEnd)
 
bool findBackward (std::size_t &nFoundPosition, const char *pSearchMask, std::size_t nSearchMaskSize)
 
bool findBackwardNext (std::size_t &nFoundPosition, const char *pSearchMask, std::size_t nSearchMaskSize)
 
int setCurrentPosition (std::size_t nNewPosition)
 
std::size_t getCurrentPosition () const
 
int append (const char *pBuffer, std::size_t nBufferSize)
 
int append (const Blob *pBlob)
 
int append (const Blob &rBlob)
 
int insert (const char *pBuffer, std::size_t nBufferSize, std::size_t nBufferPosition)
 
int insert (const Blob *pBlob, std::size_t nBufferPosition)
 
int insert (const Blob &rBlob, std::size_t nBufferPosition)
 
int remove (std::size_t nNumberRemoveBytes, std::size_t nBufferPosition)
 
int replace (const char *pOldContent, std::size_t pOldContentSize, const char *pNewContent, std::size_t pNewContentSize)
 
int replaceAll (const char *pOldContent, std::size_t pOldContentSize, const char *pNewContent, std::size_t pNewContentSize)
 
Bloboperator+= (const Blob &rBlob)
 
Bloboperator= (const Blob &rBlob)
 
Bloboperator= (int iNULL)
 
 operator int () const
 
int operator== (const Blob &rBlob) const
 
int operator!= (const Blob &rBlob) const
 
bool operator> (const Blob &rBlob)
 
bool operator< (const Blob &rBlob)
 
bool operator>= (const Blob &rBlob)
 
bool operator<= (const Blob &rBlob)
 

Protected Attributes

char * m_pBlob
 
std::size_t m_nSize
 
std::size_t m_nCurrentPosition
 
bool m_bMemResponsible
 

Friends

Blob operator+ (Blob lT, const Blob &rrT)
 

Detailed Description

This class allows to edit a blob (insert, copy, search etc.).

Author
Helmut Jakoby

Constructor & Destructor Documentation

◆ Blob() [1/3]

eut::Blob::Blob ( )

Standard constructor.

◆ Blob() [2/3]

eut::Blob::Blob ( char * pData,
std::size_t nDataSize,
bool bCopy = true )

Constructor with parameter passing.

Parameters
[in]pDataA pointer to an allocated memory.
[in]nDataSizeThe size of pData.
[in]bCopyIf false, pData is not copied, but only m_pBlob is set to pData.
Attention
If in the case of bCopy = false the calling instance deletes the buffer before deleting the blob, the method setNULL() must be called before further processing to prevent working in freed memory.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.

◆ Blob() [3/3]

eut::Blob::Blob ( const Blob & rBlob)

Copy constructor.

Parameters
[in]rBlobFrom this blob the data is copied.

◆ ~Blob()

virtual eut::Blob::~Blob ( )
virtual

Destructor, possibly allocated memory is cleaned up.

Member Function Documentation

◆ append() [1/3]

int eut::Blob::append ( const Blob & rBlob)

Copies the passed blob to the blob end if m_bMemResponsible == true.

Parameters
[in]rBlobThe reference to the blob to be attached.
Returns
A return value < 0 indicates an error.

◆ append() [2/3]

int eut::Blob::append ( const Blob * pBlob)

Copies the passed blob to the blob end if m_bMemResponsible == true.

Parameters
[in]pBlobThe pointer to the blob to attach.
Returns
A return value < 0 indicates an error.

◆ append() [3/3]

int eut::Blob::append ( const char * pBuffer,
std::size_t nBufferSize )

Copies the passed buffer to the blob if m_bMemResponsible == true.

Parameters
[in]pBufferThe pointer to the memory to append.
[in]nBufferSizeThe size (number of bytes) of pBuffer.

Code snippets

int iErr = 0;
char * szString = "12345";
eut::Blob * pBlob = new eut::Blob();
iErr = pBlob->append( szString, strlen( szString )+1 );
delete pBlob;
This class allows to edit a blob (insert, copy, search etc.).
Definition EuBlob.h:75
int append(const char *pBuffer, std::size_t nBufferSize)
Returns
A return value < 0 indicates an error.

◆ clear()

void eut::Blob::clear ( )

Sets m_pBlob to nullptr.

Frees the memory of m_pBlob if m_bMemResponsible = true and set all values to the initial size.

◆ findBackward() [1/2]

bool eut::Blob::findBackward ( std::size_t & nFoundPosition,
const char * pSearchMask,
std::size_t nSearchMaskSize )

Returns the position in the blob of the passed search mask. The search starts at the end of the blob and moves towards the beginning.

Parameters
[in,out]nFoundPositionIf found, the position in the blob (smallest value 1).
[in]pSearchMaskThe search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};)
[in]nSearchMaskSizeSince all bytes can be searched for, the length (number of bytes) must be passed.
Returns
If return false, then search mask was not found.

Used for iterating through the blob in conjunction with findBackwardNext (..).

Code snippets

std::size_t t_nEndPosition = 0;
char t_szSearchMask[] = {0x0D, 0x0A};
std::size_t t_nSearchMaskSize = sizeof(t_szSearchMask);
...
if ( pBlob->findBackward( t_nEndPosition, t_szSearchMask, t_nSearchMaskSize ) )
{
do
{
... do anything ...
} while ( pBlob->findBackwardNext( t_nEndPosition, t_szSearchMask, t_nSearchMaskSize ) );
}
Attention
m_nCurrentPosition is set to the beginning of the range that corresponds to the search mask.

◆ findBackward() [2/2]

bool eut::Blob::findBackward ( std::size_t & nFoundPosition,
const char * pSearchMask,
std::size_t nSearchMaskSize,
bool bSearchAtTheEnd )

Returns the position in the blob of the passed search mask.

Parameters
[in,out]nFoundPositionIf found, the position in the blob (smallest value 1).
[in]pSearchMaskThe search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};)
[in]nSearchMaskSizeSince all bytes can be searched for, the length (number of bytes) must be passed.
[in]bSearchAtTheEndIf true, the search starts at the end of the blob; if false, the search starts from the current position towards the beginning.
Returns
If false, then the search mask was not found.
Attention
m_nCurrentPosition is set to the beginning of the range that corresponds to the search mask.

◆ findBackwardNext()

bool eut::Blob::findBackwardNext ( std::size_t & nFoundPosition,
const char * pSearchMask,
std::size_t nSearchMaskSize )

Returns the position in the blob of the passed search mask. The search starts from the current position of the blob towards the beginning.

Parameters
[in,out]nFoundPositionIf found, the position in the blob (smallest value 1).
[in]pSearchMaskThe search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};)
[in]nSearchMaskSizeSince all bytes can be searched for, the Length (number of bytes) is transferred.
Returns
If return false, then search mask was not found.
Attention
m_nCurrentPosition is set to the beginning of the range, which corresponds to the search mask.

◆ findForward() [1/2]

bool eut::Blob::findForward ( std::size_t & nFoundPosition,
const char * pSearchMask,
std::size_t nSearchMaskSize )

Returns the position in the blob of the passed search mask. The search starts at the beginning of the blob and moves towards the end.

Parameters
[in,out]nFoundPositionIf found, the position in the blob (smallest value 1).
[in]pSearchMaskThe search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};)
[in]nSearchMaskSizeSince all bytes can be searched for, the length (number of bytes) must be passed.
Returns
If return false, then search mask was not found.

Used for iterating through the blob in conjunction with findForwardNext (..).

Code snippets

std::size_t t_nEndPosition = 0;
char t_szSearchMask[] = {0x0D, 0x0A};
std::size_t t_nSearchMaskSize = sizeof(t_szSearchMask);
...
if ( pBlob->findForward( t_nEndPosition, t_szSearchMask, t_nSearchMaskSize ) )
{
do
{
... do anything ...
} while ( pBlob->findForwardNext( t_nEndPosition, t_szSearchMask, t_nSearchMaskSize ) );
}
Attention
m_nCurrentPosition is set to the beginning of the range that corresponds to the search mask.

◆ findForward() [2/2]

bool eut::Blob::findForward ( std::size_t & nFoundPosition,
const char * pSearchMask,
std::size_t nSearchMaskSize,
bool bSearchAtTheBeginning )

Returns the position in the blob of the passed search mask.

Parameters
[in,out]nFoundPositionIf found, the position in the blob (smallest value 1).
[in]pSearchMaskThe search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};)
[in]nSearchMaskSizeSince all bytes can be searched for, the length (number of bytes) must be passed.
[in]bSearchAtTheBeginningIf true, the search starts at the beginning of the blob; if false, the search starts from the current position towards the end.
Returns
If false, then the search mask was not found.
Attention
m_nCurrentPosition is set to the beginning of the range that corresponds to the search mask.

◆ findForwardNext()

bool eut::Blob::findForwardNext ( std::size_t & nFoundPosition,
const char * pSearchMask,
std::size_t nSearchMaskSize )

Returns the position in the blob of the passed search mask. The search starts from the current Position of the blob towards the end.

Parameters
[in,out]nFoundPositionIf found, the position in the blob (smallest value 1).
[in]pSearchMaskThe search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};)
[in]nSearchMaskSizeSince all bytes can be searched for, the Length (number of bytes) is transferred.
Returns
If return false, then search mask was not found.
Attention
m_nCurrentPosition is set to the beginning of the range, which corresponds to the search mask.
See also
findForward(std::size_t &, const char *, std::size_t)

◆ getBlob()

int eut::Blob::getBlob ( Blob *& prBlob,
std::size_t nStartPosition,
std::size_t nSize )

Returns a partial blob of the blob as pointer to new blob.

Parameters
[in,out]prBlobPointer to new blob.
[in]nStartPositionThe start position (smallest value 1).
[in]nSizeThe size of the area (number of bytes) which is in the delivered new blob.
Attention
This method allocates memory for the passed pointer, which must be released by the calling instance.
Returns
A return value < 0 indicates an error.

◆ getChar()

char eut::Blob::getChar ( std::size_t nPosition)

Returns a single char.

Parameters
[in]nPositionPosition Position of the desired char (smallest value 1).
Attention
Make sure that the position pointer is within the range of the blob (none Exception).
Returns
The char at the overshot position.

◆ getCurrentPosition()

std::size_t eut::Blob::getCurrentPosition ( ) const

Returns the current position of m_nCurrentPosition in the blob.

Returns
The current position (smallest value 1).

◆ getData() [1/2]

virtual std::size_t eut::Blob::getData ( char *& prBlob,
bool bCopy = true )
virtual

Returns the blob in prBlob.

Parameters
[in,out]prBlobThe pointer to the memory area of the blob.
[in]bCopyIf parameter bCopy is set to true, a copy of the blob is returned.
Returns
The size of prBlob (number of bytes).
Attention
If parameter bCopy is set to true, this method allocates memory to prBlob, which must be released by the calling instance.
Exceptions
eut::ErrorNExceptionAn exception is thrown if no memory could be allocated.

◆ getData() [2/2]

int eut::Blob::getData ( char *& prBlob,
std::size_t nStartPosition,
std::size_t nSize )

Returns a range of the blob as char*.

Parameters
[in,out]prBlobPointer to the allocated memory area.
[in]nStartPositionThe start position (smallest value 1).
[in]nSizeThe size of the area (number of bytes).
Attention
This method allocates memory for passed pointers, which must be released again by the calling instance.
Returns
A return value < 0 indicates an error.

◆ getSize()

std::size_t eut::Blob::getSize ( ) const

Returns the blob size.

Returns
the blob size.

◆ insert() [1/3]

int eut::Blob::insert ( const Blob & rBlob,
std::size_t nBufferPosition )

Copies the transferred blob into its own blob in the transferred position.

Parameters
[in]rBlobThe reference to the blob to be inserted.
[in]nBufferPositionThe position (smallest value 1) in the blob from which to insert.
Returns
A return value < 0 indicates an error.

◆ insert() [2/3]

int eut::Blob::insert ( const Blob * pBlob,
std::size_t nBufferPosition )

Copies the transferred blob into its own blob in the transferred position.

Parameters
[in]pBlobThe pointer to the blob to be inserted.
[in]nBufferPositionThe position (smallest value 1) in the blob from which to insert.
Returns
A return value < 0 indicates an error.

◆ insert() [3/3]

int eut::Blob::insert ( const char * pBuffer,
std::size_t nBufferSize,
std::size_t nBufferPosition )

Copies the passed buffer into the own blob in passed position.

Parameters
[in]pBufferPointer to memory to be inserted.
[in]nBufferSizeThe size (number of bytes) of pBuffer.
[in]nBufferPositionThe position (smallest value 1) in the blob from which to insert.
int iErr = 0;
char * szString = "12345";
eut::Blob * pBlob = new eut::Blob();
// szString ans Ende von pBlob anhängen
iErr = pBlob->insert( szString, strlen( szString )+1, pBlob->getSize()+1 );
...
delete pBlob;
int insert(const char *pBuffer, std::size_t nBufferSize, std::size_t nBufferPosition)
std::size_t getSize() const
Returns
A return value < 0 indicates an error.

◆ isMemResponsible()

bool eut::Blob::isMemResponsible ( )

Returns the responsibility about the memory of the blob.

Returns
If true, the blob has responsibility for the buffer; allows editing and deletes the buffer in destructor.

◆ operator int()

eut::Blob::operator int ( ) const

If the size is not set then the return value is 0.

code snippets

eut::Blob myBlob();
if ( myBlob > 0 ) cout << "Blob has content!" << endl;
else cout << "Blob has NO content!" << endl;

Output:

Blob has NO content!

◆ operator!=()

int eut::Blob::operator!= ( const Blob & rBlob) const

Comparison operator.

◆ operator+=()

Blob & eut::Blob::operator+= ( const Blob & rBlob)

Assignment operator which expects an Blob and appends it to its data.

Parameters
[in]rBlobFrom this object the data is taken over.
Exceptions
eut::ErrorNExceptionAn exception is thrown if an error occurs.
See also
Blob::append( Blob & rBlob )

◆ operator<()

bool eut::Blob::operator< ( const Blob & rBlob)

Comparison operator.

◆ operator<=()

bool eut::Blob::operator<= ( const Blob & rBlob)

Comparison operator.

◆ operator=() [1/2]

Blob & eut::Blob::operator= ( const Blob & rBlob)

Assignment operator which expects an Blob.

Parameters
[in]rBlobThe data is transferred from this object.

◆ operator=() [2/2]

Blob & eut::Blob::operator= ( int iNULL)

Assignment operator which expects an integer.

Parameters
[in]iNULLNo matter what is passed; the blob is removed from memory and all values are set to 0.

In any case the Blob has an "invalid" value (operator int() returns 0)!

◆ operator==()

int eut::Blob::operator== ( const Blob & rBlob) const

Comparison operator.

◆ operator>()

bool eut::Blob::operator> ( const Blob & rBlob)

Comparison operator.

◆ operator>=()

bool eut::Blob::operator>= ( const Blob & rBlob)

Comparison operator.

◆ remove()

int eut::Blob::remove ( std::size_t nNumberRemoveBytes,
std::size_t nBufferPosition )

Removes transferred number of bytes in own blob starting from the transferred position (including this one).

Parameters
[in]nNumberRemoveBytesThe number of bytes to remove.
[in]nBufferPositionThe position (smallest value 1) in the blob from which to remove.
Returns
A return value < 0 indicates an error.

◆ replace()

int eut::Blob::replace ( const char * pOldContent,
std::size_t pOldContentSize,
const char * pNewContent,
std::size_t pNewContentSize )

Searches and removes first passed content pOldContent from the blob once from the beginning and inserts the content pNewContent instead.

Parameters
[in]pOldContentThe content to be exchanged.
[in]pOldContentSizeThe length of the content to be exchanged.
[in]pNewContentThe new content to be inserted.
[in]pNewContentSizeThe length of the content to be inserted.
Returns
If 1, the content was exchanged and if 0, the content to be exchanged was not found.
A return value < 0 indicates an error.

◆ replaceAll()

int eut::Blob::replaceAll ( const char * pOldContent,
std::size_t pOldContentSize,
const char * pNewContent,
std::size_t pNewContentSize )

Searches and removes all content equal to the first passed content pOldContent from the blob and inserts the content from pNewContent instead.

Parameters
[in]pOldContentThe content to be exchanged.
[in]pOldContentSizeThe length of the content to be exchanged.
[in]pNewContentThe new content to be inserted.
[in]pNewContentSizeThe length of the content to be inserted.
Returns
Is the number of times the content was exchanged.
A return value < 0 indicates an error.
Attention
If an error occurs, the state of the blob is undefined; contents may already have been swapped.

◆ setCurrentPosition()

int eut::Blob::setCurrentPosition ( std::size_t nNewPosition)

Sets the current position in the blob.

Parameters
[in]nNewPositionThe new position of the current pointer in the blob (smallest value 1).
Returns
If the position is outside the size of the blob, an error is returned.

◆ setData()

int eut::Blob::setData ( char * pData,
std::size_t nDataSize,
bool bCopy = true )

Sets the blob.

Parameters
[in]pDataA pointer to an allocated memory.
[in]nDataSizeThe size of pData.
[in]bCopyIf false, pData is not copied, but only m_pBlob is set to pData.
Attention
If in the case of bCopy = false the calling instance deletes the buffer before deleting the blob, the method setNULL() must be called before further processing to prevent working in freed memory.
Returns
A return < 0 indicates an error.

◆ setMemResponsible()

void eut::Blob::setMemResponsible ( bool bActiv = true)

Sets the responsibility over the memory of the blob.

Parameters
[in]bActivIf true, the blob takes responsibility for the buffer; allows editing and deletes the buffer in the destructor. Can be used if the calling instance has allocated memory and wants to pass it. However, it is then no longer allowed to edit or delete it.

◆ setNULL()

void eut::Blob::setNULL ( )

Sets m_pBlob to nullptr and m_nSize and m_nCurrentPosition to 0 without removing the m_pBlob from memory!

Attention
Can be used with caution if this blob gets an uncopied buffer and should only be used for iterating and searching, and the buffer should be preserved for the calling instance.

◆ swap()

int eut::Blob::swap ( Blob & rSwapBlob)

The contents of the attributes of this object are swapped with those of the passed object.

This only works if both are m_bMemResponsible or both are not m_bMemResponsible.

Parameters
[in,out]rSwapBlobThe blob with which the content is to be swapped.
Returns
A return value < 0 indicates an error.

Friends And Related Symbol Documentation

◆ operator+

Blob operator+ ( Blob lT,
const Blob & rrT )
friend

Member Data Documentation

◆ m_bMemResponsible

bool eut::Blob::m_bMemResponsible
protected

If a char* is passed, which was not copied or should remain in the responsibility of the calling instance, this buffer must not be changed or deleted! So here the info is set to false.

◆ m_nCurrentPosition

std::size_t eut::Blob::m_nCurrentPosition
protected

The current position in the blob (starts at 0).

◆ m_nSize

std::size_t eut::Blob::m_nSize
protected

The size of the blob.

◆ m_pBlob

char* eut::Blob::m_pBlob
protected

The blob.


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