LLBufferArray Class Reference

Class to represent scattered memory buffers and in-order segments of that buffered data. More...

#include <llbuffer.h>

Collaboration diagram for LLBufferArray:

Collaboration graph
[legend]
List of all members.
LLChannelDescriptors nextChannel ()
 Generate the next channel descriptor for this buffer array.
static LLChannelDescriptors makeChannelConsumer (const LLChannelDescriptors &channels)
 Generate the a channel descriptor which consumes the output for the channel passed in.

Public Types

typedef std::vector< LLBuffer * > buffer_list_t
typedef buffer_list_t::iterator buffer_iterator_t
typedef buffer_list_t::const_iterator const_buffer_iterator_t
typedef std::list< LLSegmentsegment_list_t
typedef segment_list_t::const_iterator const_segment_iterator_t
typedef segment_list_t::iterator segment_iterator_t
 npos = 0xffffffff
enum  { npos = 0xffffffff }

Public Member Functions

 LLBufferArray ()
 ~LLBufferArray ()
S32 capacity () const
 Return the sum of all allocated bytes.
bool append (S32 channel, const U8 *src, S32 len)
 Put data on a channel at the end of this buffer array.
bool prepend (S32 channel, const U8 *src, S32 len)
 Put data on a channel at the front of this buffer array.
bool insertAfter (segment_iterator_t segment, S32 channel, const U8 *src, S32 len)
 Insert data into a buffer array after a particular segment.
S32 countAfter (S32 channel, U8 *start) const
 Count bytes in the buffer array on the specified channel.
U8readAfter (S32 channel, U8 *start, U8 *dest, S32 &len) const
 Read bytes in the buffer array on the specified channel.
U8seek (S32 channel, U8 *start, S32 delta) const
 Find an address in a buffer array.
bool takeContents (LLBufferArray &source)
 Take the contents of another buffer array.
segment_iterator_t splitAfter (U8 *address)
 Split a segments so that address is the last address of one segment, and the rest of the original segment becomes another segment on the same channel.
segment_iterator_t beginSegment ()
 Get the first segment in the buffer array.
segment_iterator_t endSegment ()
 Get the one-past-the-end segment in the buffer array.
const_segment_iterator_t getSegment (U8 *address) const
 Get the segment which holds the given address.
segment_iterator_t getSegment (U8 *address)
 Get the segment which holds the given address.
segment_iterator_t constructSegmentAfter (U8 *address, LLSegment &segment)
 Get a segment iterator after address, and a constructed segment to represent the next linear block of memory.
segment_iterator_t makeSegment (S32 channel, S32 length)
 Make a new segment at the end of buffer array.
bool eraseSegment (const segment_iterator_t &iter)
 Erase the segment if it is in the buffer array.

Protected Member Functions

bool copyIntoBuffers (S32 channel, const U8 *src, S32 len, std::vector< LLSegment > &segments)
 Optimally put data in buffers, and reutrn segments.

Protected Attributes

S32 mNextBaseChannel
buffer_list_t mBuffers
segment_list_t mSegments

Detailed Description

Class to represent scattered memory buffers and in-order segments of that buffered data.

*NOTE: This class needs to have an iovec interface

Definition at line 304 of file llbuffer.h.


Member Typedef Documentation

typedef buffer_list_t::iterator LLBufferArray::buffer_iterator_t

Definition at line 308 of file llbuffer.h.

typedef std::vector<LLBuffer*> LLBufferArray::buffer_list_t

Definition at line 307 of file llbuffer.h.

typedef buffer_list_t::const_iterator LLBufferArray::const_buffer_iterator_t

Definition at line 309 of file llbuffer.h.

typedef segment_list_t::const_iterator LLBufferArray::const_segment_iterator_t

Definition at line 311 of file llbuffer.h.

typedef segment_list_t::iterator LLBufferArray::segment_iterator_t

Definition at line 312 of file llbuffer.h.

typedef std::list<LLSegment> LLBufferArray::segment_list_t

Definition at line 310 of file llbuffer.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
npos 

