activemq-cpp-3.4.0

decaf::nio::ShortBuffer Class Reference

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

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

Inheritance diagram for decaf::nio::ShortBuffer:

Public Member Functions

virtual ~ShortBuffer ()
virtual std::string toString () const
virtual short * array ()=0
 Returns the short 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 ShortBufferasReadOnlyBuffer () const =0
 Creates a new, read-only short buffer that shares this buffer's content.
virtual ShortBuffercompact ()=0
 Compacts this buffer.
virtual ShortBufferduplicate ()=0
 Creates a new short buffer that shares this buffer's content.
virtual short get ()=0
 Relative get method.
virtual short get (int index) const =0
 Absolute get method.
ShortBufferget (std::vector< short > buffer)
 Relative bulk get method.
ShortBufferget (short *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 short array.
ShortBufferput (ShortBuffer &src)
 This method transfers the shorts remaining in the given source buffer into this buffer.
ShortBufferput (const short *buffer, int size, int offset, int length)
 This method transfers shorts into this buffer from the given source array.
ShortBufferput (std::vector< short > &buffer)
 This method transfers the entire content of the given source shorts array into this buffer.
virtual ShortBufferput (short value)=0
 Writes the given shorts into this buffer at the current position, and then increments the position.
virtual ShortBufferput (int index, short value)=0
 Writes the given shorts into this buffer at the given index.
virtual ShortBufferslice () const =0
 Creates a new ShortBuffer whose content is a shared subsequence of this buffer's content.
virtual int compareTo (const ShortBuffer &value) const
 
virtual bool equals (const ShortBuffer &value) const
 
virtual bool operator== (const ShortBuffer &value) const
 
virtual bool operator< (const ShortBuffer &value) const
 

Static Public Member Functions

static ShortBufferallocate (int capacity)
 Allocates a new Double buffer.
static ShortBufferwrap (short *array, int size, int offset, int length)
 Wraps the passed buffer with a new ShortBuffer.
static ShortBufferwrap (std::vector< short > &buffer)
 Wraps the passed STL short Vector in a ShortBuffer.

Protected Member Functions

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

Detailed Description

This class defines four categories of operations upon short buffers:

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

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

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.


Constructor & Destructor Documentation

decaf::nio::ShortBuffer::ShortBuffer ( int  capacity) [protected]

Creates a ShortBuffer 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 and limit of the Buffer in doubles
Exceptions:
IllegalArguementExceptionif capacity is negative.
virtual decaf::nio::ShortBuffer::~ShortBuffer ( ) [inline, virtual]

Member Function Documentation

static ShortBuffer* decaf::nio::ShortBuffer::allocate ( int  capacity) [static]

Allocates a new Double 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 Double buffer in shorts.
Returns:
the ShortBuffer that was allocated, caller owns.
virtual short* decaf::nio::ShortBuffer::array ( ) [pure virtual]

Returns the short 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::ShortArrayBuffer.

virtual int decaf::nio::ShortBuffer::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::ShortArrayBuffer.

virtual ShortBuffer* decaf::nio::ShortBuffer::asReadOnlyBuffer ( ) const [pure virtual]

Creates a new, read-only short 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 short buffer which the caller then owns.

Implemented in decaf::internal::nio::ShortArrayBuffer.

virtual ShortBuffer& decaf::nio::ShortBuffer::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 ShortBuffer.
Exceptions:
ReadOnlyBufferExceptionif this buffer is read-only.

Implemented in decaf::internal::nio::ShortArrayBuffer.

virtual int decaf::nio::ShortBuffer::compareTo ( const ShortBuffer value) const [virtual]

virtual ShortBuffer* decaf::nio::ShortBuffer::duplicate ( ) [pure virtual]

Creates a new short 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 short Buffer which the caller owns.

Implemented in decaf::internal::nio::ShortArrayBuffer.

virtual bool decaf::nio::ShortBuffer::equals ( const ShortBuffer value) const [virtual]

ShortBuffer& decaf::nio::ShortBuffer::get ( std::vector< short >  buffer)

Relative bulk get method.

This method transfers values 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 Buffer.
Exceptions:
BufferUnderflowExceptionif there are fewer than length shorts remaining in this buffer.
virtual short decaf::nio::ShortBuffer::get ( int  index) const [pure virtual]

Absolute get method.

Reads the value at the given index.

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

Implemented in decaf::internal::nio::ShortArrayBuffer.

ShortBuffer& decaf::nio::ShortBuffer::get ( short *  buffer,
int  size,
int  offset,
int  length 
)

Relative bulk get method.

This method transfers shorts from this buffer into the given destination array. If there are fewer shorts 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 shorts 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 provided.
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 shorts remaining in this buffer
NullPointerExceptionif the passed buffer is null.
IndexOutOfBoundsExceptionif the preconditions of size, offset, or length are not met.
virtual short decaf::nio::ShortBuffer::get ( ) [pure virtual]

Relative get method.

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

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

Implemented in decaf::internal::nio::ShortArrayBuffer.

virtual bool decaf::nio::ShortBuffer::hasArray ( ) const [pure virtual]

Tells whether or not this buffer is backed by an accessible short 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::ShortArrayBuffer.

virtual bool decaf::nio::ShortBuffer::operator< ( const ShortBuffer value) const [virtual]

virtual bool decaf::nio::ShortBuffer::operator== ( const ShortBuffer value) const [virtual]

virtual ShortBuffer& decaf::nio::ShortBuffer::put ( short  value) [pure virtual]

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

Parameters:
valueThe shorts 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::ShortArrayBuffer.

virtual ShortBuffer& decaf::nio::ShortBuffer::put ( int  index,
short  value 
) [pure virtual]

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

Parameters:
indexThe position in the Buffer to write the data.
valueThe shorts 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.
ReadOnlyBufferExceptionif this buffer is read-only.

Implemented in decaf::internal::nio::ShortArrayBuffer.

ShortBuffer& decaf::nio::ShortBuffer::put ( const short *  buffer,
int  size,
int  offset,
int  length 
)

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

If there are more shorts to be copied from the array than remain in this buffer, that is, if length > remaining(), then no shorts 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 shorts 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 shorts 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.
ShortBuffer& decaf::nio::ShortBuffer::put ( std::vector< short > &  buffer)

This method transfers the entire content of the given source shorts 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 ShortBuffer.
Returns:
a reference to this buffer.
Exceptions:
BufferOverflowExceptionif there is insufficient space in this buffer.
ReadOnlyBufferExceptionif this buffer is read-only.
ShortBuffer& decaf::nio::ShortBuffer::put ( ShortBuffer src)

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

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

Otherwise, this method copies n = src.remaining() shorts 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:
srcThe buffer to take shorts from an place in this one.
Returns:
a reference to this buffer.
Exceptions:
BufferOverflowExceptionif there is insufficient space in this buffer for the remaining shorts in the source buffer.
IllegalArgumentExceptionif the source buffer is this buffer.
ReadOnlyBufferExceptionif this buffer is read-only.
virtual ShortBuffer* decaf::nio::ShortBuffer::slice ( ) const [pure virtual]

Creates a new ShortBuffer 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 ShortBuffer which the caller owns.

Implemented in decaf::internal::nio::ShortArrayBuffer.

virtual std::string decaf::nio::ShortBuffer::toString ( ) const [virtual]
Returns:
a std::string describing this object
static ShortBuffer* decaf::nio::ShortBuffer::wrap ( short *  array,
int  size,
int  offset,
int  length 
) [static]

Wraps the passed buffer with a new ShortBuffer.

The new buffer will be backed by the given short 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 passed in array.
offsetThe offset of the subarray to be used.
lengthThe length of the subarray to be used.
Returns:
a new ShortBuffer that is backed by buffer, caller owns.
Exceptions:
NullPointerExceptionif the array pointer is NULL.
IndexOutOfBoundsExceptionif the preconditions of size, offset, or length are not met.
static ShortBuffer* decaf::nio::ShortBuffer::wrap ( std::vector< short > &  buffer) [static]

Wraps the passed STL short Vector in a ShortBuffer.

The new buffer will be backed by the given short 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 ShortBuffer that is backed by buffer, caller owns.

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