BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlbb::BlobUtil Struct Reference

#include <bdlbb_blobutil.h>

Static Public Member Functions

static void append (Blob *dest, const Blob &source, int offset, int length)
 
static void append (Blob *dest, const Blob &source, int offset)
 
static void append (Blob *dest, const Blob &source)
 
static void append (Blob *dest, const char *source, int offset, int length)
 
static void append (Blob *dest, const char *source, int length)
 
static void append (Blob *dest, int length, char fill)
 
static void appendWithCapacityBuffer (Blob *dest, BlobBuffer *buffer, const char *source, int length)
 
static void erase (Blob *blob, int offset, int length)
 
static void insert (Blob *dest, int destOffset, const Blob &source, int sourceOffset, int sourceLength)
 
static void insert (Blob *dest, int destOffset, const Blob &source, int sourceOffset)
 
static void insert (Blob *dest, int destOffset, const Blob &source)
 
static bsl::pair< int, int > findBufferIndexAndOffset (const Blob &blob, int position)
 
static void copy (char *dstBuffer, const Blob &srcBlob, int position, int length)
 
static void copy (Blob *dst, int dstOffset, const char *src, int length)
 
static void copy (Blob *dst, int dstOffset, const Blob &src, int srcOffset, int length)
 
static char * getContiguousRangeOrCopy (char *dstBuffer, const Blob &srcBlob, int position, int length, int alignment=1)
 
static char * getContiguousDataBuffer (Blob *blob, int addLength, BlobBufferFactory *factory)
 
static bsl::ostream & asciiDump (bsl::ostream &stream, const Blob &source)
 
static bsl::ostream & asciiDump (bsl::ostream &stream, const Blob &source, int offset, int length)
 
static bsl::ostream & hexDump (bsl::ostream &stream, const Blob &source)
 
static bsl::ostream & hexDump (bsl::ostream &stream, const Blob &source, int offset, int length)
 
static void padToAlignment (Blob *dest, int alignment, char fillChar='\0')
 
static void prependWithCapacityBuffer (Blob *dest, BlobBuffer *buffer, const char *source, int length)
 
template<class STREAM >
static STREAM & read (STREAM &stream, Blob *dest, int numBytes)
 
template<class STREAM >
static STREAM & write (STREAM &stream, const Blob &source)
 
template<class STREAM >
static int write (STREAM &stream, const Blob &source, int sourcePosition, int numBytes)
 
static int compare (const Blob &a, const Blob &b)
 
static int appendBufferIfValid (Blob *dest, const BlobBuffer &buffer)
 
static int appendBufferIfValid (Blob *dest, bslmf::MovableRef< BlobBuffer > buffer)
 
static int appendDataBufferIfValid (Blob *dest, const BlobBuffer &buffer)
 
static int appendDataBufferIfValid (Blob *dest, bslmf::MovableRef< BlobBuffer > buffer)
 
static int insertBufferIfValid (Blob *dest, int index, const BlobBuffer &buffer)
 
static int insertBufferIfValid (Blob *dest, int index, bslmf::MovableRef< BlobBuffer > buffer)
 
static int prependDataBufferIfValid (Blob *dest, const BlobBuffer &buffer)
 
static int prependDataBufferIfValid (Blob *dest, bslmf::MovableRef< BlobBuffer > buffer)
 
static void append (Blob *dest, const Blob &source, int offset, int length, bslma::Allocator *)
 
static void append (Blob *dest, const Blob &source, int offset, bslma::Allocator *)
 
static void append (Blob *dest, const Blob &source, bslma::Allocator *)
 

Detailed Description

This struct is a namespace for a collection of static methods used for manipulating and accessing Blob objects.

Member Function Documentation

◆ append() [1/9]

void bdlbb::BlobUtil::append ( Blob dest,
const Blob source 
)
inlinestatic

Append the specified source to the specified dest. Note that the data memory from source is not copied, but rather new BlobBuffers referring to the same data memory are created and appended to dest, hence dest is not required to have a BlobBufferFactory.

◆ append() [2/9]

void bdlbb::BlobUtil::append ( Blob dest,
const Blob source,
bslma::Allocator  
)
inlinestatic

◆ append() [3/9]

void bdlbb::BlobUtil::append ( Blob dest,
const Blob source,
int  offset 
)
inlinestatic

Append from the specified offset in the specified source to the specified dest. Note that the data memory from source is not copied, but rather new BlobBuffers referring to the same data memory are created and appended to dest, hence dest is not required to have a BlobBufferFactory.

◆ append() [4/9]

void bdlbb::BlobUtil::append ( Blob dest,
const Blob source,
int  offset,
bslma::Allocator  
)
inlinestatic

◆ append() [5/9]

