You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2008/04/29 22:52:37 UTC
svn commit: r652104 [2/29] - in /activemq/activemq-cpp/trunk: ./ m4/
src/examples/ src/examples/consumers/ src/main/ src/main/decaf/
src/main/decaf/internal/ src/main/decaf/internal/net/
src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/ma...
Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/BufferFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/BufferFactory.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/BufferFactory.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/BufferFactory.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,326 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_BUFFERFACTORY_H_
+#define _DECAF_INTERNAL_NIO_BUFFERFACTORY_H_
+
+#include <decaf/nio/ByteBuffer.h>
+#include <decaf/nio/CharBuffer.h>
+#include <decaf/nio/DoubleBuffer.h>
+#include <decaf/nio/FloatBuffer.h>
+#include <decaf/nio/LongBuffer.h>
+#include <decaf/nio/IntBuffer.h>
+#include <decaf/nio/ShortBuffer.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+ /**
+ * Factory class used by static methods in the decaf::nio package to
+ * create the various default version of the NIO interfaces.
+ */
+ class DECAF_API BufferFactory {
+ public:
+
+ virtual ~BufferFactory() {}
+
+ /**
+ * Allocates a new byte buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated ByteBuffer which the caller owns.
+ */
+ static decaf::nio::ByteBuffer* createByteBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new ByteBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new ByteBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::ByteBuffer* createByteBuffer( unsigned char* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL Byte Vector in a ByteBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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 ByteBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::ByteBuffer* createByteBuffer( std::vector<unsigned char>& buffer );
+
+ /**
+ * Allocates a new char buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated CharBuffer which the caller owns.
+ */
+ static decaf::nio::CharBuffer* createCharBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new CharBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new CharBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::CharBuffer* createCharBuffer( char* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL Byte Vector in a CharBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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.
+ */
+ static decaf::nio::CharBuffer* createCharBuffer( std::vector<char>& buffer );
+
+ /**
+ * Allocates a new double buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated DoubleBuffer which the caller owns.
+ */
+ static decaf::nio::DoubleBuffer* createDoubleBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new DoubleBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::DoubleBuffer* createDoubleBuffer( double* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL Double Vector in a DoubleBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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 DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::DoubleBuffer* createDoubleBuffer( std::vector<double>& buffer );
+
+ /**
+ * Allocates a new float buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated DoubleBuffer which the caller owns.
+ */
+ static decaf::nio::FloatBuffer* createFloatBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new FloatBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::FloatBuffer* createFloatBuffer( float* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL Float Vector in a FloatBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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 DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::FloatBuffer* createFloatBuffer( std::vector<float>& buffer );
+
+ /**
+ * Allocates a new long long buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated DoubleBuffer which the caller owns.
+ */
+ static decaf::nio::LongBuffer* createLongBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new LongBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::LongBuffer* createLongBuffer( long long* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL Long Vector in a LongBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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 DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::LongBuffer* createLongBuffer( std::vector<long long>& buffer );
+
+ /**
+ * Allocates a new int buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated DoubleBuffer which the caller owns.
+ */
+ static decaf::nio::IntBuffer* createIntBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new IntBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::IntBuffer* createIntBuffer( int* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL int Vector in a IntBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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 DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::IntBuffer* createIntBuffer( std::vector<int>& buffer );
+
+ /**
+ * Allocates a new short buffer whose position will be zero its limit will
+ * be its capacity and its mark is not set.
+ * @param capacity - the internal buffer's capacity.
+ * @returns a newly allocated DoubleBuffer which the caller owns.
+ */
+ static decaf::nio::ShortBuffer* createShortBuffer( std::size_t capacity );
+
+ /**
+ * Wraps the passed buffer with a new ShortBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The array that will back the new buffer
+ * @param offset - The offset of the subarray to be used
+ * @param length - The length of the subarray to be used
+ * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::ShortBuffer* createShortBuffer( short* buffer,
+ std::size_t offset,
+ std::size_t length )
+ throw( lang::exceptions::NullPointerException );
+
+ /**
+ * Wraps the passed STL Short Vector in a ShortBuffer.
+ * <p>
+ * The new buffer will be backed by the given byte 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.
+ * @param buffer - The 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 DoubleBuffer that is backed by buffer, caller owns.
+ */
+ static decaf::nio::ShortBuffer* createShortBuffer( std::vector<short>& buffer );
+
+ };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BUFFERFACTORY_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,668 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ByteArrayBuffer.h"
+#include "decaf/lang/Short.h"
+#include "decaf/lang/Integer.h"
+#include "decaf/lang/Long.h"
+#include "decaf/lang/Float.h"
+#include "decaf/lang/Double.h"
+
+using namespace std;
+using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+using namespace decaf::internal::nio;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer::ByteArrayBuffer( std::size_t capacity, bool readOnly )
+ : decaf::nio::ByteBuffer( capacity ) {
+
+ // Allocate using the ByteArray, not read-only initially. Take a reference to it.
+ this->_array = new ByteArrayPerspective( capacity );
+ this->offset = 0;
+ this->readOnly = readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer::ByteArrayBuffer( unsigned char* array, std::size_t offset,
+ std::size_t capacity, bool readOnly )
+ throw( decaf::lang::exceptions::NullPointerException )
+ : decaf::nio::ByteBuffer( capacity ) {
+
+ try{
+
+ // Allocate using the ByteArray, not read-only initially.
+ this->_array = new ByteArrayPerspective( array, capacity, false );
+ this->offset = offset;
+ this->readOnly = readOnly;
+ }
+ DECAF_CATCH_RETHROW( NullPointerException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+ DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer::ByteArrayBuffer( ByteArrayPerspective& array, std::size_t offset,
+ std::size_t length, bool readOnly )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+ : decaf::nio::ByteBuffer( length ) {
+
+ try{
+ if( offset > array.getCapacity() ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::ByteArrayBuffer - offset %d is greater than capacity %d",
+ offset, array.getCapacity() );
+ }
+
+ // Allocate using the ByteArray, not read-only initially.
+ this->_array = array.takeRef();
+ this->offset = offset;
+ this->readOnly = readOnly;
+ }
+ DECAF_CATCH_RETHROW( NullPointerException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+ DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer::ByteArrayBuffer( const ByteArrayBuffer& other )
+ : decaf::nio::ByteBuffer( other ) {
+
+ // get the byte buffer of the caller and take a reference
+ this->_array = other._array->takeRef();
+ this->offset = other.offset;
+ this->readOnly = other.readOnly;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer::~ByteArrayBuffer() {
+
+ try{
+
+ // Return this object's reference to the buffer.
+ this->_array->returnRef();
+
+ // If there are no other Buffers out there that reference it then we
+ // delete it now, the internal unsigned char* array will be deleted
+ // if we where the owner.
+ if( this->_array->getReferences() == 0 ) {
+ delete this->_array;
+ }
+ }
+ DECAF_CATCH_NOTHROW( Exception )
+ DECAF_CATCHALL_NOTHROW()
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char* ByteArrayBuffer::array()
+ throw( decaf::nio::ReadOnlyBufferException, UnsupportedOperationException ) {
+
+ try{
+
+ if( !this->hasArray() ) {
+ throw UnsupportedOperationException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+ }
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::array() - Buffer is Read Only." );
+ }
+
+ return this->_array->getByteArray();
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( UnsupportedOperationException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCHALL_THROW( decaf::nio::ReadOnlyBufferException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+std::size_t ByteArrayBuffer::arrayOffset() const
+ throw( decaf::nio::ReadOnlyBufferException,
+ lang::exceptions::UnsupportedOperationException ) {
+
+ try{
+
+ if( !this->hasArray() ) {
+ throw UnsupportedOperationException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+ }
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::arrayOffset() - Buffer is Read Only." );
+ }
+
+ return this->offset;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( UnsupportedOperationException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCHALL_THROW( decaf::nio::ReadOnlyBufferException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer* ByteArrayBuffer::asReadOnlyBuffer() const {
+
+ try{
+
+ ByteArrayBuffer* buffer = new ByteArrayBuffer( *this );
+ buffer->setReadOnly( true );
+
+ return buffer;
+ }
+ DECAF_CATCH_RETHROW( Exception )
+ DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::compact() throw( decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::compact() - Buffer is Read Only." );
+ }
+
+ // copy from the current pos to the beginning all the remaining bytes
+ // the set pos to the
+ memcpy( this->array() + offset,
+ this->array() + offset + this->position(),
+ this->remaining() );
+
+ this->position( this->limit() - this->position() );
+ this->limit( this->capacity() );
+ this->_markSet = false;
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCHALL_THROW( decaf::nio::ReadOnlyBufferException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer* ByteArrayBuffer::duplicate() {
+
+ try{
+ return new ByteArrayBuffer( *this );
+ }
+ DECAF_CATCH_RETHROW( Exception )
+ DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char ByteArrayBuffer::get() const throw( decaf::nio::BufferUnderflowException ) {
+
+ try{
+ return this->get( this->_position++ );
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferUnderflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char ByteArrayBuffer::get( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ try{
+
+ if( ( index ) >= this->limit() ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::get - Not enough data to fill request." );
+ }
+
+ return this->_array->get( offset + index );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double ByteArrayBuffer::getDouble() throw( decaf::nio::BufferUnderflowException ) {
+
+ try{
+
+ unsigned long long lvalue = this->getLong();
+ return Double::longBitsToDouble( lvalue );
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferUnderflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double ByteArrayBuffer::getDouble( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ try{
+
+ unsigned long long lvalue = this->getLong( index );
+ return Double::longBitsToDouble( lvalue );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float ByteArrayBuffer::getFloat() throw( decaf::nio::BufferUnderflowException ) {
+
+ try{
+
+ unsigned int ivalue = this->getInt();
+ return Float::intBitsToFloat( ivalue );
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferUnderflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float ByteArrayBuffer::getFloat( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ try{
+
+ unsigned int ivalue = this->getInt( index );
+ return Float::intBitsToFloat( ivalue );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ByteArrayBuffer::getLong() throw( decaf::nio::BufferUnderflowException ) {
+
+ try{
+
+ long long value = this->getLong( this->_position );
+ this->_position += sizeof(value);
+ return value;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferUnderflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ByteArrayBuffer::getLong( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ try{
+
+ if( (offset + index + sizeof(long long)) > this->limit() ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::getLong(i) - Not enough data to fill a long long." );
+ }
+
+ return this->_array->getLongAt( index + offset );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteArrayBuffer::getInt() throw( decaf::nio::BufferUnderflowException ) {
+
+ try{
+
+ int value = this->getInt( this->_position );
+ this->_position += sizeof(value);
+ return value;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferUnderflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteArrayBuffer::getInt( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ try{
+
+ if( (offset + index + sizeof(int)) > this->limit() ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::getInt(i) - Not enough data to fill an int." );
+ };
+
+ return this->_array->getIntAt( offset + index );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short ByteArrayBuffer::getShort() throw( decaf::nio::BufferUnderflowException ) {
+
+ try{
+
+ short value = this->getShort( this->_position );
+ this->_position += sizeof(value);
+ return value;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferUnderflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short ByteArrayBuffer::getShort( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ try{
+
+ if( (offset + index + sizeof(short)) > this->limit() ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::getShort(i) - Not enough data to fill a short." );
+ }
+
+ return this->_array->getShortAt( offset + index );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::put( unsigned char value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->put( this->_position++, value );
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::put( std::size_t index, unsigned char value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::put(i,i) - Buffer is Read Only." );
+ }
+
+ if( index >= this->limit() ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::put(i,i) - Not enough data to fill request." );
+ }
+
+ this->_array->put( index + offset, value );
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putChar( char value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->put( this->_position++, value );
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putChar( std::size_t index, char value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->put( index, value );
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putDouble( double value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putDouble( this->_position, value );
+ this->_position += sizeof(value);
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putDouble( std::size_t index, double value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putLong( index, Double::doubleToLongBits( value ) );
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putFloat( float value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putFloat( this->_position, value );
+ this->_position += sizeof(value);
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putFloat( std::size_t index, float value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putInt( index, Float::floatToIntBits( value ) );
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putLong( long long value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putLong( this->_position, value );
+ this->_position += sizeof(value);
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putLong( std::size_t index, long long value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::putLong() - Buffer is Read Only." );
+ }
+
+ this->_array->putLongAt( index + offset, value );
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putInt( int value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putInt( this->_position, value );
+ this->_position += sizeof(value);
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putInt( std::size_t index, int value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::putInt() - Buffer is Read Only." );
+ }
+
+ this->_array->putIntAt( index + offset, value );
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putShort( short value )
+ throw( decaf::nio::BufferOverflowException, decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ this->putShort( this->_position, value );
+ this->_position += sizeof(value);
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( decaf::nio::BufferOverflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::BufferOverflowException )
+ DECAF_CATCHALL_THROW( decaf::nio::BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer& ByteArrayBuffer::putShort( std::size_t index, short value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException ) {
+
+ try{
+
+ if( this->isReadOnly() ) {
+ throw decaf::nio::ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "ByteArrayBuffer::putShort() - Buffer is Read Only." );
+ }
+
+ this->_array->putShortAt( index + offset, value );
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayBuffer* ByteArrayBuffer::slice() const {
+
+ try{
+
+ return new ByteArrayBuffer( *(this->_array),
+ this->offset + this->position(),
+ this->remaining(),
+ this->isReadOnly() );
+ }
+ DECAF_CATCH_RETHROW( Exception )
+ DECAF_CATCHALL_THROW( Exception )
+}
Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,712 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_BYTEBUFFER_H_
+#define _DECAF_INTERNAL_NIO_BYTEBUFFER_H_
+
+#include <decaf/nio/ByteBuffer.h>
+#include <decaf/lang/exceptions/NullPointerException.h>
+#include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
+#include <decaf/nio/BufferUnderflowException.h>
+#include <decaf/nio/BufferOverflowException.h>
+#include <decaf/nio/ReadOnlyBufferException.h>
+#include <decaf/internal/nio/ByteArrayPerspective.h>
+
+#include <decaf/nio/CharBuffer.h>
+#include <decaf/nio/DoubleBuffer.h>
+#include <decaf/nio/FloatBuffer.h>
+#include <decaf/nio/ShortBuffer.h>
+#include <decaf/nio/IntBuffer.h>
+#include <decaf/nio/LongBuffer.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+ /**
+ * This class defines six categories of operations upon byte buffers:
+ *
+ * 1. Absolute and relative get and put methods that read and write single bytes;
+ * 2. Relative bulk get methods that transfer contiguous sequences of bytes from
+ * this buffer into an array;
+ * 3. Relative bulk put methods that transfer contiguous sequences of bytes from
+ * a byte array or some other byte buffer into this buffer;
+ * 4. Absolute and relative get and put methods that read and write values of other
+ * primitive types, translating them to and from sequences of bytes in a
+ * particular byte order;
+ * 5. Methods for creating view buffers, which allow a byte buffer to be viewed as
+ * a buffer containing values of some other primitive type; and
+ * 6. Methods for compacting, duplicating, and slicing a byte buffer.
+ *
+ * Byte buffers can be created either by allocation, which allocates space for the
+ * buffer's content, or by wrapping an existing byte array into a buffer.
+ *
+ * Access to binary data:
+ *
+ * This class defines methods for reading and writing values of all other primitive
+ * types, except boolean. Primitive values are translated to (or from) sequences of
+ * bytes according to the buffer's current byte order.
+ *
+ * For access to heterogeneous binary data, that is, sequences of values of
+ * different types, this class defines a family of absolute and relative get and
+ * put methods for each type. For 32-bit floating-point values, for example, this
+ * class defines:
+ *
+ * float getFloat()
+ * float getFloat(int index)
+ * void putFloat(float f)
+ * void putFloat(int index, float f)
+ *
+ * Corresponding methods are defined for the types char, short, int, long, and
+ * double. The index parameters of the absolute get and put methods are in terms
+ * of bytes rather than of the type being read or written.
+ *
+ * For access to homogeneous binary data, that is, sequences of values of the same
+ * type, this class defines methods that can create views of a given byte buffer.
+ * A view buffer is simply another buffer whose content is backed by the byte buffer.
+ * Changes to the byte buffer's content will be visible in the view buffer, and vice
+ * versa; the two buffers' position, limit, and mark values are independent. The
+ * asFloatBuffer method, for example, creates an instance of the FloatBuffer class
+ * that is backed by the byte buffer upon which the method is invoked. Corresponding
+ * view-creation methods are defined for the types char, short, int, long, and double.
+ *
+ * View buffers have two important advantages over the families of type-specific
+ * get and put methods described above:
+ *
+ * A view buffer is indexed not in terms of bytes but rather in terms of the
+ * type-specific size of its values;
+ *
+ * A view buffer provides relative bulk get and put methods that can transfer
+ * contiguous sequences of values between a buffer and an array or some other
+ * buffer of the same type; and
+ *
+ */
+ class DECAF_API ByteArrayBuffer : public decaf::nio::ByteBuffer {
+ private:
+
+ // Read / Write flag
+ bool readOnly;
+
+ // The reference array object that backs this buffer.
+ internal::nio::ByteArrayPerspective* _array;
+
+ // Offset into the array that we are to start from
+ std::size_t offset;
+
+ public:
+
+ /**
+ * Creates a ByteArrayBuffer 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.
+ * @param capacity - size of the array, this is the limit we read and write to.
+ * @param readOnly - should this buffer be read-only, default as false
+ */
+ ByteArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+ /**
+ * Creates a ByteArrayBuffer object that wraps the given array. If the own flag
+ * is set then it will delete this array when this object is deleted.
+ * @param array - array to wrap
+ * @param offset - the position that is this buffers start pos.
+ * @param capacity - size of the array, this is the limit we read and write to.
+ * @param readOnly - should this buffer be read-only, default as false
+ * @throws NullPointerException if buffer is NULL
+ */
+ ByteArrayBuffer( unsigned char* array, std::size_t offset,
+ std::size_t capacity, bool readOnly = false )
+ throw( decaf::lang::exceptions::NullPointerException );
+
+ /**
+ * Creates a byte buffer that wraps the passed ByteArrayPerspective and
+ * start at the given offset. The capacity and limit of the new ByteArrayBuffer
+ * will be that of the remaining capacity of the passed buffer.
+ * @param array - the ByteArrayPerspective to wrap
+ * @param offset - the offset into array where the buffer starts
+ * @param length - the length of the array we are wrapping or limit.
+ * @param readOnly - is this a readOnly buffer.
+ * @throws NullPointerException if buffer is NULL
+ * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+ */
+ ByteArrayBuffer( ByteArrayPerspective& array,
+ std::size_t offset, std::size_t length,
+ bool readOnly = false )
+ throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Create a ByteArrayBuffer that mirros this one, meaning it shares a
+ * reference to this buffers ByteArrayPerspective and when changes
+ * are made to that data it is reflected in both.
+ * @param other - the ByteArrayBuffer this one is to mirror.
+ * @param readOnly - should this buffer be read-only, default as false
+ */
+ ByteArrayBuffer( const ByteArrayBuffer& other );
+
+ virtual ~ByteArrayBuffer();
+
+ /**
+ * Tells whether or not this buffer is read-only.
+ * @returns true if, and only if, this buffer is read-only
+ */
+ virtual bool isReadOnly() const {
+ return this->readOnly;
+ }
+
+ /**
+ * Returns the byte array that backs this buffer
+ * <p>
+ * Modifications to this buffer's content will cause the returned array's
+ * content to be modified, and vice versa.
+ * <p>
+ * 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
+ * @throws ReadOnlyBufferException - If this buffer is backed by an array but
+ * is read-only
+ * @throws UnsupportedOperationException - If this buffer is not backed by an
+ * accessible array
+ */
+ virtual unsigned char* array()
+ throw( decaf::nio::ReadOnlyBufferException,
+ decaf::lang::exceptions::UnsupportedOperationException );
+
+ /**
+ * Returns the offset within this buffer's backing array of the first element
+ * of the buffer.
+ * <p>
+ * If this buffer is backed by an array then buffer position p corresponds to
+ * array index p + arrayOffset().
+ * <p>
+ * Invoke the hasArray method before invoking this method in order to ensure
+ * that this buffer has an accessible backing array.
+ * @returns The offset within this buffer's array of the first element of
+ * the buffer
+ * @throws ReadOnlyBufferException - If this buffer is backed by an array but
+ * is read-only
+ * @throws UnsupportedOperationException - If this buffer is not backed by an
+ * accessible array
+ */
+ virtual std::size_t arrayOffset() const
+ throw( decaf::nio::ReadOnlyBufferException,
+ lang::exceptions::UnsupportedOperationException );
+
+ /**
+ * Tells whether or not this buffer is backed by an accessible byte 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
+ */
+ virtual bool hasArray() const { return true; }
+
+ public: // Abstract Methods
+
+ /**
+ * Creates a view of this byte buffer as a char buffer.
+ * <p>
+ * 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.
+ * <p>
+ * 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 new Char Buffer, which the caller then owns.
+ */
+ virtual decaf::nio::CharBuffer* asCharBuffer() const { return NULL; } //TODO
+
+ /**
+ * Creates a view of this byte buffer as a double buffer.
+ * <p>
+ * 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.
+ * <p>
+ * The new buffer's position will be zero, its capacity and its limit will be
+ * the number of bytes remaining in this buffer divided by eight, and its mark
+ * will be undefined. The new buffer will be read-only if, and only if, this
+ * buffer is read-only.
+ * @returns the new double Buffer, which the caller then owns.
+ */
+ virtual decaf::nio::DoubleBuffer* asDoubleBuffer() const { return NULL; } //TODO
+
+ /**
+ * Creates a view of this byte buffer as a float buffer.
+ * <p>
+ * 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.
+ * <p>
+ * The new buffer's position will be zero, its capacity and its limit will be
+ * the number of bytes remaining in this buffer divided by four, and its mark
+ * will be undefined. The new buffer will be read-only if, and only if, this
+ * buffer is read-only.
+ * @returns the new float Buffer, which the caller then owns.
+ */
+ virtual decaf::nio::FloatBuffer* asFloatBuffer() const { return NULL; } //TODO
+
+ /**
+ * Creates a view of this byte buffer as a int buffer.
+ * <p>
+ * 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.
+ * <p>
+ * The new buffer's position will be zero, its capacity and its limit will be
+ * the number of bytes remaining in this buffer divided by four, and its mark
+ * will be undefined. The new buffer will be read-only if, and only if, this
+ * buffer is read-only.
+ * @returns the new int Buffer, which the caller then owns.
+ */
+ virtual decaf::nio::IntBuffer* asIntBuffer() const { return NULL; } //TODO
+
+ /**
+ * Creates a view of this byte buffer as a long buffer.
+ * <p>
+ * 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.
+ * <p>
+ * The new buffer's position will be zero, its capacity and its limit will be
+ * the number of bytes remaining in this buffer divided by eight, and its mark
+ * will be undefined. The new buffer will be read-only if, and only if, this
+ * buffer is read-only.
+ * @returns the new long Buffer, which the caller then owns.
+ */
+ virtual decaf::nio::LongBuffer* asLongBuffer() const { return NULL; } //TODO
+
+ /**
+ * Creates a view of this byte buffer as a short buffer.
+ * <p>
+ * 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.
+ * <p>
+ * The new buffer's position will be zero, its capacity and its limit will be
+ * the number of bytes remaining in this buffer divided by two, and its mark
+ * will be undefined. The new buffer will be read-only if, and only if, this
+ * buffer is read-only.
+ * @returns the new short Buffer, which the caller then owns.
+ */
+ virtual decaf::nio::ShortBuffer* asShortBuffer() const { return NULL; } //TODO
+
+ /**
+ * Creates a new, read-only byte buffer that shares this buffer's content.
+ * <p>
+ * 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.
+ * <p>
+ * If this buffer is itself read-only then this method behaves in exactly the
+ * same way as the duplicate method.
+ * <p>
+ * The new buffer's capacity, limit, position, and mark values will be
+ * identical to those of this buffer.
+ * @return The new, read-only byte buffer which the caller then owns.
+ */
+ virtual ByteArrayBuffer* asReadOnlyBuffer() const;
+
+ /**
+ * Compacts this buffer
+ * <p>
+ * 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.
+ * <p>
+ * 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 ByteArrayBuffer
+ * @throws ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Creates a new byte buffer that shares this buffer's content.
+ * <p>
+ * 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.
+ * <p>
+ * 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 Byte Buffer which the caller owns.
+ */
+ virtual ByteArrayBuffer* duplicate();
+
+ /**
+ * Relative get method. Reads the byte at this buffer's current position, and
+ * then increments the position.
+ * @returns The byte at the buffer's current position
+ * @throws BufferUnderflowException - If the buffer's current position is not
+ * smaller than its limit
+ */
+ virtual unsigned char get() const throw( decaf::nio::BufferUnderflowException );
+
+ /**
+ * Absolute get method. Reads the byte at the given index.
+ * @param index - the index in the Buffer where the byte is to be read
+ * @returns the byte that is located at the given index
+ * @throws IndexOutOfBoundsException - If index is not smaller than the
+ * buffer's limit
+ */
+ virtual unsigned char get( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Reads the next byte at this buffer's current position, and then increments
+ * the position by one
+ * @returns the next char in the buffer..
+ * @throws BufferUnderflowException - If there are no more bytes remaining in
+ * this buffer, meaning we have reached the set limit.
+ */
+ virtual char getChar() throw( decaf::nio::BufferUnderflowException ) {
+ return (char)this->get();
+ }
+
+ /**
+ * Reads one byte at the given index and returns it
+ * @param index - the index in the Buffer where the byte is to be read
+ * @returns the char at the given index in the buffer
+ * @throws IndexOutOfBoundsException - If index is not smaller than the
+ * buffer's limit
+ */
+ virtual char getChar( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+ return (char)this->get( index );
+ }
+
+ /**
+ * Reads the next eight bytes at this buffer's current position, and then
+ * increments the position by that amount.
+ * @returns the next double in the buffer..
+ * @throws BufferUnderflowException - If there are no more bytes remaining in
+ * this buffer, meaning we have reached the set limit.
+ */
+ virtual double getDouble() throw( decaf::nio::BufferUnderflowException );
+
+ /**
+ * Reads eight bytes at the given index and returns it
+ * @param index - the index in the Buffer where the bytes are to be read
+ * @returns the double at the given index in the buffer
+ * @throws IndexOutOfBoundsException - If there are not enough bytes
+ * remaining to fill the requested Data Type
+ */
+ virtual double getDouble( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Reads the next four bytes at this buffer's current position, and then
+ * increments the position by that amount.
+ * @returns the next float in the buffer..
+ * @throws BufferUnderflowException - If there are no more bytes remaining in
+ * this buffer, meaning we have reached the set limit.
+ */
+ virtual float getFloat() throw( decaf::nio::BufferUnderflowException );
+
+ /**
+ * Reads four bytes at the given index and returns it
+ * @param index - the index in the Buffer where the bytes are to be read
+ * @returns the float at the given index in the buffer
+ * @throws IndexOutOfBoundsException - If there are not enough bytes
+ * remaining to fill the requested Data Type
+ */
+ virtual float getFloat( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Reads the next eight bytes at this buffer's current position, and then
+ * increments the position by that amount.
+ * @returns the next long long in the buffer..
+ * @throws BufferUnderflowException - If there are no more bytes remaining in
+ * this buffer, meaning we have reached the set limit.
+ */
+ virtual long long getLong() throw( decaf::nio::BufferUnderflowException );
+
+ /**
+ * Reads eight bytes at the given index and returns it
+ * @param index - the index in the Buffer where the bytes are to be read
+ * @returns the long long at the given index in the buffer
+ * @throws IndexOutOfBoundsException - If there are not enough bytes
+ * remaining to fill the requested Data Type
+ */
+ virtual long long getLong( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Reads the next four bytes at this buffer's current position, and then
+ * increments the position by that amount.
+ * @returns the next int in the buffer..
+ * @throws BufferUnderflowException - If there are no more bytes remaining in
+ * this buffer, meaning we have reached the set limit.
+ */
+ virtual int getInt() throw( decaf::nio::BufferUnderflowException );
+
+ /**
+ * Reads four bytes at the given index and returns it
+ * @param index - the index in the Buffer where the bytes are to be read
+ * @returns the int at the given index in the buffer
+ * @throws IndexOutOfBoundsException - If there are not enough bytes
+ * remaining to fill the requested Data Type
+ */
+ virtual int getInt( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Reads the next two bytes at this buffer's current position, and then
+ * increments the position by that amount.
+ * @returns the next short in the buffer..
+ * @throws BufferUnderflowException - If there are no more bytes remaining in
+ * this buffer, meaning we have reached the set limit.
+ */
+ virtual short getShort() throw( decaf::nio::BufferUnderflowException );
+
+ /**
+ * Reads two bytes at the given index and returns it
+ * @param index - the index in the Buffer where the bytes are to be read
+ * @returns the short at the given index in the buffer
+ * @throws IndexOutOfBoundsException - If there are not enough bytes
+ * remaining to fill the requested Data Type
+ */
+ virtual short getShort( std::size_t index ) const
+ throw ( lang::exceptions::IndexOutOfBoundsException );
+
+ /**
+ * Writes the given byte into this buffer at the current position, and then
+ * increments the position.
+ * @param value - the byte value to be written
+ * @returns a reference to this buffer
+ * @throws BufferOverflowException - If this buffer's current position is not
+ * smaller than its limit
+ * @throws ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& put( unsigned char value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes the given byte into this buffer at the given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the byte to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& put( std::size_t index, unsigned char value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes one byte containing the given value, into this buffer at the
+ * current position, and then increments the position by one.
+ * @param value - The value to be written
+ * @returns a reference to this buffer
+ * @throw BufferOverflowException - If there are fewer than bytes remaining
+ * in this buffer than the size of the data to be written
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putChar( char value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes one byte containing the given value, into this buffer at the
+ * given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the value to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putChar( std::size_t index, char value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes eight bytes containing the given value, into this buffer at the
+ * current position, and then increments the position by eight.
+ * @param value - The value to be written
+ * @returns a reference to this buffer
+ * @throw BufferOverflowException - If there are fewer than bytes remaining
+ * in this buffer than the size of the data to be written
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putDouble( double value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes eight bytes containing the given value, into this buffer at the
+ * given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the value to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putDouble( std::size_t index, double value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes four bytes containing the given value, into this buffer at the
+ * current position, and then increments the position by eight.
+ * @param value - The value to be written
+ * @returns a reference to this buffer
+ * @throw BufferOverflowException - If there are fewer than bytes remaining
+ * in this buffer than the size of the data to be written
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putFloat( float value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes four bytes containing the given value, into this buffer at the
+ * given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the value to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putFloat( std::size_t index, float value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes eight bytes containing the given value, into this buffer at the
+ * current position, and then increments the position by eight.
+ * @param value - The value to be written
+ * @returns a reference to this buffer
+ * @throw BufferOverflowException - If there are fewer than bytes remaining
+ * in this buffer than the size of the data to be written
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putLong( long long value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes eight bytes containing the given value, into this buffer at the
+ * given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the value to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putLong( std::size_t index, long long value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes four bytes containing the given value, into this buffer at the
+ * current position, and then increments the position by eight.
+ * @param value - The value to be written
+ * @returns a reference to this buffer
+ * @throw BufferOverflowException - If there are fewer than bytes remaining
+ * in this buffer than the size of the data to be written
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putInt( int value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes four bytes containing the given value, into this buffer at the
+ * given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the value to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putInt( std::size_t index, int value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes two bytes containing the given value, into this buffer at the
+ * current position, and then increments the position by eight.
+ * @param value - The value to be written
+ * @returns a reference to this buffer
+ * @throw BufferOverflowException - If there are fewer than bytes remaining
+ * in this buffer than the size of the data to be written
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putShort( short value )
+ throw( decaf::nio::BufferOverflowException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Writes two bytes containing the given value, into this buffer at the
+ * given index.
+ * @param index - position in the Buffer to write the data
+ * @param value - the value to write.
+ * @returns a reference to this buffer
+ * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+ * minus the size of the type being written.
+ * @throw ReadOnlyBufferException - If this buffer is read-only
+ */
+ virtual ByteArrayBuffer& putShort( std::size_t index, short value )
+ throw( lang::exceptions::IndexOutOfBoundsException,
+ decaf::nio::ReadOnlyBufferException );
+
+ /**
+ * Creates a new byte buffer 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.
+ * <p>
+ * 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 ByteArrayBuffer which the caller owns.
+ */
+ virtual ByteArrayBuffer* slice() const;
+
+ protected:
+
+ /**
+ * Sets this ByteArrayBuffer as Read-Only.
+ * @param value - true if this buffer is to be read-only.
+ */
+ virtual void setReadOnly( bool value ) {
+ this->readOnly = value;
+ }
+
+ };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BYTEBUFFER_H_*/
Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "ByteArrayPerspective.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::nio;
+using namespace decaf::internal::util;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( int capacity ) : ByteArrayAdapter( capacity ){
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( unsigned char* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( char* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( double* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( float* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( long long* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( int* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( short* array, std::size_t capacity, bool own )
+ throw( lang::exceptions::NullPointerException ) :
+ ByteArrayAdapter( array, capacity, own ) {
+
+ this->references = 1;
+}