activemq-cpp-3.6.0
decaf::nio::CharBuffer Class Reference

This class defines four categories of operations upon character buffers: More...

#include <src/main/decaf/nio/CharBuffer.h>

Inheritance diagram for decaf::nio::CharBuffer:

Public Member Functions

virtual ~CharBuffer ()
virtual std::string toString () const
CharBufferappend (char value)
 Appends the specified character to this buffer.
CharBufferappend (const lang::CharSequence *value)
 Appends the specified character sequence to this buffer.
CharBufferappend (const lang::CharSequence *value, int start, int end)
 Appends a subsequence of the specified character sequence to this buffer If value is Null the the string "null" is appended to the buffer.
virtual char * array ()=0
 Returns the character array that backs this buffer (optional operation).
virtual int arrayOffset ()=0
 Returns the offset within this buffer's backing array of the first element of the buffer (optional operation).
virtual CharBufferasReadOnlyBuffer () const =0
 Creates a new, read-only char buffer that shares this buffer's content.
char charAt (int index) const
 Reads the character at the given index relative to the current position.
virtual CharBuffercompact ()=0
 Compacts this buffer.
virtual CharBufferduplicate ()=0
 Creates a new char buffer that shares this buffer's content.
virtual char get ()=0
 Relative get method.
virtual char get (int index) const =0
 Absolute get method.
CharBufferget (std::vector< char > buffer)
 Relative bulk get method.
CharBufferget (char *buffer, int size, int offset, int length)
 Relative bulk get method.
virtual bool hasArray () const =0
 Tells whether or not this buffer is backed by an accessible char array.
int length () const
 Returns the length of this character buffer.
CharBufferput (CharBuffer &src)
 This method transfers the chars remaining in the given source buffer into this buffer.
CharBufferput (const char *buffer, int size, int offset, int length)
 This method transfers chars into this buffer from the given source array.
CharBufferput (std::vector< char > &buffer)
 This method transfers the entire content of the given source char array into this buffer.
virtual CharBufferput (char value)=0
 Writes the given char into this buffer at the current position, and then increments the position.
virtual CharBufferput (int index, char value)=0
 Writes the given char into this buffer at the given index.
CharBufferput (std::string &src, int start, int end)
 Relative bulk put method (optional operation).
CharBufferput (const std::string &src)
 Relative bulk put method (optional operation).
virtual int read (CharBuffer *target)
 Attempts to read characters into the specified character buffer.
virtual lang::CharSequencesubSequence (int start, int end) const =0
 Creates a new character buffer that represents the specified subsequence of this buffer, relative to the current position.
virtual CharBufferslice () const =0
 Creates a new CharBuffer whose content is a shared subsequence of this buffer's content.
virtual int compareTo (const CharBuffer &value) const
 
virtual bool equals (const CharBuffer &value) const
 
virtual bool operator== (const CharBuffer &value) const
 
virtual bool operator< (const CharBuffer &value) const
 
- Public Member Functions inherited from decaf::nio::Buffer
 Buffer (int capactiy)
 Buffer (const Buffer &other)
virtual ~Buffer ()
virtual int capacity () const
virtual int position () const
virtual Bufferposition (int newPosition)
 Sets this buffer's position.
virtual int limit () const
virtual Bufferlimit (int newLimit)
 Sets this buffer's limit.
virtual Buffermark ()
 Sets this buffer's mark at its position.
virtual Bufferreset ()
 Resets this buffer's position to the previously-marked position.
virtual Bufferclear ()
 Clears this buffer.
virtual Bufferflip ()
 Flips this buffer.
virtual Bufferrewind ()
 Rewinds this buffer.
virtual int remaining () const
 Returns the number of elements between the current position and the limit.
virtual bool hasRemaining () const
 Tells whether there are any elements between the current position and the limit.
virtual bool isReadOnly () const =0
 Tells whether or not this buffer is read-only.
- Public Member Functions inherited from decaf::lang::CharSequence
virtual ~CharSequence ()
- Public Member Functions inherited from decaf::lang::Appendable
virtual ~Appendable ()
- Public Member Functions inherited from decaf::lang::Comparable< CharBuffer >
virtual ~Comparable ()
virtual int compareTo (const CharBuffer &value) const =0
 Compares this object with the specified object for order.
virtual bool equals (const CharBuffer &value) const =0
virtual bool operator== (const CharBuffer &value) const =0
 Compares equality between this object and the one passed.
