Quick Links:

bal | bbl | bdl | bsl

Public Member Functions | Friends

bdlbb::Blob Class Reference

#include <bdlbb_blob.h>

List of all members.

Public Member Functions

 Blob (bslma::Allocator *basicAllocator=0)
 Blob (BlobBufferFactory *factory, bslma::Allocator *basicAllocator=0)
 Blob (const BlobBuffer *buffers, int numBuffers, BlobBufferFactory *factory, bslma::Allocator *basicAllocator=0)
 Blob (const Blob &original, BlobBufferFactory *factory, bslma::Allocator *basicAllocator=0)
 Blob (const Blob &original, bslma::Allocator *basicAllocator=0)
 Blob (bslmf::MovableRef< Blob > original) BSLS_KEYWORD_NOEXCEPT
 Blob (bslmf::MovableRef< Blob > original, bslma::Allocator *basicAllocator)
 ~Blob ()
Bloboperator= (const Blob &rhs)
Bloboperator= (bslmf::MovableRef< Blob > rhs)
void appendBuffer (const BlobBuffer &buffer)
void appendBuffer (bslmf::MovableRef< BlobBuffer > buffer)
void appendDataBuffer (const BlobBuffer &buffer)
void appendDataBuffer (bslmf::MovableRef< BlobBuffer > buffer)
void insertBuffer (int index, const BlobBuffer &buffer)
void insertBuffer (int index, bslmf::MovableRef< BlobBuffer > buffer)
void prependDataBuffer (const BlobBuffer &buffer)
void prependDataBuffer (bslmf::MovableRef< BlobBuffer > buffer)
void removeAll ()
void removeBuffer (int index)
void removeBuffers (int index, int numBuffers)
void removeUnusedBuffers ()
void replaceDataBuffer (int index, const BlobBuffer &buffer)
void reserveBufferCapacity (int numBuffers)
void setLength (int length)
void swap (Blob &other)
void swapBufferRaw (int index, BlobBuffer *srcBuffer)
BlobBuffer trimLastDataBuffer ()
void moveBuffers (Blob *srcBlob)
void moveDataBuffers (Blob *srcBlob)
void moveAndAppendDataBuffers (Blob *srcBlob)
bslma::Allocatorallocator () const
const BlobBufferbuffer (int index) const
BlobBufferFactoryfactory () const
int lastDataBufferLength () const
int length () const
int numDataBuffers () const
int numBuffers () const
int totalSize () const

Friends

bool operator== (const Blob &, const Blob &)
bool operator!= (const Blob &, const Blob &)

Detailed Description

Blob is an in-core container for BlobBuffer objects. This class is exception-neutral with no guarantee of rollback: if an exception is thrown during the invocation of a method on a pre-existing instance, the container is left in a valid state, but its value is undefined. In no event is memory leaked.

See Component bdlbb_blob


Constructor & Destructor Documentation

bdlbb::Blob::Blob ( bslma::Allocator basicAllocator = 0  )  [explicit]

Create an empty blob having no factory to allocate blob buffers. Since there is no factory, the behavior is undefined if the length of the blob is set beyond the total size. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlbb::Blob::Blob ( BlobBufferFactory factory,
bslma::Allocator basicAllocator = 0 
) [explicit]

Create an empty blob using the specified factory to allocate blob buffers. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlbb::Blob::Blob ( const BlobBuffer buffers,
int  numBuffers,
BlobBufferFactory factory,
bslma::Allocator basicAllocator = 0 
)

Create a blob that initially holds the specified numBuffers buffers referenced by the specified buffers, and uses the specified factory to allocate blob buffers. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlbb::Blob::Blob ( const Blob original,
BlobBufferFactory factory,
bslma::Allocator basicAllocator = 0 
)

Create a blob that holds the same buffers as the specified original blob, and uses the specified factory to allocate blob buffers. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlbb::Blob::Blob ( const Blob original,
bslma::Allocator basicAllocator = 0 
)

Create a blob that holds the same buffers as the specified original blob, and has no factory to allocate blob buffers. Since there is no factory, the behavior is undefined if the length of the blob is set beyond the total size. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

bdlbb::Blob::Blob ( bslmf::MovableRef< Blob original  ) 

Create a blob object having the same value as the specified original object by moving the contents of original to the newly-created object. The allocator associated with original is propagated for use in the newly-created object. original is left in a valid but unspecified state.

bdlbb::Blob::Blob ( bslmf::MovableRef< Blob original,
bslma::Allocator basicAllocator 
)

Create a blob object having the same value as the specified original object that uses the specified basicAllocator to supply memory. If basicAllocator is 0, the currently installed default allocator is used. The contents of original are moved to the newly-created object. original is left in a valid but unspecified state.