static void bdlbb::BlobUtil::append ( Blob dest,
const Blob source,
int  offset,
int  length 
)
static

Append the specified length bytes from the specified offset in the specified source to the specified dest. Note that the data memory from source is not copied, but rather new BlobBuffers referring to the same data memory are created and appended to dest, hence dest is not required to have a BlobBufferFactory.

◆ append() [6/9]

void bdlbb::BlobUtil::append ( Blob dest,
const Blob source,
int  offset,
int  length,
bslma::Allocator  
)
inlinestatic

◆ append() [7/9]

void bdlbb::BlobUtil::append ( Blob dest,
const char *  source,
int  length 
)
inlinestatic

Append the specified length bytes starting from the specified source address to the specified dest. The behavior is undefined unless the range [source, source + length) is valid memory, and length <= dest->totalSize() - dest->length() or 0 != dest->factory().

◆ append() [8/9]

static void bdlbb::BlobUtil::append ( Blob dest,
const char *  source,
int  offset,
int  length 
)
static

Append the specified length bytes starting from the specified offset from the specified source address to the specified dest. The behavior of this function is undefined unless the range [source + offset, source + offset + length) represents a readable sequence of memory, and length <= dest->totalSize() - dest->length() or 0 != dest->factory().

◆ append() [9/9]

static void bdlbb::BlobUtil::append ( Blob dest,
int  length,
char  fill 
)
static

Append the specified length bytes to the specified dest, all new bytes are to be set to the specified fill. The behavior is undefined unless length <= dest->totalSize() - dest->length() or 0 != dest->factory().

◆ appendBufferIfValid() [1/2]

int bdlbb::BlobUtil::appendBufferIfValid ( Blob dest,
bslmf::MovableRef< BlobBuffer buffer 
)
inlinestatic

Append the specified move-insertable buffer after the last buffer of the specified dest if neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. The length of the dest is unaffected. In case of success the buffer is left in a valid but unspecified state.

◆ appendBufferIfValid() [2/2]

int bdlbb::BlobUtil::appendBufferIfValid ( Blob dest,
const BlobBuffer buffer 
)
inlinestatic

Append the specified buffer after the last buffer of the specified dest if neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. The length of the dest is unaffected.

◆ appendDataBufferIfValid() [1/2]

int bdlbb::BlobUtil::appendDataBufferIfValid ( Blob dest,
bslmf::MovableRef< BlobBuffer buffer 
)
inlinestatic

Append the specified move-insertable buffer after the last data buffer of the specified dest if neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. The last data buffer of the dest is trimmed, if necessary. The length of the dest is incremented by the size of buffer. In case of success the buffer is left in a valid but unspecified state.

◆ appendDataBufferIfValid() [2/2]

int bdlbb::BlobUtil::appendDataBufferIfValid ( Blob dest,
const BlobBuffer buffer 
)
inlinestatic

Append the specified buffer after the last data buffer of the specified dest if neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. The last data buffer of the dest is trimmed, if necessary. The length of the dest is incremented by the size of buffer.

◆ appendWithCapacityBuffer()

static void bdlbb::BlobUtil::appendWithCapacityBuffer ( Blob dest,
BlobBuffer buffer,
const char *  source,
int  length 
)
static

Append the specified length bytes from the specified source address to the specified dest. Use the existing capacity in dest first, followed by that in the buffer, and finally allocate from the blob buffer factory associated with the dest. Load any unused space into the specified buffer. The behavior is undefined unless the range [source, source + length) represents a readable sequence of memory.

◆ asciiDump() [1/2]

static bsl::ostream & bdlbb::BlobUtil::asciiDump ( bsl::ostream &  stream,
const Blob source 
)
static

Write to the specified stream an ascii dump of the specified source, and return a reference to the modifiable stream.

◆ asciiDump() [2/2]

static bsl::ostream & bdlbb::BlobUtil::asciiDump ( bsl::ostream &  stream,
const Blob source,
int  offset,
int  length 
)
static

Write to the specified stream an ascii dump of the specified length bytes of the specified source starting at the specified offset, and return a reference to the modifiable stream. The behavior is undefined unless 0 <= offset, 0 <= length, length <= source.length() and offset <= source.length() - length.

◆ compare()

static int bdlbb::BlobUtil::compare ( const Blob a,
const Blob b 
)
static

Compare, lexicographically, the data (data length and character data values at each index position) stored by the specified a and b blobs. Return 0 if the data stored by a is lexicographically equal to the data stored by b, a negative value if a is lexicographically less than b, and a positive value if a is lexicographically greater than b.

◆ copy() [1/3]

static void bdlbb::BlobUtil::copy ( Blob dst,
int  dstOffset,
const Blob src,
int  srcOffset,
int  length 
)
static