virtual bool operator< (const CharBuffer &value) const =0
 Compares this object to another and returns true if this object is considered to be less than the one passed.

Static Public Member Functions

static CharBufferallocate (int capacity)
 Allocates a new character buffer.
static CharBufferwrap (char *array, int size, int offset, int length)
 Wraps the passed buffer with a new CharBuffer.
static CharBufferwrap (std::vector< char > &buffer)
 Wraps the passed STL char Vector in a CharBuffer.

Protected Member Functions

 CharBuffer (int capacity)
 Creates a CharBuffer object that has its backing array allocated internally and is then owned and deleted when this object is deleted.

Additional Inherited Members

- Protected Attributes inherited from decaf::nio::Buffer
int _position
int _capacity
int _limit
int _mark
bool _markSet

Detailed Description

This class defines four categories of operations upon character buffers:

o Absolute and relative get and put methods that read and write single characters; o Relative bulk get methods that transfer contiguous sequences of characters from this buffer into an array; and o Relative bulk put methods that transfer contiguous sequences of characters from a character array, a string, or some other character buffer into this buffer. o Methods for compacting, duplicating, and slicing a character buffer.

Character buffers can be created either by allocation, which allocates space for the buffer's content, by wrapping an existing character array or string into a buffer, or by creating a view of an existing byte buffer

This class implements the CharSequence interface so that character buffers may be used wherever character sequences are accepted, for example in the regular-expression package decaf.util.regex.

Methods in this class that do not otherwise have a value to return are specified to return the buffer upon which they are invoked. This allows method invocations to be chained. The sequence of statements

cb.put("text/");
cb.put(subtype);
cb.put("; charset=");
cb.put(enc);

can, for example, be replaced by the single statement

cb.put("text/").put(subtype).put("; charset=").put(enc);

Constructor & Destructor Documentation

decaf::nio::CharBuffer::CharBuffer ( int  capacity)
protected

Creates a CharBuffer object that has its backing array allocated internally and is then owned and deleted when this object is deleted.

The array is initially created with all elements initialized to zero.

Parameters
capacityThe size of the array, this is the limit we read and write to.
Exceptions
IllegalArguementExceptionif capacity is negative.
virtual decaf::nio::CharBuffer::~CharBuffer ( )
inlinevirtual

Member Function Documentation

static CharBuffer* decaf::nio::CharBuffer::allocate ( int  capacity)
static

Allocates a new character buffer.

The new buffer's position will be zero, its limit will be its capacity, and its mark will be undefined. It will have a backing array, and its array offset will be zero.

Parameters
capacityThe size of the Char buffer in chars ( 1 byte ).
Returns
the CharBuffer that was allocated, caller owns.
Exceptions
IndexOutOfBoundsExceptionif capacity is negative.
CharBuffer& decaf::nio::CharBuffer::append ( char  value)
virtual

Appends the specified character to this buffer.

Parameters
valueThe char to append.
Returns
a reference to this modified CharBuffer.
Exceptions
BufferOverflowExceptionif there is no more space
ReadOnlyBufferExceptionif this Buffer is read only.

Implements decaf::lang::Appendable.

CharBuffer& decaf::nio::CharBuffer::append ( const lang::CharSequence value)
virtual

Appends the specified character sequence to this buffer.

If value is Null the the string "null" is appended to the buffer.

Parameters
valueThe CharSequence to append.
Returns
a reference to this modified CharBuffer
Exceptions
BufferOverflowExceptionif there is no more space
ReadOnlyBufferExceptionif this Buffer is read only.

Implements decaf::lang::Appendable.

CharBuffer& decaf::nio::CharBuffer::append ( const lang::CharSequence value,
int  start,
int  end 
)
virtual

Appends a subsequence of the specified character sequence to this buffer If value is Null the the string "null" is appended to the buffer.

Parameters
valueThe CharSequence to append.
startThe index to start appending from.
endThe index to append to.
Returns
a reference to this modified CharBuffer.
Exceptions
BufferOverflowExceptionif there is no more space
ReadOnlyBufferExceptionif this Buffer is read only.
IndexOutOfBoundsExceptionif start > end, or > length of sequence.

Implements decaf::lang::Appendable.

virtual char* decaf::nio::CharBuffer::array ( )
pure virtual

Returns the character array that backs this buffer (optional operation).

Modifications to this buffer's content will cause the returned array's content to be modified, and vice versa.

Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.