bdlbb::Blob::~Blob (  ) 

Destroy this blob.


Member Function Documentation

Blob& bdlbb::Blob::operator= ( const Blob rhs  ) 

Assign to this blob the value of the specified rhs blob, and return a reference to this modifiable blob.

Blob& bdlbb::Blob::operator= ( bslmf::MovableRef< Blob rhs  ) 

Assign to this object the value of the specified rhs, and return a reference providing modifiable access to this object. The contents of rhs are move-assigned to this object. rhs is left in a valid but unspecified state.

void bdlbb::Blob::appendBuffer ( const BlobBuffer buffer  ) 

Append the specified buffer after the last buffer of this blob. The length of this blob is unaffected. The behavior is undefined unless neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX. Note that this operation is equivalent to insertBuffer(numBuffers(), buffer), but is more efficient.

void bdlbb::Blob::appendBuffer ( bslmf::MovableRef< BlobBuffer buffer  ) 

Append the specified move-insertable buffer after the last buffer of this blob. The buffer is left in a valid but unspecified state. The length of this blob is unaffected. The behavior is undefined unless neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX. Note that this operation is equivalent to insertBuffer(numBuffers(), buffer), but is more efficient.

void bdlbb::Blob::appendDataBuffer ( const BlobBuffer buffer  ) 

Append the specified buffer after the last data buffer of this blob; the last data buffer is trimmed, if necessary. The length of this blob is incremented by the size of buffer. The behavior is undefined unless neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX. Note that this operation is equivalent to:

          const int n = blob.length();
          blob.trimLastDataBuffer();
          blob.insertBuffer(numDataBuffers(), buffer);
          blob.setLength(n + buffer.size());

but is more efficient.

void bdlbb::Blob::appendDataBuffer ( bslmf::MovableRef< BlobBuffer buffer  ) 

Append the specified move-insertable buffer after the last data buffer of this blob; the last data buffer is trimmed, if necessary. The buffer is left in a valid but unspecified state. The length of this blob is incremented by the size of buffer. The behavior is undefined unless neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX. Note that this operation is equivalent to:

          const int n = blob.length();
          blob.trimLastDataBuffer();
          blob.insertBuffer(numDataBuffers(), MoveUtil::move(buffer));
          blob.setLength(n + buffer.size());

but is more efficient.

void bdlbb::Blob::insertBuffer ( int  index,
const BlobBuffer buffer 
)

Insert the specified buffer at the specified index in this blob. Increment the length of this blob by the size of buffer if buffer is inserted before the logical end of this blob. The length of this blob 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. The behavior is undefined unless 0 <= index <= numBuffers() and neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX.

void bdlbb::Blob::insertBuffer ( int  index,
bslmf::MovableRef< BlobBuffer buffer 
)

Insert the specified move-insertable buffer at the specified index in this blob. Increment the length of this blob by the size of buffer if buffer is inserted before the logical end of this blob. The length of this blob 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. The buffer is left in a valid but unspecified state. The behavior is undefined unless 0 <= index <= numBuffers() and neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX.

void bdlbb::Blob::prependDataBuffer ( const BlobBuffer buffer  ) 

Insert the specified buffer before the beginning of this blob. The length of this blob is incremented by the length of the prepended buffer. The behavior is undefined unless neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX. Note that this operation is equivalent to:

          const int n = blob.length();
          blob.insertBuffer(0, buffer);
          blob.setLength(n + buffer.size());

but is more efficient.

void bdlbb::Blob::prependDataBuffer ( bslmf::MovableRef< BlobBuffer buffer  ) 

Insert the specified move-insertable buffer before the beginning of this blob. The length of this blob is incremented by the length of the prepended buffer. The buffer is left in a valid but unspecified state. The behavior is undefined unless neither the total size of the resulting blob nor its total number of buffers exceeds INT_MAX. Note that this operation is equivalent to:

          const int n = blob.length();
          blob.insertBuffer(0, MoveUtil::move(buffer));
          blob.setLength(n + buffer.size());

but is more efficient.

void bdlbb::Blob::removeAll (  ) 

Remove all blob buffers from this blob, and set its length to 0.

void bdlbb::Blob::removeBuffer ( int  index  ) 

Remove the buffer at the specified index from this blob, and decrement the length of this blob by the size of buffer if the buffer at index contains data bytes (i.e., if the first byte of buffer occurs before the logical end of this blob). Buffers at positions higher than index (if any) are shifted down by one index position. The behavior is undefined unless 0 <= index < numBuffers().

void bdlbb::Blob::removeBuffers ( int  index,
int  numBuffers 
)

Remove the specified numBuffers starting at the specified index from this blob. Buffers at positions higher than index (if any) are shifted down by numBuffers index positions. The behavior is undefined unless 0 <= index, 0 <= numBuffers, and index + numBuffers <= numBuffers().