Definition at line 313 of file llbuffer.h.


Constructor & Destructor Documentation

LLBufferArray::LLBufferArray (  ) 

LLBufferArray

Definition at line 231 of file llbuffer.cpp.

References LLMemType::MTYPE_IO_BUFFER.

LLBufferArray::~LLBufferArray (  ) 

Definition at line 237 of file llbuffer.cpp.

References mBuffers, and LLMemType::MTYPE_IO_BUFFER.


Member Function Documentation

bool LLBufferArray::append ( S32  channel,
const U8 src,
S32  len 
)

Put data on a channel at the end of this buffer array.

The data is copied from src into the buffer array. At least one new segment is created and put on the end of the array. This object will internally allocate new buffers if necessary.

Parameters:
channel The channel for this data
src The start of memory for the data to be copied
len The number of bytes of data to copy
Returns:
Returns true if the method worked.

Definition at line 269 of file llbuffer.cpp.

References copyIntoBuffers(), mSegments, and LLMemType::MTYPE_IO_BUFFER.

Referenced by LLURLRequest::downCallback().

LLBufferArray::segment_iterator_t LLBufferArray::beginSegment (  ) 

Get the first segment in the buffer array.

Returns:
Returns the segment if there is one.

Definition at line 343 of file llbuffer.cpp.

References mSegments.

S32 LLBufferArray::capacity (  )  const

Return the sum of all allocated bytes.

Definition at line 257 of file llbuffer.cpp.

References end, mBuffers, and S32.

LLBufferArray::segment_iterator_t LLBufferArray::constructSegmentAfter ( U8 address,
LLSegment segment 
)

Get a segment iterator after address, and a constructed segment to represent the next linear block of memory.

This method is a helper by giving you the largest segment possible in the out-value param after the address provided. The iterator will be useful for iteration, while the segment can be used for direct access to memory after address if the return values isnot end. Passing in NULL will return beginSegment() which may be endSegment(). The segment returned will only be zero length if the return value equals end. This is really just a helper method, since all the information returned could be constructed through other methods.

Parameters:
address An address in the middle of the sought segment.
segment[out] segment to be used for reading or writing
Returns:
Returns an iterator which contains at least segment or endSegment() on failure.

Definition at line 353 of file llbuffer.cpp.

References end, mSegments, and LLMemType::MTYPE_IO_BUFFER.

Referenced by LLBufferStreamBuf::underflow().

bool LLBufferArray::copyIntoBuffers ( S32  channel,
const U8 src,
S32  len,
std::vector< LLSegment > &  segments 
) [protected]

Optimally put data in buffers, and reutrn segments.

This is an internal function used to create buffers as necessary, and sequence the segments appropriately for the various ways to copy data from src into this. If this method fails, it may actually leak some space inside buffers, but I am not too worried about the slim possibility that we may have some 'dead' space which will be recovered when the buffer (which we will not lose) is deleted. Addressing this weakness will make the buffers almost as complex as a general memory management system.

Parameters:
channel The channel for this data
src The start of memory for the data to be copied
len The number of bytes of data to copy
segments Out-value for the segments created.
Returns:
Returns true if the method worked.

Definition at line 801 of file llbuffer.cpp.

References LLBuffer::createSegment(), LLSegment::data(), end, llmin(), mBuffers, LLMemType::MTYPE_IO_BUFFER, S32, and LLSegment::size().

Referenced by append(), insertAfter(), and prepend().

S32 LLBufferArray::countAfter ( S32  channel,
U8 start 
) const

Count bytes in the buffer array on the specified channel.

Parameters:
channel The channel to count.
start The start address in the array for counting. You can specify NULL to start at the beginning.
Returns:
Returns the number of bytes in the channel after start

Definition at line 469 of file llbuffer.cpp.

References count, end, getSegment(), mSegments, and S32.

Referenced by LLURLRequest::configure(), and LLURLRequest::upCallback().

LLBufferArray::segment_iterator_t LLBufferArray::endSegment (  ) 