Returns
the array that backs this Buffer.
Exceptions
ReadOnlyBufferExceptionif this Buffer is read only.
UnsupportedOperationExceptionif the underlying store has no array.

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual int decaf::nio::CharBuffer::arrayOffset ( )
pure virtual

Returns the offset within this buffer's backing array of the first element of the buffer (optional operation).

Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.

Returns
The offset into the backing array where index zero starts.
Exceptions
ReadOnlyBufferExceptionif this Buffer is read only.
UnsupportedOperationExceptionif the underlying store has no array.

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual CharBuffer* decaf::nio::CharBuffer::asReadOnlyBuffer ( ) const
pure virtual

Creates a new, read-only char buffer that shares this buffer's content.

The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer; the new buffer itself, however, will be read-only and will not allow the shared content to be modified. The two buffers' position, limit, and mark values will be independent.

If this buffer is itself read-only then this method behaves in exactly the same way as the duplicate method.

The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer.

Returns
The new, read-only char buffer which the caller then owns.

Implemented in decaf::internal::nio::CharArrayBuffer.

char decaf::nio::CharBuffer::charAt ( int  index) const
virtual

Reads the character at the given index relative to the current position.

Parameters
index- The index of the character to be read relative to position
Returns
The character at index position() + index.
Exceptions
IndexOutOfBoundsExceptionif the index + the current position exceeds the size of the buffer or the index is negative.

Implements decaf::lang::CharSequence.

virtual CharBuffer& decaf::nio::CharBuffer::compact ( )
pure virtual

Compacts this buffer.

The bytes between the buffer's current position and its limit, if any, are copied to the beginning of the buffer. That is, the byte at index p = position() is copied to index zero, the byte at index p + 1 is copied to index one, and so forth until the byte at index limit() - 1 is copied to index n = limit() - 1 - p. The buffer's position is then set to n+1 and its limit is set to its capacity. The mark, if defined, is discarded.

The buffer's position is set to the number of bytes copied, rather than to zero, so that an invocation of this method can be followed immediately by an invocation of another relative put method.

Returns
a reference to this CharBuffer.
Exceptions
ReadOnlyBufferException- If this buffer is read-only

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual int decaf::nio::CharBuffer::compareTo ( const CharBuffer value) const
virtual

virtual CharBuffer* decaf::nio::CharBuffer::duplicate ( )
pure virtual

Creates a new char buffer that shares this buffer's content.

The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's capacity, limit, position, and mark values will be identical to those of this buffer. The new buffer will be read-only if, and only if, this buffer is read-only.

Returns
a new char Buffer which the caller owns.

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual bool decaf::nio::CharBuffer::equals ( const CharBuffer value) const
virtual

virtual char decaf::nio::CharBuffer::get ( )
pure virtual

Relative get method.

Reads the character at this buffer's current position, and then increments the position.

Returns
the char at the current position.
Exceptions
BufferUnderflowExceptionif there no more data to return

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual char decaf::nio::CharBuffer::get ( int  index) const
pure virtual

Absolute get method.

Reads the char at the given index.

Parameters
indexThe index in the Buffer where the char is to be read.
Returns
the char that is located at the given index.
Exceptions
IndexOutOfBoundsExceptionif index is not smaller than the buffer's limit or is negative.

Implemented in decaf::internal::nio::CharArrayBuffer.

CharBuffer& decaf::nio::CharBuffer::get ( std::vector< char >  buffer)

Relative bulk get method.

This method transfers chars from this buffer into the given destination vector. An invocation of this method of the form src.get(a) behaves in exactly the same way as the invocation. The vector must be sized to the amount of data that is to be read, that is to say, the caller should call buffer.resize( N ) before calling this get method.

Returns
a reference to this CharBuffer.
Exceptions
BufferUnderflowExceptionif there are fewer than length chars remaining in this buffer.
CharBuffer& decaf::nio::CharBuffer::get ( char *  buffer,
int  size,
int  offset,
int  length 
)

Relative bulk get method.

This method transfers chars from this buffer into the given destination array. If there are fewer chars remaining in the buffer than are required to satisfy the request, that is, if length > remaining(), then no bytes are transferred and a BufferUnderflowException is thrown.

Otherwise, this method copies length chars from this buffer into the given array, starting at the current position of this buffer and at the given offset in the array. The position of this buffer is then incremented by length.