Copy into the specified dst starting at the specified dstOffset the specified length bytes starting at the specified srcOffset in the specified src. The behavior is undefined unless 0 <= dstOffset, 0 <= srcOffset, 0 <= length, dst || 0 == length, !dst || dstOffset <= dst->length() - length, and srcOffset <= src->length() - length. Note that this operation does not require dst to have a blob buffer factory in that it does not create or destroy blobs – it simply copies data from src into dst, so dst must already have room for length bytes of data added at dstOffset.

◆ copy() [2/3]

static void bdlbb::BlobUtil::copy ( Blob dst,
int  dstOffset,
const char *  src,
int  length 
)
static

Copy into the specified dst starting at the specified dstOffset the specified length bytes from the specified src. The behavior is undefined unless 0 <= dstOffset, 0 <= length, dst || 0 == length, src || 0 == length, !dst || dstOffset <= dst->length() - length, and src refers to a buffer with at least length bytes. Note that this operation does not require dst to have a blob buffer factory in that it does not create or destroy blobs – it simply copies data from src into dst, so dst must already have room for length bytes of data added at dstOffset.

◆ copy() [3/3]

static void bdlbb::BlobUtil::copy ( char *  dstBuffer,
const Blob srcBlob,
int  position,
int  length 
)
static

Copy the specified length bytes starting at the specified position in the specified srcBlob to the specified dstBuffer. The behavior of this function is undefined unless 0 <= length, 0 <= position, position <= srcBlob.totalSize() - length, and dstBuffer has room for length bytes. Note that this function does not set dstBuffer[length] to 0.

◆ erase()

static void bdlbb::BlobUtil::erase ( Blob blob,
int  offset,
int  length 
)
static

Erase the specified length bytes starting at the specified offset from the specified blob. The behavior is undefined unless offset >= 0, length >= 0, and offset + length <= blob->length().

◆ findBufferIndexAndOffset()

static bsl::pair< int, int > bdlbb::BlobUtil::findBufferIndexAndOffset ( const Blob blob,
int  position 
)
static

Return a value, designated here as p, such that for the specified blob, blob.buffer(p.first) is the buffer that contains the byte at the specified position in blob, and p.second is the offset corresponding to position within said buffer. The behavior of this function is undefined unless 0 <= position, 0 < blob.totalSize(), and position < blob.totalSize(). Note that (1) subsequent changes to blob may invalidate the result of this function, and (2) p.first never indicates a zero-size buffer.

◆ getContiguousDataBuffer()

static char * bdlbb::BlobUtil::getContiguousDataBuffer ( Blob blob,
int  addLength,
BlobBufferFactory factory 
)
static

Obtain contiguous storage for at least the specified addLength bytes in the specified blob at position blob->length(), and then grow blob->length() by addLength. If, upon entry, such storage does not exist in blob, first trim the final data buffer, if any, and insert a new buffer obtained from the specified factory. Return a pointer to the beginning of the storage obtained. The behavior of this function is undefined unless 0 < addLength, and factory->allocate(), if called, yields a block of memory of a size at least as large as addLength.

◆ getContiguousRangeOrCopy()

static char * bdlbb::BlobUtil::getContiguousRangeOrCopy ( char *  dstBuffer,
const Blob srcBlob,
int  position,
int  length,
int  alignment = 1 
)
static

Return the address of the byte at the specified position in the specified srcBlob, if that address is aligned to the optionally specified alignment and the specified length bytes are stored contiguously; otherwise, copy length bytes to the specified buffer dstBuffer, and return dstBuffer. If alignment is not specified, none is enforced. (An address is aligned to A if, when converted to an integral value a, a & (A - 1) is 0.) The behavior of this function is undefined unless 0 < length, 0 <= position, alignment is a power of two, dstBuffer is aligned as required, dstBuffer has room for length bytes, and position <= srcBlob.totalSize() - length.

◆ hexDump() [1/2]

bsl::ostream & bdlbb::BlobUtil::hexDump ( bsl::ostream &  stream,
const Blob source 
)
inlinestatic

Write to the specified stream a hexdump of the specified source, and return a reference to the modifiable stream.

◆ hexDump() [2/2]

static bsl::ostream & bdlbb::BlobUtil::hexDump ( bsl::ostream &  stream,
const Blob source,
int  offset,
int  length 
)
static

Write to the specified stream a hexdump of the specified length bytes of the specified source starting at the specified offset, and return a reference to the modifiable stream. The behavior is undefined unless 0 <= offset, 0 <= length, length <= source.length() and offset <= source.length() - length.

◆ insert() [1/3]

void bdlbb::BlobUtil::insert ( Blob dest,
int  destOffset,
const Blob source 
)
inlinestatic

Insert the specified source to the specified destOffset in the specified dest.