Get the one-past-the-end segment in the buffer array.

Returns:
Returns the iterator for an invalid segment location.

Definition at line 348 of file llbuffer.cpp.

References mSegments.

Referenced by LLBufferStreamBuf::overflow(), LLBufferStreamBuf::sync(), and LLBufferStreamBuf::underflow().

bool LLBufferArray::eraseSegment ( const segment_iterator_t iter  ) 

Erase the segment if it is in the buffer array.

Parameters:
iter An iterator referring to the segment to erase.
Returns:
Returns true on success.

Definition at line 773 of file llbuffer.cpp.

References end, mBuffers, mSegments, LLMemType::MTYPE_IO_BUFFER, and void.

Referenced by LLBufferStreamBuf::sync(), and LLBufferStreamBuf::underflow().

LLBufferArray::segment_iterator_t LLBufferArray::getSegment ( U8 address  ) 

Get the segment which holds the given address.

As opposed to some methods, passing a NULL will result in returning the end segment.

Parameters:
address An address in the middle of the sought segment.
Returns:
Returns the iterator for the segment or endSegment() on failure.

Definition at line 403 of file llbuffer.cpp.

References end, and mSegments.

LLBufferArray::const_segment_iterator_t LLBufferArray::getSegment ( U8 address  )  const

Get the segment which holds the given address.

As opposed to some methods, passing a NULL will result in returning the end segment.

Parameters:
address An address in the middle of the sought segment.
Returns:
Returns the iterator for the segment or endSegment() on failure.

Definition at line 422 of file llbuffer.cpp.

References end, and mSegments.

Referenced by countAfter(), readAfter(), seek(), and splitAfter().

bool LLBufferArray::insertAfter ( segment_iterator_t  segment,
S32  channel,
const U8 src,
S32  len 
)

Insert data into a buffer array after a particular segment.

The data is copied from src into the buffer array. At least one new segment is created and put in the array. This object will internally allocate new buffers if necessary.

Parameters:
segment The segment in front of the new segments location
channel The channel for this data
src The start of memory for the data to be copied
len The number of bytes of data to copy
Returns:
Returns true if the method worked.

Definition at line 293 of file llbuffer.cpp.

References copyIntoBuffers(), mSegments, and LLMemType::MTYPE_IO_BUFFER.

LLChannelDescriptors LLBufferArray::makeChannelConsumer ( const LLChannelDescriptors channels  )  [static]

Generate the a channel descriptor which consumes the output for the channel passed in.

Definition at line 244 of file llbuffer.cpp.

References LLChannelDescriptors::out().

Referenced by LLURLRequest::process_impl(), and LLHTTPResponder::process_impl().

LLBufferArray::segment_iterator_t LLBufferArray::makeSegment ( S32  channel,
S32  length 
)

Make a new segment at the end of buffer array.

This method will attempt to create a new and empty segment of the specified length. The segment created may be shorter than requested.

Parameters:
channel[in] The channel for the newly created segment.
length[in] The requested length of the segment.
Returns:
Returns an iterator which contains at least segment or endSegment() on failure.

Definition at line 734 of file llbuffer.cpp.

References LLBuffer::createSegment(), end, mBuffers, mSegments, and LLMemType::MTYPE_IO_BUFFER.

Referenced by LLBufferStreamBuf::overflow().

LLChannelDescriptors LLBufferArray::nextChannel (  ) 

Generate the next channel descriptor for this buffer array.

The channel descriptor interface is how the buffer array clients can know where to read and write data. Use this interface to get the 'next' channel set for usage. This is a bit of a simple hack until it's utility indicates it should be extended.

Returns:
Returns a valid channel descriptor set for input and output.

Definition at line 251 of file llbuffer.cpp.

References mNextBaseChannel.

bool LLBufferArray::prepend ( S32  channel,
const U8 src,
S32  len 
)

Put data on a channel at the front of this buffer array.

The data is copied from src into the buffer array. At least one new segment is created and put in the front of the array. This object will internally allocate new buffers if necessary.