Parameters
bufferThe pointer to an allocated buffer to fill.
sizeThe size of the buffer passed.
offsetThe position in the buffer to start filling.
lengthThe amount of data to put in the passed buffer.
Returns
a reference to this Buffer.
Exceptions
BufferUnderflowExceptionif there are fewer than length chars remaining in this buffer
NullPointerExceptionif the passed buffer is null.
IndexOutOfBoundsExceptionif the preconditions of size, offset, or length are not met.
virtual bool decaf::nio::CharBuffer::hasArray ( ) const
pure virtual

Tells whether or not this buffer is backed by an accessible char array.

If this method returns true then the array and arrayOffset methods may safely be invoked. Subclasses should override this method if they do not have a backing array as this class always returns true.

Returns
true if, and only if, this buffer is backed by an array and is not read-only

Implemented in decaf::internal::nio::CharArrayBuffer.

int decaf::nio::CharBuffer::length ( ) const
inlinevirtual

Returns the length of this character buffer.

Returns
the length of this buffer from the position to the limit.

Implements decaf::lang::CharSequence.

virtual bool decaf::nio::CharBuffer::operator< ( const CharBuffer value) const
virtual

virtual bool decaf::nio::CharBuffer::operator== ( const CharBuffer value) const
virtual

CharBuffer& decaf::nio::CharBuffer::put ( CharBuffer src)

This method transfers the chars remaining in the given source buffer into this buffer.

If there are more chars remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no chars are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies n = src.remaining() chars from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

Parameters
src- the buffer to take chars from an place in this one.
Returns
a reference to this buffer.
Exceptions
BufferOverflowExceptionif there is insufficient space in this buffer for the remaining chars in the source buffer.
IllegalArgumentExceptionif the source buffer is this buffer.
ReadOnlyBufferExceptionif this buffer is read-only.
CharBuffer& decaf::nio::CharBuffer::put ( const char *  buffer,
int  size,
int  offset,
int  length 
)

This method transfers chars into this buffer from the given source array.

If there are more chars to be copied from the array than remain in this buffer, that is, if length > remaining(), then no chars are transferred and a BufferOverflowException is thrown.

Otherwise, this method copies length bytes from the given array into this buffer, starting at the given offset in the array and at the current position of this buffer. The position of this buffer is then incremented by length.

Parameters
bufferThe array from which chars are to be read.
sizeThe size of the buffer passed.
offsetThe offset within the array of the first char to be read.
lengthThe number of chars to be read from the given array.
Returns
a reference to this buffer.
Exceptions
BufferOverflowExceptionif there is insufficient space in this buffer
ReadOnlyBufferExceptionif this buffer is read-only
NullPointerExceptionif the passed buffer is null.
IndexOutOfBoundsExceptionif the preconditions of size, offset, or length are not met.
CharBuffer& decaf::nio::CharBuffer::put ( std::vector< char > &  buffer)

This method transfers the entire content of the given source char array into this buffer.

