IniFile
|
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) |
Blob & | operator+= (const Blob &rBlob) |
Blob & | operator= (const Blob &rBlob) |
Blob & | operator= (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) |
This class allows to edit a blob (insert, copy, search etc.).
eut::Blob::Blob | ( | ) |
Standard constructor.
eut::Blob::Blob | ( | char * | pData, |
std::size_t | nDataSize, | ||
bool | bCopy = true ) |
Constructor with parameter passing.
[in] | pData | A pointer to an allocated memory. |
[in] | nDataSize | The size of pData. |
[in] | bCopy | If false, pData is not copied, but only m_pBlob is set to pData. |
eut::ErrorNException | An exception is thrown if an error occurs. |
eut::Blob::Blob | ( | const Blob & | rBlob | ) |
Copy constructor.
[in] | rBlob | From this blob the data is copied. |
|
virtual |
Destructor, possibly allocated memory is cleaned up.
int eut::Blob::append | ( | const Blob & | rBlob | ) |
Copies the passed blob to the blob end if m_bMemResponsible == true.
[in] | rBlob | The reference to the blob to be attached. |
int eut::Blob::append | ( | const Blob * | pBlob | ) |
Copies the passed blob to the blob end if m_bMemResponsible == true.
[in] | pBlob | The pointer to the blob to attach. |
int eut::Blob::append | ( | const char * | pBuffer, |
std::size_t | nBufferSize ) |
Copies the passed buffer to the blob if m_bMemResponsible == true.
[in] | pBuffer | The pointer to the memory to append. |
[in] | nBufferSize | The size (number of bytes) of pBuffer. |
Code snippets
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.
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.
[in,out] | nFoundPosition | If found, the position in the blob (smallest value 1). |
[in] | pSearchMask | The search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};) |
[in] | nSearchMaskSize | Since all bytes can be searched for, the length (number of bytes) must be passed. |
Used for iterating through the blob in conjunction with findBackwardNext (..).
Code snippets
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.
[in,out] | nFoundPosition | If found, the position in the blob (smallest value 1). |
[in] | pSearchMask | The search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};) |
[in] | nSearchMaskSize | Since all bytes can be searched for, the length (number of bytes) must be passed. |
[in] | bSearchAtTheEnd | If true, the search starts at the end of the blob; if false, the search starts from the current position towards the beginning. |
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.
[in,out] | nFoundPosition | If found, the position in the blob (smallest value 1). |
[in] | pSearchMask | The search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};) |
[in] | nSearchMaskSize | Since all bytes can be searched for, the Length (number of bytes) is transferred. |
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.
[in,out] | nFoundPosition | If found, the position in the blob (smallest value 1). |
[in] | pSearchMask | The search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};) |
[in] | nSearchMaskSize | Since all bytes can be searched for, the length (number of bytes) must be passed. |
Used for iterating through the blob in conjunction with findForwardNext (..).
Code snippets
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.
[in,out] | nFoundPosition | If found, the position in the blob (smallest value 1). |
[in] | pSearchMask | The search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};) |
[in] | nSearchMaskSize | Since all bytes can be searched for, the length (number of bytes) must be passed. |
[in] | bSearchAtTheBeginning | If true, the search starts at the beginning of the blob; if false, the search starts from the current position towards the end. |
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.
[in,out] | nFoundPosition | If found, the position in the blob (smallest value 1). |
[in] | pSearchMask | The search mask (e.g. char t_szSuchMaske[] = {0x0D, 0x0A};) |
[in] | nSearchMaskSize | Since all bytes can be searched for, the Length (number of bytes) is transferred. |
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.
[in,out] | prBlob | Pointer to new blob. |
[in] | nStartPosition | The start position (smallest value 1). |
[in] | nSize | The size of the area (number of bytes) which is in the delivered new blob. |
char eut::Blob::getChar | ( | std::size_t | nPosition | ) |
Returns a single char.
[in] | nPosition | Position Position of the desired char (smallest value 1). |
std::size_t eut::Blob::getCurrentPosition | ( | ) | const |
Returns the current position of m_nCurrentPosition in the blob.
|
virtual |
Returns the blob in prBlob.
[in,out] | prBlob | The pointer to the memory area of the blob. |
[in] | bCopy | If parameter bCopy is set to true, a copy of the blob is returned. |
eut::ErrorNException | An exception is thrown if no memory could be allocated. |
int eut::Blob::getData | ( | char *& | prBlob, |
std::size_t | nStartPosition, | ||
std::size_t | nSize ) |
Returns a range of the blob as char*.
[in,out] | prBlob | Pointer to the allocated memory area. |
[in] | nStartPosition | The start position (smallest value 1). |
[in] | nSize | The size of the area (number of bytes). |
std::size_t eut::Blob::getSize | ( | ) | const |
Returns the blob size.
int eut::Blob::insert | ( | const Blob & | rBlob, |
std::size_t | nBufferPosition ) |
Copies the transferred blob into its own blob in the transferred position.
[in] | rBlob | The reference to the blob to be inserted. |
[in] | nBufferPosition | The position (smallest value 1) in the blob from which to insert. |
int eut::Blob::insert | ( | const Blob * | pBlob, |
std::size_t | nBufferPosition ) |
Copies the transferred blob into its own blob in the transferred position.
[in] | pBlob | The pointer to the blob to be inserted. |
[in] | nBufferPosition | The position (smallest value 1) in the blob from which to insert. |
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.
[in] | pBuffer | Pointer to memory to be inserted. |
[in] | nBufferSize | The size (number of bytes) of pBuffer. |
[in] | nBufferPosition | The position (smallest value 1) in the blob from which to insert. |
bool eut::Blob::isMemResponsible | ( | ) |
Returns the responsibility about the memory of the blob.
eut::Blob::operator int | ( | ) | const |
int eut::Blob::operator!= | ( | const Blob & | rBlob | ) | const |
Comparison operator.
Assignment operator which expects an Blob and appends it to its data.
[in] | rBlob | From this object the data is taken over. |
eut::ErrorNException | An exception is thrown if an error occurs. |
bool eut::Blob::operator< | ( | const Blob & | rBlob | ) |
Comparison operator.
bool eut::Blob::operator<= | ( | const Blob & | rBlob | ) |
Comparison operator.
Assignment operator which expects an Blob.
[in] | rBlob | The data is transferred from this object. |
Blob & eut::Blob::operator= | ( | int | iNULL | ) |
Assignment operator which expects an integer.
[in] | iNULL | No 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)!
int eut::Blob::operator== | ( | const Blob & | rBlob | ) | const |
Comparison operator.
bool eut::Blob::operator> | ( | const Blob & | rBlob | ) |
Comparison operator.
bool eut::Blob::operator>= | ( | const Blob & | rBlob | ) |
Comparison operator.
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).
[in] | nNumberRemoveBytes | The number of bytes to remove. |
[in] | nBufferPosition | The position (smallest value 1) in the blob from which to remove. |
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.
[in] | pOldContent | The content to be exchanged. |
[in] | pOldContentSize | The length of the content to be exchanged. |
[in] | pNewContent | The new content to be inserted. |
[in] | pNewContentSize | The length of the content to be inserted. |
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.
[in] | pOldContent | The content to be exchanged. |
[in] | pOldContentSize | The length of the content to be exchanged. |
[in] | pNewContent | The new content to be inserted. |
[in] | pNewContentSize | The length of the content to be inserted. |
int eut::Blob::setCurrentPosition | ( | std::size_t | nNewPosition | ) |
Sets the current position in the blob.
[in] | nNewPosition | The new position of the current pointer in the blob (smallest value 1). |
int eut::Blob::setData | ( | char * | pData, |
std::size_t | nDataSize, | ||
bool | bCopy = true ) |
Sets the blob.
[in] | pData | A pointer to an allocated memory. |
[in] | nDataSize | The size of pData. |
[in] | bCopy | If false, pData is not copied, but only m_pBlob is set to pData. |
void eut::Blob::setMemResponsible | ( | bool | bActiv = true | ) |
Sets the responsibility over the memory of the blob.
[in] | bActiv | If 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. |
void eut::Blob::setNULL | ( | ) |
Sets m_pBlob to nullptr and m_nSize and m_nCurrentPosition to 0 without removing the m_pBlob from memory!
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.
[in,out] | rSwapBlob | The blob with which the content is to be swapped. |
|
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.
|
protected |
The current position in the blob (starts at 0).
|
protected |
The size of the blob.
|
protected |
The blob.