Parameters:
channel The channel for this data
src The start of memory for the data to be copied
len The number of bytes of data to copy
Returns:
Returns true if the method worked.

Definition at line 281 of file llbuffer.cpp.

References copyIntoBuffers(), mSegments, and LLMemType::MTYPE_IO_BUFFER.

U8 * LLBufferArray::readAfter ( S32  channel,
U8 start,
U8 dest,
S32 len 
) const

Read bytes in the buffer array on the specified channel.

You should prefer iterating over segments is possible since this method requires you to allocate large buffers - precisely what this class is trying to prevent. This method will skip any segments which are not on the given channel, so this method would usually be used to read a channel and copy that to a log or a socket buffer or something.

Parameters:
channel The channel to read.
start The start address in the array for reading. You can specify NULL to start at the beginning.
dest The destination of the data read. This must be at least len bytes long.
len[in,out] in How many bytes to read. out How many bytes were read.
Returns:
Returns the address of the last read byte.

Definition at line 509 of file llbuffer.cpp.

References end, getSegment(), llmin(), mSegments, LLMemType::MTYPE_IO_BUFFER, and S32.

Referenced by LLURLRequest::upCallback().

U8 * LLBufferArray::seek ( S32  channel,
U8 start,
S32  delta 
) const

Find an address in a buffer array.

Parameters:
channel The channel to seek in.
start The start address in the array for the seek operation. You can specify NULL to start the seek at the beginning, or pass in npos to start at the end.
delta How many bytes to seek through the array.
Returns:
Returns the address of the last read byte.

Definition at line 571 of file llbuffer.cpp.

References end, getSegment(), llabs(), llmin(), mSegments, LLMemType::MTYPE_IO_BUFFER, npos, NULL, and S32.

Referenced by LLBufferStreamBuf::sync().

LLBufferArray::segment_iterator_t LLBufferArray::splitAfter ( U8 address  ) 

Split a segments so that address is the last address of one segment, and the rest of the original segment becomes another segment on the same channel.

After this method call, getLastSegmentAddress(*getSegment(address)) == address should be true. This call will only create a new segment if the statement above is false before the call. Since you usually call splitAfter() to change a segment property, use getSegment() to perform those operations.

Parameters:
address The address which will become the last address of the segment it is in.
Returns:
Returns an iterator to the segment which contains address which is endSegment() on failure.

Definition at line 313 of file llbuffer.cpp.

References base, end, getSegment(), mSegments, LLMemType::MTYPE_IO_BUFFER, S32, and size.

Referenced by LLBufferStreamBuf::sync(), and LLBufferStreamBuf::underflow().

bool LLBufferArray::takeContents ( LLBufferArray source  ) 

Take the contents of another buffer array.

This method simply strips the contents out of the source buffery array - segments, buffers, etc, and appends them to this instance. After this operation, the source is empty and ready for reuse.

Parameters:
source The source buffer
Returns:
Returns true if the operation succeeded.

Definition at line 717 of file llbuffer.cpp.

References mBuffers, mNextBaseChannel, mSegments, and LLMemType::MTYPE_IO_BUFFER.


Member Data Documentation

buffer_list_t LLBufferArray::mBuffers [protected]

Definition at line 589 of file llbuffer.h.

Referenced by capacity(), copyIntoBuffers(), eraseSegment(), makeSegment(), takeContents(), and ~LLBufferArray().

S32 LLBufferArray::mNextBaseChannel [protected]

Definition at line 588 of file llbuffer.h.

Referenced by nextChannel(), and takeContents().

segment_list_t LLBufferArray::mSegments [protected]

Definition at line 590 of file llbuffer.h.

Referenced by append(), beginSegment(), constructSegmentAfter(), countAfter(), endSegment(), eraseSegment(), getSegment(), insertAfter(), makeSegment(), prepend(), readAfter(), seek(), splitAfter(), and takeContents().


The documentation for this class was generated from the following files:
Generated on Thu Jul 1 06:11:11 2010 for Second Life Viewer by  doxygen 1.4.7