◆ insert() [2/3]

void bdlbb::BlobUtil::insert ( Blob dest,
int  destOffset,
const Blob source,
int  sourceOffset 
)
inlinestatic

Insert from the specified sourceOffset in the specified source to the specified destOffset in the specified dest.

◆ insert() [3/3]

static void bdlbb::BlobUtil::insert ( Blob dest,
int  destOffset,
const Blob source,
int  sourceOffset,
int  sourceLength 
)
static

Insert the specified sourceLength bytes from the specified sourceOffset in the specified source to the specified destOffset in the specified dest.

◆ insertBufferIfValid() [1/2]

int bdlbb::BlobUtil::insertBufferIfValid ( Blob dest,
int  index,
bslmf::MovableRef< BlobBuffer buffer 
)
inlinestatic

Insert the specified move-insertable buffer at the specified index in the specified dest if 0 <= index <= dest->numBuffers() and neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. Increment the length of the 'dest by the size of the buffer if buffer is inserted before the logical end of the dest. The length of the dest is unchanged if inserting at a position following all data buffers (e.g., inserting into an empty blob or inserting a buffer to increase capacity); in that case, the blob length must be changed by an explicit call to setLength. Buffers at index and higher positions (if any) are shifted up by one index position. In case of success the buffer is left in a valid but unspecified state.

◆ insertBufferIfValid() [2/2]

int bdlbb::BlobUtil::insertBufferIfValid ( Blob dest,
int  index,
const BlobBuffer buffer 
)
inlinestatic

Insert the specified buffer at the specified index in the specified dest if 0 <= index <= dest->numBuffers() and neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. Increment the length of the 'dest by the size of the buffer if buffer is inserted before the logical end of the dest. The length of the dest is unchanged if inserting at a position following all data buffers (e.g., inserting into an empty blob or inserting a buffer to increase capacity); in that case, the blob length must be changed by an explicit call to setLength. Buffers at index and higher positions (if any) are shifted up by one index position.

◆ padToAlignment()

void bdlbb::BlobUtil::padToAlignment ( Blob dest,
int  alignment,
char  fillChar = '\0' 
)
inlinestatic

Append padding bytes to the specified dest so that its resulting length is an integer multiple of the specified alignment. Optionally specify fillChar with which the padding is to be filled. If fillChar is not specified, a 0 byte will be used. The behavior is undefined unless alignment is a power of 2, and less than or equal to 64.

◆ prependDataBufferIfValid() [1/2]

int bdlbb::BlobUtil::prependDataBufferIfValid ( Blob dest,
bslmf::MovableRef< BlobBuffer buffer 
)
inlinestatic

Insert the specified move-insertable buffer before the beginning of the specified dest if neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. The length of the dest is incremented by the length of the prepended buffer. In case of success the buffer is left in a valid but unspecified state.

◆ prependDataBufferIfValid() [2/2]

int bdlbb::BlobUtil::prependDataBufferIfValid ( Blob dest,
const BlobBuffer buffer 
)
inlinestatic

Insert the specified buffer before the beginning of the specified dest if neither the resulting total size of dest nor its resulting total number of buffers exceeds INT_MAX. Return 0 on success, and a non-zero value (with no effect) otherwise. The length of the dest is incremented by the length of the prepended buffer.

◆ prependWithCapacityBuffer()

static void bdlbb::BlobUtil::prependWithCapacityBuffer ( Blob dest,
BlobBuffer buffer,
const char *  source,
int  length 
)
static

Prepend the specified length bytes from the specified source address to the specified dest. Use the existing capacity in dest first if 0 == dest->length(), followed by that in the buffer, and finally allocate from the blob buffer factory associated with the dest. Load any unused space into the specified buffer. The behavior is undefined unless the range [source, source + length) represents a readable sequence of memory.

◆ read()

template<class STREAM >
STREAM & bdlbb::BlobUtil::read ( STREAM &  stream,
Blob dest,
int  numBytes 
)
static

Read the specified numBytes from the specified stream and load it into the specified dest, and return a reference to the modifiable stream.

◆ write() [1/2]

template<class STREAM >
STREAM & bdlbb::BlobUtil::write ( STREAM &  stream,
const Blob source 
)
static

Write the specified source to the specified stream, and return a reference to the modifiable stream.

◆ write() [2/2]

template<class STREAM >
int bdlbb::BlobUtil::write ( STREAM &  stream,
const Blob source,
int  sourcePosition,
int  numBytes 
)
static

Write to the specified stream the specified numBytes starting at the specified sourcePosition in the specified source blob. Return 0 on success or a non-zero value otherwise. Note that this function will fail (immediately) if the length of source is less than numBytes; or if there is any error writing to stream.


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