void bdlbb::Blob::removeUnusedBuffers (  ) 

Remove any unused capacity buffers from this blob. Note that this method does not trim the last data buffer, and that the resulting totalSize will be length plus any unused capacity in the last buffer having data.

void bdlbb::Blob::replaceDataBuffer ( int  index,
const BlobBuffer buffer 
)

Replace the data buffer at the specified index with the specified buffer. The behavior is undefined unless 0 <= index < numDataBuffers() and the total size of the resulting blob does not exceed INT_MAX. Note that this operation is equivalent to:

          blob.removeBuffer(index);
          const int n = blob.length();
          blob.insertBuffer(index, buffer);
          blob.setLength(n + buffer.size());

but is more efficient.

void bdlbb::Blob::reserveBufferCapacity ( int  numBuffers  ) 

Allocate sufficient capacity to store at least the specified numBuffers buffers. The behavior is undefined unless 0 <= numBuffers. Note that this method does not change the length of this blob or add any buffers to it. Note also that the internal capacity will be increased to maintain a geometric growth factor.

void bdlbb::Blob::setLength ( int  length  ) 

Set the length of this blob to the specified length and, if length is greater than its total size, grow this blob by appending buffers allocated using this object's underlying BlobBufferFactory. The behavior is undefined if length is a negative value, or if the new length requires growing the blob and this blob has no underlying factory.

void bdlbb::Blob::swap ( Blob other  ) 

Efficiently exchange the value of this object with the value of the specified other object. This method provides the no-throw exception-safety guarantee. The behavior is undefined unless this object was created with the same allocator as other.

void bdlbb::Blob::swapBufferRaw ( int  index,
BlobBuffer srcBuffer 
)

Swap the blob buffer at the specified index with the specified srcBuffer. The behavior is undefined unless 0 <= index < numBuffers() and srcBuffer->size() == buffer(index).size(). Note that other than the buffer swap the state of this object remains unchanged.

BlobBuffer bdlbb::Blob::trimLastDataBuffer (  ) 

Set the size of the last data buffer to lastDataBufferLength(). If there are no data buffers, or if the last data buffer is full (i.e., its size is lastDataBufferLength()), then this method has no effect. Return the leftover of the trimmed buffer or default constructed BlobBuffer if nothing to trim. Note that the length of the blob is unchanged, and that capacity buffers (i.e., of indices numDataBuffers() and higher) are not removed.

void bdlbb::Blob::moveBuffers ( Blob srcBlob  ) 

Remove all blob buffers from this blob and move the buffers held by the specified srcBlob to this blob. Note that this method is logically equivalent to:

          *this = *srcBlob;
          srcBlob->removeAll();

but its implementation is more efficient.

void bdlbb::Blob::moveDataBuffers ( Blob srcBlob  ) 

Remove all blob buffers from this blob and move the data buffers held by the specified srcBlob to this blob.

void bdlbb::Blob::moveAndAppendDataBuffers ( Blob srcBlob  ) 

Move the data buffers held by the specified srcBlob to this blob appending them to the current data buffers of this blob. The behavior is undefined unless the total size of the resulting blob and the total number of buffers in this blob are less than or equal to INT_MAX.

bslma::Allocator* bdlbb::Blob::allocator (  )  const

Return the allocator used by this object to supply memory.

const BlobBuffer& bdlbb::Blob::buffer ( int  index  )  const

Return a reference to the non-modifiable blob buffer at the specified index in this blob. The behavior is undefined unless 0 <= index < numBuffers().

BlobBufferFactory* bdlbb::Blob::factory (  )  const

Return the factory used by this object.

int bdlbb::Blob::lastDataBufferLength (  )  const

Return the length of the last blob buffer in this blob, or 0 if this blob is of 0 length.

int bdlbb::Blob::length (  )  const

Return the length of this blob.

int bdlbb::Blob::numDataBuffers (  )  const

Return the number of blob buffers containing data in this blob.

int bdlbb::Blob::numBuffers (  )  const

Return the number of blob buffers held by this blob.

int bdlbb::Blob::totalSize (  )  const

Return the sum of the sizes of all blob buffers in this blob (i.e., the capacity of this blob).


Friends And Related Function Documentation

bool operator== ( const Blob ,
const Blob  
) [friend]

Return true if the specified lhs and rhs blobs have the same value, and false otherwise. Two blobs have the same value if they hold the same buffers, and have the same length.

bool operator!= ( const Blob ,
const Blob  
) [friend]

Return true if the specified lhs and rhs blobs do not have the same value, and false otherwise. Two blobs do not have the same value if they do not hold the same buffers, or do not have the same length.


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