This is the same as calling put( &buffer[0], 0, buffer.size().

Parameters
bufferThe buffer whose contents are copied to this CharBuffer.
Returns
a reference to this buffer.
Exceptions
BufferOverflowExceptionif there is insufficient space in this buffer.
ReadOnlyBufferExceptionif this buffer is read-only.
virtual CharBuffer& decaf::nio::CharBuffer::put ( char  value)
pure virtual

Writes the given char into this buffer at the current position, and then increments the position.

Parameters
valueThe char value to be written.
Returns
a reference to this buffer.
Exceptions
BufferOverflowExceptionif this buffer's current position is not smaller than its limit
ReadOnlyBufferExceptionif this buffer is read-only.

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual CharBuffer& decaf::nio::CharBuffer::put ( int  index,
char  value 
)
pure virtual

Writes the given char into this buffer at the given index.

Parameters
indexThe position in the Buffer to write the data.
valueThe char to write.
Returns
a reference to this buffer.
Exceptions
IndexOutOfBoundsExceptionif index greater than the buffer's limit minus the size of the type being written, or index is negative.
ReadOnlyBufferExceptionif this buffer is read-only.

Implemented in decaf::internal::nio::CharArrayBuffer.

CharBuffer& decaf::nio::CharBuffer::put ( std::string &  src,
int  start,
int  end 
)

Relative bulk put method (optional operation).

This method transfers characters from the given string into this buffer. If there are more characters to be copied from the string than remain in this buffer, that is, if end - start > remaining(), then no characters are transferred and a BufferOverflowException is thrown.

Returns
a reference to this buffer

Otherwise, this method copies n = end - start characters from the given string into this buffer, starting at the given start index and at the current position of this buffer. The position of this buffer is then incremented by n.

Parameters
srcThe string to copy from.
startThe position in src to start from.
endThe position in src to stop at.
Returns
a reference to this CharBuffer.
Exceptions
BufferOverflowExceptionif this buffer's current position is not
IndexOutOfBoundsExceptionif index greater than the buffer's limit minus the size of the type being written.
ReadOnlyBufferExceptionif this buffer is read-only
CharBuffer& decaf::nio::CharBuffer::put ( const std::string &  src)

Relative bulk put method (optional operation).

This method transfers the entire content of the given source string into this buffer. An invocation of this method of the form dst.put(s) behaves in exactly the same way as the invocation.

Parameters
srcThe string to copy from.
Returns
a reference to this CharBuffer.
Exceptions
BufferOverflowExceptionif this buffer's current position is not.
ReadOnlyBufferExceptionif this buffer is read-only.
virtual int decaf::nio::CharBuffer::read ( CharBuffer target)
virtual

Attempts to read characters into the specified character buffer.

The buffer is used as a repository of characters as-is: the only changes made are the results of a put operation. No flipping or rewinding of the buffer is performed.

Parameters
targetThe buffer to read characters into
Returns
The number of characters added to the buffer, or string::npos if this source of characters is at its end
Exceptions
NullPointerExceptionif target is Null.
IllegalArgumentExceptionif target is this CharBuffer.
ReadOnlyBufferExceptionif this buffer is in read-only mode.
virtual CharBuffer* decaf::nio::CharBuffer::slice ( ) const
pure virtual

Creates a new CharBuffer whose content is a shared subsequence of this buffer's content.

The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position, limit, and mark values will be independent.

The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer, and its mark will be undefined. The new buffer will be read-only if, and only if, this buffer is read-only.

Returns
the newly create CharBuffer which the caller owns.

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual lang::CharSequence* decaf::nio::CharBuffer::subSequence ( int  start,
int  end 
) const
pure virtual

Creates a new character buffer that represents the specified subsequence of this buffer, relative to the current position.

The new buffer will share this buffer's content; that is, if the content of this buffer is mutable then modifications to one buffer will cause the other to be modified. The new buffer's capacity will be that of this buffer, its position will be position() + start, and its limit will be position() + end. The new Buffer will be read-only if, and only if, this buffer is read-only.

Parameters
startThe index, relative to the current position, of the first character in the subsequence; must be non-negative and no larger than remaining().
endThe index, relative to the current position, of the character following the last character in the subsequence; must be no smaller than start and no larger than remaining().
Returns
The new character buffer, caller owns.
Exceptions
IndexOutOfBoundsExceptionif the preconditions on start and end fail.

Implements decaf::lang::CharSequence.

Implemented in decaf::internal::nio::CharArrayBuffer.

virtual std::string decaf::nio::CharBuffer::toString ( ) const
virtual
Returns
a std::string describing this object

Implements decaf::lang::CharSequence.

static CharBuffer* decaf::nio::CharBuffer::wrap ( char *  array,
int  size,
int  offset,
int  length 
)
static

Wraps the passed buffer with a new CharBuffer.

The new buffer will be backed by the given char array; that is, modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity will be array.length, its position will be offset, its limit will be offset + length, and its mark will be undefined. Its backing array will be the given array, and its array offset will be zero.

Parameters
arrayThe array that will back the new buffer.
sizeThe size of the array passed in.
offsetThe offset of the subarray to be used.
lengthThe length of the subarray to be used.
Returns
a new CharBuffer that is backed by buffer, caller owns.
Exceptions
NullPointerExceptionif the array pointer is Null.
IndexOutOfBoundsExceptionif capacity is negative.
static CharBuffer* decaf::nio::CharBuffer::wrap ( std::vector< char > &  buffer)
static

Wraps the passed STL char Vector in a CharBuffer.

The new buffer will be backed by the given char array; modifications to the buffer will cause the array to be modified and vice versa. The new buffer's capacity and limit will be buffer.size(), its position will be zero, and its mark will be undefined. Its backing array will be the given array, and its array offset will be zero.

Parameters
bufferThe vector that will back the new buffer, the vector must have been sized to the desired size already by calling vector.resize( N ).
Returns
a new CharBuffer that is backed by buffer, caller owns.

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