activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r925692 [3/14] - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/ main/activemq/commands/ main/activemq/io/ main/activemq/wireformat/openwire/ main/activemq/wireformat/openwire/marshal/ main/decaf/internal/io/ main/decaf/internal/nio...
Date Sat, 20 Mar 2010 21:57:24 GMT
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.cpp Sat Mar 20 21:57:20 2010
@@ -26,54 +26,72 @@ using namespace decaf::internal::util;
 using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-FloatArrayBuffer::FloatArrayBuffer( std::size_t capacity, bool readOnly )
-    : FloatBuffer( capacity ){
+FloatArrayBuffer::FloatArrayBuffer( int size, bool readOnly )
+    throw( decaf::lang::exceptions::IllegalArgumentException ) : FloatBuffer( size ){
 
     // Allocate using the ByteArray, not read-only initially.  Take a reference to it.
     // The capacity is the given capacity times the size of the stored datatype
-    this->_array = new ByteArrayPerspective( capacity * sizeof(float) );
+    this->_array.reset( new ByteArrayAdapter( size * sizeof(float) ) );
     this->offset = 0;
+    this->length = size;
     this->readOnly = readOnly;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-FloatArrayBuffer::FloatArrayBuffer( float* array, std::size_t offset,
-                                      std::size_t capacity, bool readOnly )
-    throw( decaf::lang::exceptions::NullPointerException ) : FloatBuffer( capacity ) {
+FloatArrayBuffer::FloatArrayBuffer( float* array, int size, int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : FloatBuffer( length ) {
 
     try{
 
+        if( offset < 0 || offset > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
+        }
+
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = new ByteArrayPerspective( array, capacity, false );
+        this->_array.reset( new ByteArrayAdapter( array, size, false ) );
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-FloatArrayBuffer::FloatArrayBuffer( ByteArrayPerspective& array,
-                                      std::size_t offset, std::size_t capacity,
-                                      bool readOnly )
-    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
-    : FloatBuffer( capacity ) {
+FloatArrayBuffer::FloatArrayBuffer( const Pointer<ByteArrayAdapter>& array,
+                                    int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : FloatBuffer( length ) {
 
     try{
-        if( offset > array.getCapacity() ) {
+
+        if( offset < 0 || offset > array->getCapacity() ) {
             throw IndexOutOfBoundsException(
-                __FILE__, __LINE__,
-                "FloatArrayBuffer::FloatArrayBuffer - offset %d is greater than capacity %d",
-                offset, array.getCapacity() );
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > array->getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
         }
 
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = array.takeRef();
+        this->_array = array;
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
@@ -83,8 +101,9 @@ FloatArrayBuffer::FloatArrayBuffer( cons
     : FloatBuffer( other ) {
 
     // get the byte buffer of the caller and take a reference
-    this->_array = other._array->takeRef();
+    this->_array = other._array;
     this->offset = other.offset;
+    this->length = other.length;
     this->readOnly = other.readOnly;
 }
 
@@ -92,16 +111,6 @@ FloatArrayBuffer::FloatArrayBuffer( cons
 FloatArrayBuffer::~FloatArrayBuffer() {
 
     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()
@@ -135,7 +144,7 @@ float* FloatArrayBuffer::array()
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-std::size_t FloatArrayBuffer::arrayOffset()
+int FloatArrayBuffer::arrayOffset()
     throw( decaf::lang::exceptions::UnsupportedOperationException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -188,7 +197,7 @@ FloatBuffer& FloatArrayBuffer::compact()
 
         // copy from the current pos to the beginning all the remaining bytes
         // the set pos to the
-        for( std::size_t ix = 0; ix < this->remaining(); ++ix ) {
+        for( int ix = 0; ix < this->remaining(); ++ix ) {
             this->put( ix, this->get( this->position() + ix ) );
         }
 
@@ -225,7 +234,7 @@ float FloatArrayBuffer::get() throw ( de
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-float FloatArrayBuffer::get( std::size_t index ) const
+float FloatArrayBuffer::get( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -259,7 +268,7 @@ FloatBuffer& FloatArrayBuffer::put( floa
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-FloatBuffer& FloatArrayBuffer::put( std::size_t index, float value )
+FloatBuffer& FloatArrayBuffer::put( int index, float value )
     throw( decaf::lang::exceptions::IndexOutOfBoundsException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -292,7 +301,7 @@ FloatBuffer* FloatArrayBuffer::slice() c
 
     try{
 
-        return new FloatArrayBuffer( *(this->_array),
+        return new FloatArrayBuffer( this->_array,
                                      this->offset + this->position(),
                                      this->remaining(),
                                      this->isReadOnly() );

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/FloatArrayBuffer.h Sat Mar 20 21:57:20 2010
@@ -24,12 +24,16 @@
 #include <decaf/nio/BufferUnderflowException.h>
 #include <decaf/nio/BufferOverflowException.h>
 #include <decaf/nio/ReadOnlyBufferException.h>
-#include <decaf/internal/nio/ByteArrayPerspective.h>
+#include <decaf/internal/util/ByteArrayAdapter.h>
+
+#include <decaf/lang/Pointer.h>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
+    using decaf::internal::util::ByteArrayAdapter;
+
     class DECAF_API FloatArrayBuffer : public decaf::nio::FloatBuffer{
     private:
 
@@ -37,10 +41,13 @@ namespace nio{
         bool readOnly;
 
         // The reference array object that backs this buffer.
-        internal::nio::ByteArrayPerspective* _array;
+        decaf::lang::Pointer<ByteArrayAdapter> _array;
 
         // Offset into the array that we are to start from
-        std::size_t offset;
+        int offset;
+
+        // Number of bytes to read past the offset, or Limit.
+        int length;
 
     public:
 
@@ -48,44 +55,68 @@ namespace nio{
          * Creates a FloatArrayBuffer 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
+         *
+         * @param size
+         *      The size of the array, this is the limit we read and write to.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws IllegalArguementException if the capacity value is negative.
          */
-        FloatArrayBuffer( std::size_t capacity, bool readOnly = false );
+        FloatArrayBuffer( int size, bool readOnly = false )
+            throw( decaf::lang::exceptions::IllegalArgumentException );
 
         /**
          * Creates a FloatArrayBuffer 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
+         *
+         * @param array
+         *      The actual array to wrap.
+         * @param size
+         *      The size of the given array.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
          * @throws NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
          */
-        FloatArrayBuffer( float* array, std::size_t offset,
-                          std::size_t capacity, bool readOnly = false )
-            throw( decaf::lang::exceptions::NullPointerException );
+        FloatArrayBuffer( float* array, int size, int offset, int length, bool readOnly = false )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Creates a byte buffer that wraps the passed ByteArrayPerspective and
+         * Creates a byte buffer that wraps the passed ByteArrayAdapter and
          * start at the given offset.  The capacity and limit of the new FloatArrayBuffer
          * 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 capacity - the length of the array we are wrapping or limit.
-         * @param readOnly - is this a readOnly buffer.
-         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         *
+         * @param array
+         *      The ByteArrayAdapter to wrap.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws NullPointerException if array is NULL
+         * @throws IndexOutOfBoundsException if offset + length is greater than array size.
          */
-        FloatArrayBuffer( ByteArrayPerspective& array,
-                          std::size_t offset, std::size_t capacity,
+        FloatArrayBuffer( const decaf::lang::Pointer<ByteArrayAdapter>& array, int offset, int capacity,
                           bool readOnly = false )
-            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Create a FloatArrayBuffer that mirrors this one, meaning it shares a
-         * reference to this buffers ByteArrayPerspective and when changes
+         * reference to this buffers ByteArrayAdapter and when changes
          * are made to that data it is reflected in both.
-         * @param other - the FloatArrayBuffer this one is to mirror.
+         *
+         * @param other
+         *      The FloatArrayBuffer this one is to mirror.
          */
         FloatArrayBuffer( const FloatArrayBuffer& other );
 
@@ -94,166 +125,83 @@ namespace nio{
     public:
 
         /**
-         * Returns the float array that backs this buffer  (optional operation).
-         * <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 read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
         virtual float* array()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Returns the offset within this buffer's backing array of the first element of
-         * the buffer  (optional operation).
-         * <p>
-         * 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.
-         * @throws ReadOnlyBufferException if this Buffer is read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
-        virtual std::size_t arrayOffset()
+        virtual int arrayOffset()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new, read-only float 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 float buffer which the caller then owns.
+         * {@inheritDoc}
          */
         virtual FloatBuffer* 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 FloatBuffer
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
         virtual FloatBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new float 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 float Buffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual FloatBuffer* duplicate();
 
         /**
-         * Relative get method. Reads the value at this buffer's current position,
-         * and then increments the position.
-         * @returns the float at the current position
-         * @throws BufferUnderflowException if there no more data to return
+         * {@inheritDoc}
          */
         virtual float get() throw ( decaf::nio::BufferUnderflowException );
 
         /**
-         * Absolute get method. Reads the value at the given index.
-         * @param index - the index in the Buffer where the float is to be read
-         * @returns the float that is located at the given index
-         * @throws IndexOutOfBoundsException - If index is not smaller than the
-         * buffer's limit
+         * {@inheritDoc}
          */
-        virtual float get( std::size_t index ) const
+        virtual float get( int index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Tells whether or not this buffer is backed by an accessible float 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
+         * {@inheritDoc}
          */
         virtual bool hasArray() const { return true; }
 
         /**
-         * Tells whether or not this buffer is read-only.
-         * @returns true if, and only if, this buffer is read-only
+         * {@inheritDoc}
          */
         virtual bool isReadOnly() const {
             return this->readOnly;
         }
 
         /**
-         * Writes the given doubles into this buffer at the current position, and then
-         * increments the position.
-         * @param value - the doubles 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
+         * {@inheritDoc}
          */
         virtual FloatBuffer& put( float value )
             throw( decaf::nio::BufferOverflowException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Writes the given doubles into this buffer at the given index.
-         * @param index - position in the Buffer to write the data
-         * @param value - the doubles to write.
-         * @returns a reference to this buffer
-         * @throws IndexOutOfBoundsException - If index greater than the buffer's limit
-         * minus the size of the type being written.
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
-        virtual FloatBuffer& put( std::size_t index, float value )
+        virtual FloatBuffer& put( int index, float value )
             throw( lang::exceptions::IndexOutOfBoundsException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new FloatBuffer 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 FloatBuffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual FloatBuffer* slice() const;
 
     protected:
 
         /**
-         * Sets this ByteArrayBuffer as Read-Only.
-         * @param value - true if this buffer is to be read-only.
+         * Sets this FloatArrayBuffer as Read-Only.
+         *
+         * @param value
+         *      Boolean value, true if this buffer is to be read-only, false otherwise.
          */
         virtual void setReadOnly( bool value ) {
             this->readOnly = value;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.cpp Sat Mar 20 21:57:20 2010
@@ -26,54 +26,72 @@ using namespace decaf::internal::util;
 using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-IntArrayBuffer::IntArrayBuffer( std::size_t capacity, bool readOnly )
-    : IntBuffer( capacity ){
+IntArrayBuffer::IntArrayBuffer( int size, bool readOnly )
+    throw( decaf::lang::exceptions::IllegalArgumentException ) : IntBuffer( size ){
 
     // Allocate using the ByteArray, not read-only initially.  Take a reference to it.
-    // The capacity is the given capacity times the size of the stored datatype
-    this->_array = new ByteArrayPerspective( capacity * sizeof(int) );
+    // The size is the given size times the size of the stored datatype
+    this->_array.reset( new ByteArrayAdapter( size * sizeof(int) ) );
     this->offset = 0;
+    this->length = size;
     this->readOnly = readOnly;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-IntArrayBuffer::IntArrayBuffer( int* array, std::size_t offset,
-                                      std::size_t capacity, bool readOnly )
-    throw( decaf::lang::exceptions::NullPointerException ) : IntBuffer( capacity ) {
+IntArrayBuffer::IntArrayBuffer( int* array, int size, int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : IntBuffer( length ) {
 
     try{
 
+        if( offset < 0 || offset > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
+        }
+
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = new ByteArrayPerspective( array, capacity, false );
+        this->_array.reset( new ByteArrayAdapter( array, size, false ) );
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-IntArrayBuffer::IntArrayBuffer( ByteArrayPerspective& array,
-                                      std::size_t offset, std::size_t capacity,
-                                      bool readOnly )
-    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
-    : IntBuffer( capacity ) {
+IntArrayBuffer::IntArrayBuffer( const Pointer<ByteArrayAdapter>& array,
+                                int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : IntBuffer( length ) {
 
     try{
-        if( offset > array.getCapacity() ) {
+
+        if( offset < 0 || offset > array->getCapacity() ) {
             throw IndexOutOfBoundsException(
-                __FILE__, __LINE__,
-                "IntArrayBuffer::IntArrayBuffer - offset %d is greater than capacity %d",
-                offset, array.getCapacity() );
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > array->getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
         }
 
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = array.takeRef();
+        this->_array = array;
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
@@ -83,8 +101,9 @@ IntArrayBuffer::IntArrayBuffer( const In
     : IntBuffer( other ) {
 
     // get the byte buffer of the caller and take a reference
-    this->_array = other._array->takeRef();
+    this->_array = other._array;
     this->offset = other.offset;
+    this->length = other.length;
     this->readOnly = other.readOnly;
 }
 
@@ -92,16 +111,6 @@ IntArrayBuffer::IntArrayBuffer( const In
 IntArrayBuffer::~IntArrayBuffer() {
 
     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()
@@ -135,7 +144,7 @@ int* IntArrayBuffer::array()
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-std::size_t IntArrayBuffer::arrayOffset()
+int IntArrayBuffer::arrayOffset()
     throw( decaf::lang::exceptions::UnsupportedOperationException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -188,7 +197,7 @@ IntBuffer& IntArrayBuffer::compact() thr
 
         // copy from the current pos to the beginning all the remaining bytes
         // the set pos to the
-        for( std::size_t ix = 0; ix < this->remaining(); ++ix ) {
+        for( int ix = 0; ix < this->remaining(); ++ix ) {
             this->put( ix, this->get( this->position() + ix ) );
         }
 
@@ -225,7 +234,7 @@ int IntArrayBuffer::get() throw ( decaf:
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-int IntArrayBuffer::get( std::size_t index ) const
+int IntArrayBuffer::get( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -259,7 +268,7 @@ IntBuffer& IntArrayBuffer::put( int valu
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-IntBuffer& IntArrayBuffer::put( std::size_t index, int value )
+IntBuffer& IntArrayBuffer::put( int index, int value )
     throw( decaf::lang::exceptions::IndexOutOfBoundsException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -292,10 +301,10 @@ IntBuffer* IntArrayBuffer::slice() const
 
     try{
 
-        return new IntArrayBuffer( *(this->_array),
-                                     this->offset + this->position(),
-                                     this->remaining(),
-                                     this->isReadOnly() );
+        return new IntArrayBuffer( this->_array,
+                                   this->offset + this->position(),
+                                   this->remaining(),
+                                   this->isReadOnly() );
     }
     DECAF_CATCH_RETHROW( Exception )
     DECAF_CATCHALL_THROW( Exception )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/IntArrayBuffer.h Sat Mar 20 21:57:20 2010
@@ -24,12 +24,16 @@
 #include <decaf/nio/BufferUnderflowException.h>
 #include <decaf/nio/BufferOverflowException.h>
 #include <decaf/nio/ReadOnlyBufferException.h>
-#include <decaf/internal/nio/ByteArrayPerspective.h>
+#include <decaf/internal/util/ByteArrayAdapter.h>
+
+#include <decaf/lang/Pointer.h>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
+    using decaf::internal::util::ByteArrayAdapter;
+
     class DECAF_API IntArrayBuffer : public decaf::nio::IntBuffer {
     private:
 
@@ -37,10 +41,13 @@ namespace nio{
         bool readOnly;
 
         // The reference array object that backs this buffer.
-        internal::nio::ByteArrayPerspective* _array;
+        decaf::lang::Pointer<ByteArrayAdapter> _array;
 
         // Offset into the array that we are to start from
-        std::size_t offset;
+        int offset;
+
+        // The length of the sub-array, or limit
+        int length;
 
     public:
 
@@ -48,44 +55,68 @@ namespace nio{
          * Creates a IntArrayBuffer 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
+         *
+         * @param size
+         *      The size of the array, this is the limit we read and write to.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws IllegalArguementException if the capacity value is negative.
          */
-        IntArrayBuffer( std::size_t capacity, bool readOnly = false );
+        IntArrayBuffer( int size, bool readOnly = false )
+            throw( decaf::lang::exceptions::IllegalArgumentException );
 
         /**
          * Creates a IntArrayBuffer 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
+         *
+         * @param array
+         *      The actual array to wrap.
+         * @param size
+         *      The size of the given array.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
          * @throws NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
          */
-        IntArrayBuffer( int* array, std::size_t offset,
-                        std::size_t capacity, bool readOnly = false )
-            throw( decaf::lang::exceptions::NullPointerException );
+        IntArrayBuffer( int* array, int size, int offset, int length, bool readOnly = false )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Creates a byte buffer that wraps the passed ByteArrayPerspective and
+         * Creates a byte buffer that wraps the passed ByteArrayAdapter and
          * start at the given offset.  The capacity and limit of the new IntArrayBuffer
          * 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 capacity - the length of the array we are wrapping or limit.
-         * @param readOnly - is this a readOnly buffer.
-         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         *
+         * @param array
+         *      The ByteArrayAdapter to wrap.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws NullPointerException if array is NULL
+         * @throws IndexOutOfBoundsException if offset + length is greater than array size.
          */
-        IntArrayBuffer( ByteArrayPerspective& array,
-                        std::size_t offset, std::size_t capacity,
+        IntArrayBuffer( const decaf::lang::Pointer<ByteArrayAdapter>& array, int offset, int length,
                         bool readOnly = false )
-            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Create a IntArrayBuffer that mirrors this one, meaning it shares a
-         * reference to this buffers ByteArrayPerspective and when changes
+         * reference to this buffers ByteArrayAdapter and when changes
          * are made to that data it is reflected in both.
-         * @param other - the IntArrayBuffer this one is to mirror.
+         *
+         * @param other
+         *      The IntArrayBuffer this one is to mirror.
          */
         IntArrayBuffer( const IntArrayBuffer& other );
 
@@ -94,166 +125,83 @@ namespace nio{
     public:
 
         /**
-         * Returns the int array that backs this buffer  (optional operation).
-         * <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 read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
         virtual int* array()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Returns the offset within this buffer's backing array of the first element of
-         * the buffer  (optional operation).
-         * <p>
-         * 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.
-         * @throws ReadOnlyBufferException if this Buffer is read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
-        virtual std::size_t arrayOffset()
+        virtual int arrayOffset()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new, read-only int 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 int buffer which the caller then owns.
+         * {@inheritDoc}
          */
         virtual IntBuffer* 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 IntBuffer
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
         virtual IntBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new int 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 int Buffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual IntBuffer* duplicate();
 
         /**
-         * Relative get method. Reads the value at this buffer's current position,
-         * and then increments the position.
-         * @returns the int at the current position
-         * @throws BufferUnderflowException if there no more data to return
+         * {@inheritDoc}
          */
         virtual int get() throw ( decaf::nio::BufferUnderflowException );
 
         /**
-         * Absolute get method. Reads the value at the given index.
-         * @param index - the index in the Buffer where the int is to be read
-         * @returns the int that is located at the given index
-         * @throws IndexOutOfBoundsException - If index is not smaller than the
-         * buffer's limit
+         * {@inheritDoc}
          */
-        virtual int get( std::size_t index ) const
+        virtual int get( int index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Tells whether or not this buffer is backed by an accessible int 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
+         * {@inheritDoc}
          */
         virtual bool hasArray() const { return true; }
 
         /**
-         * Tells whether or not this buffer is read-only.
-         * @returns true if, and only if, this buffer is read-only
+         * {@inheritDoc}
          */
         virtual bool isReadOnly() const {
             return this->readOnly;
         }
 
         /**
-         * Writes the given doubles into this buffer at the current position, and then
-         * increments the position.
-         * @param value - the doubles 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
+         * {@inheritDoc}
          */
         virtual IntBuffer& put( int value )
             throw( decaf::nio::BufferOverflowException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Writes the given doubles into this buffer at the given index.
-         * @param index - position in the Buffer to write the data
-         * @param value - the doubles to write.
-         * @returns a reference to this buffer
-         * @throws IndexOutOfBoundsException - If index greater than the buffer's limit
-         * minus the size of the type being written.
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
-        virtual IntBuffer& put( std::size_t index, int value )
+        virtual IntBuffer& put( int index, int value )
             throw( lang::exceptions::IndexOutOfBoundsException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new IntBuffer 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 IntBuffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual IntBuffer* slice() const;
 
     protected:
 
         /**
-         * Sets this ByteArrayBuffer as Read-Only.
-         * @param value - true if this buffer is to be read-only.
+         * Sets this IntArrayBuffer as Read-Only.
+         *
+         * @param value
+         *      Boolean value, true if this buffer is to be read-only, false otherwise.
          */
         virtual void setReadOnly( bool value ) {
             this->readOnly = value;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.cpp Sat Mar 20 21:57:20 2010
@@ -26,54 +26,72 @@ using namespace decaf::internal::util;
 using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-LongArrayBuffer::LongArrayBuffer( std::size_t capacity, bool readOnly )
-    : LongBuffer( capacity ){
+LongArrayBuffer::LongArrayBuffer( int size, bool readOnly )
+    throw( decaf::lang::exceptions::IllegalArgumentException ) : LongBuffer( size ){
 
     // Allocate using the ByteArray, not read-only initially.  Take a reference to it.
     // The capacity is the given capacity times the size of the stored datatype
-    this->_array = new ByteArrayPerspective( capacity * sizeof(long long) );
+    this->_array.reset( new ByteArrayAdapter( size * sizeof(long long) ) );
     this->offset = 0;
+    this->length = size;
     this->readOnly = readOnly;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-LongArrayBuffer::LongArrayBuffer( long long* array, std::size_t offset,
-                                      std::size_t capacity, bool readOnly )
-    throw( decaf::lang::exceptions::NullPointerException ) : LongBuffer( capacity ) {
+LongArrayBuffer::LongArrayBuffer( long long* array, int size, int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : LongBuffer( length ) {
 
     try{
 
+        if( offset < 0 || offset > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
+        }
+
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = new ByteArrayPerspective( array, capacity, false );
+        this->_array.reset( new ByteArrayAdapter( array, size, false ) );
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-LongArrayBuffer::LongArrayBuffer( ByteArrayPerspective& array,
-                                      std::size_t offset, std::size_t capacity,
-                                      bool readOnly )
-    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
-    : LongBuffer( capacity ) {
+LongArrayBuffer::LongArrayBuffer( const Pointer<ByteArrayAdapter>& array,
+                                  int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : LongBuffer( length ) {
 
     try{
-        if( offset > array.getCapacity() ) {
+
+        if( offset < 0 || offset > array->getCapacity() ) {
             throw IndexOutOfBoundsException(
-                __FILE__, __LINE__,
-                "LongArrayBuffer::LongArrayBuffer - offset %d is greater than capacity %d",
-                offset, array.getCapacity() );
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > array->getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
         }
 
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = array.takeRef();
+        this->_array = array;
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
@@ -83,8 +101,9 @@ LongArrayBuffer::LongArrayBuffer( const 
     : LongBuffer( other ) {
 
     // get the byte buffer of the caller and take a reference
-    this->_array = other._array->takeRef();
+    this->_array = other._array;
     this->offset = other.offset;
+    this->length = other.length;
     this->readOnly = other.readOnly;
 }
 
@@ -92,16 +111,6 @@ LongArrayBuffer::LongArrayBuffer( const 
 LongArrayBuffer::~LongArrayBuffer() {
 
     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()
@@ -135,7 +144,7 @@ long long* LongArrayBuffer::array()
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-std::size_t LongArrayBuffer::arrayOffset()
+int LongArrayBuffer::arrayOffset()
     throw( decaf::lang::exceptions::UnsupportedOperationException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -188,7 +197,7 @@ LongBuffer& LongArrayBuffer::compact() t
 
         // copy from the current pos to the beginning all the remaining bytes
         // the set pos to the
-        for( std::size_t ix = 0; ix < this->remaining(); ++ix ) {
+        for( int ix = 0; ix < this->remaining(); ++ix ) {
             this->put( ix, this->get( this->position() + ix ) );
         }
 
@@ -225,7 +234,7 @@ long long LongArrayBuffer::get() throw (
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-long long LongArrayBuffer::get( std::size_t index ) const
+long long LongArrayBuffer::get( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -259,7 +268,7 @@ LongBuffer& LongArrayBuffer::put( long l
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-LongBuffer& LongArrayBuffer::put( std::size_t index, long long value )
+LongBuffer& LongArrayBuffer::put( int index, long long value )
     throw( decaf::lang::exceptions::IndexOutOfBoundsException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -292,10 +301,10 @@ LongBuffer* LongArrayBuffer::slice() con
 
     try{
 
-        return new LongArrayBuffer( *(this->_array),
-                                     this->offset + this->position(),
-                                     this->remaining(),
-                                     this->isReadOnly() );
+        return new LongArrayBuffer( this->_array,
+                                    this->offset + this->position(),
+                                    this->remaining(),
+                                    this->isReadOnly() );
     }
     DECAF_CATCH_RETHROW( Exception )
     DECAF_CATCHALL_THROW( Exception )

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.h?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/LongArrayBuffer.h Sat Mar 20 21:57:20 2010
@@ -24,12 +24,16 @@
 #include <decaf/nio/BufferUnderflowException.h>
 #include <decaf/nio/BufferOverflowException.h>
 #include <decaf/nio/ReadOnlyBufferException.h>
-#include <decaf/internal/nio/ByteArrayPerspective.h>
+#include <decaf/internal/util/ByteArrayAdapter.h>
+
+#include <decaf/lang/Pointer.h>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
+    using decaf::internal::util::ByteArrayAdapter;
+
     class DECAF_API LongArrayBuffer : public decaf::nio::LongBuffer {
     private:
 
@@ -37,10 +41,13 @@ namespace nio{
         bool readOnly;
 
         // The reference array object that backs this buffer.
-        internal::nio::ByteArrayPerspective* _array;
+        decaf::lang::Pointer<ByteArrayAdapter> _array;
 
         // Offset into the array that we are to start from
-        std::size_t offset;
+        int offset;
+
+        // The length of the sub-array, or limit
+        int length;
 
     public:
 
@@ -48,44 +55,68 @@ namespace nio{
          * Creates a IntArrayBuffer 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
+         *
+         * @param size
+         *      The size of the array, this is the limit we read and write to.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws IllegalArguementException if the capacity value is negative.
          */
-        LongArrayBuffer( std::size_t capacity, bool readOnly = false );
+        LongArrayBuffer( int size, bool readOnly = false )
+            throw( decaf::lang::exceptions::IllegalArgumentException );
 
         /**
          * Creates a LongArrayBuffer 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
+         *
+         * @param array
+         *      The actual array to wrap.
+         * @param size
+         *      The size of the given array.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
          * @throws NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
          */
-        LongArrayBuffer( long long* array, std::size_t offset,
-                         std::size_t capacity, bool readOnly = false )
-            throw( decaf::lang::exceptions::NullPointerException );
+        LongArrayBuffer( long long* array, int size, int offset, int length, bool readOnly = false )
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Creates a byte buffer that wraps the passed ByteArrayPerspective and
+         * Creates a byte buffer that wraps the passed ByteArrayAdapter and
          * start at the given offset.  The capacity and limit of the new LongArrayBuffer
          * 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 capacity - the length of the array we are wrapping or limit.
-         * @param readOnly - is this a readOnly buffer.
-         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         *
+         * @param array
+         *      The ByteArrayAdapter to wrap.
+         * @param offset
+         *      The position that is this buffers start position.
+         * @param length
+         *      The limit of how many bytes into the array this Buffer can write.
+         * @param readOnly
+         *      Boolean indicating if this buffer should be read-only, default as false.
+         *
+         * @throws NullPointerException if array is NULL
+         * @throws IndexOutOfBoundsException if offset + length is greater than array size.
          */
-        LongArrayBuffer( ByteArrayPerspective& array,
-                         std::size_t offset, std::size_t capacity,
+        LongArrayBuffer( const decaf::lang::Pointer<ByteArrayAdapter>& array, int offset, int length,
                          bool readOnly = false )
-            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+            throw( decaf::lang::exceptions::NullPointerException,
+                   decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Create a LongArrayBuffer that mirrors this one, meaning it shares a
-         * reference to this buffers ByteArrayPerspective and when changes
+         * reference to this buffers ByteArrayAdapter and when changes
          * are made to that data it is reflected in both.
-         * @param other - the LongArrayBuffer this one is to mirror.
+         *
+         * @param other
+         *      The LongArrayBuffer this one is to mirror.
          */
         LongArrayBuffer( const LongArrayBuffer& other );
 
@@ -94,166 +125,83 @@ namespace nio{
     public:
 
         /**
-         * Returns the long long array that backs this buffer  (optional operation).
-         * <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 read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
         virtual long long* array()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Returns the offset within this buffer's backing array of the first element of
-         * the buffer  (optional operation).
-         * <p>
-         * 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.
-         * @throws ReadOnlyBufferException if this Buffer is read only.
-         * @throws UnsupportedOperationException if the underlying store has no array.
+         * {@inheritDoc}
          */
-        virtual std::size_t arrayOffset()
+        virtual int arrayOffset()
             throw( decaf::lang::exceptions::UnsupportedOperationException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new, read-only long long 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 long long buffer which the caller then owns.
+         * {@inheritDoc}
          */
         virtual LongBuffer* 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 LongBuffer
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
         virtual LongBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new long long 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 long long Buffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual LongBuffer* duplicate();
 
         /**
-         * Relative get method. Reads the value at this buffer's current position,
-         * and then increments the position.
-         * @returns the long long at the current position
-         * @throws BufferUnderflowException if there no more data to return
+         * {@inheritDoc}
          */
         virtual long long get() throw ( decaf::nio::BufferUnderflowException );
 
         /**
-         * Absolute get method. Reads the value at the given index.
-         * @param index - the index in the Buffer where the long long is to be read
-         * @returns the long long that is located at the given index
-         * @throws IndexOutOfBoundsException - If index is not smaller than the
-         * buffer's limit
+         * {@inheritDoc}
          */
-        virtual long long get( std::size_t index ) const
+        virtual long long get( int index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Tells whether or not this buffer is backed by an accessible long long 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
+         * {@inheritDoc}
          */
         virtual bool hasArray() const { return true; }
 
         /**
-         * Tells whether or not this buffer is read-only.
-         * @returns true if, and only if, this buffer is read-only
+         * {@inheritDoc}
          */
         virtual bool isReadOnly() const {
             return this->readOnly;
         }
 
         /**
-         * Writes the given doubles into this buffer at the current position, and then
-         * increments the position.
-         * @param value - the doubles 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
+         * {@inheritDoc}
          */
         virtual LongBuffer& put( long long value )
             throw( decaf::nio::BufferOverflowException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Writes the given doubles into this buffer at the given index.
-         * @param index - position in the Buffer to write the data
-         * @param value - the doubles to write.
-         * @returns a reference to this buffer
-         * @throws IndexOutOfBoundsException - If index greater than the buffer's limit
-         * minus the size of the type being written.
-         * @throws ReadOnlyBufferException - If this buffer is read-only
+         * {@inheritDoc}
          */
-        virtual LongBuffer& put( std::size_t index, long long value )
+        virtual LongBuffer& put( int index, long long value )
             throw( lang::exceptions::IndexOutOfBoundsException,
                    decaf::nio::ReadOnlyBufferException );
 
         /**
-         * Creates a new LongBuffer 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 LongBuffer which the caller owns.
+         * {@inheritDoc}
          */
         virtual LongBuffer* slice() const;
 
     protected:
 
         /**
-         * Sets this ByteArrayBuffer as Read-Only.
-         * @param value - true if this buffer is to be read-only.
+         * Sets this LongArrayBuffer as Read-Only.
+         *
+         * @param value
+         *      Boolean value, true if this buffer is to be read-only, false otherwise.
          */
         virtual void setReadOnly( bool value ) {
             this->readOnly = value;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.cpp?rev=925692&r1=925691&r2=925692&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/internal/nio/ShortArrayBuffer.cpp Sat Mar 20 21:57:20 2010
@@ -26,54 +26,72 @@ using namespace decaf::internal::util;
 using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-ShortArrayBuffer::ShortArrayBuffer( std::size_t capacity, bool readOnly )
-    : ShortBuffer( capacity ){
+ShortArrayBuffer::ShortArrayBuffer( int size, bool readOnly )
+    throw( decaf::lang::exceptions::IllegalArgumentException ) : ShortBuffer( size ){
 
     // Allocate using the ByteArray, not read-only initially.  Take a reference to it.
     // The capacity is the given capacity times the size of the stored datatype
-    this->_array = new ByteArrayPerspective( capacity * sizeof(short) );
+    this->_array.reset( new ByteArrayAdapter( size * sizeof(short) ) );
     this->offset = 0;
+    this->length = size;
     this->readOnly = readOnly;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-ShortArrayBuffer::ShortArrayBuffer( short* array, std::size_t offset,
-                                      std::size_t capacity, bool readOnly )
-    throw( decaf::lang::exceptions::NullPointerException ) : ShortBuffer( capacity ) {
+ShortArrayBuffer::ShortArrayBuffer( short* array, int size, int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : ShortBuffer( length ) {
 
     try{
 
+        if( offset < 0 || offset > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > size ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
+        }
+
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = new ByteArrayPerspective( array, capacity, false );
+        this->_array.reset( new ByteArrayAdapter( array, length, false ) );
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-ShortArrayBuffer::ShortArrayBuffer( ByteArrayPerspective& array,
-                                      std::size_t offset, std::size_t capacity,
-                                      bool readOnly )
-    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
-    : ShortBuffer( capacity ) {
+ShortArrayBuffer::ShortArrayBuffer( const Pointer<ByteArrayAdapter>& array,
+                                    int offset, int length, bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::lang::exceptions::NullPointerException ) : ShortBuffer( length ) {
 
     try{
-        if( offset > array.getCapacity() ) {
+
+        if( offset < 0 || offset > array->getCapacity() ) {
             throw IndexOutOfBoundsException(
-                __FILE__, __LINE__,
-                "ShortArrayBuffer::ShortArrayBuffer - offset %d is greater than capacity %d",
-                offset, array.getCapacity() );
+                __FILE__, __LINE__, "Offset parameter if out of bounds, %d", offset );
+        }
+
+        if( length < 0 || offset + length > array->getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__, "length parameter if out of bounds, %d", length );
         }
 
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = array.takeRef();
+        this->_array = array;
         this->offset = offset;
+        this->length = length;
         this->readOnly = readOnly;
     }
     DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
     DECAF_CATCHALL_THROW( NullPointerException )
 }
@@ -83,8 +101,9 @@ ShortArrayBuffer::ShortArrayBuffer( cons
     : ShortBuffer( other ) {
 
     // get the byte buffer of the caller and take a reference
-    this->_array = other._array->takeRef();
+    this->_array = other._array;
     this->offset = other.offset;
+    this->length = other.length;
     this->readOnly = other.readOnly;
 }
 
@@ -92,16 +111,6 @@ ShortArrayBuffer::ShortArrayBuffer( cons
 ShortArrayBuffer::~ShortArrayBuffer() {
 
     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()
@@ -135,7 +144,7 @@ short* ShortArrayBuffer::array()
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-std::size_t ShortArrayBuffer::arrayOffset()
+int ShortArrayBuffer::arrayOffset()
     throw( decaf::lang::exceptions::UnsupportedOperationException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -188,7 +197,7 @@ ShortBuffer& ShortArrayBuffer::compact()
 
         // copy from the current pos to the beginning all the remaining bytes
         // the set pos to the
-        for( std::size_t ix = 0; ix < this->remaining(); ++ix ) {
+        for( int ix = 0; ix < this->remaining(); ++ix ) {
             this->put( ix, this->get( this->position() + ix ) );
         }
 
@@ -225,7 +234,7 @@ short ShortArrayBuffer::get() throw ( de
 }
 
 ///////////////////////////////////////////////////////////////////////////////
-short ShortArrayBuffer::get( std::size_t index ) const
+short ShortArrayBuffer::get( int index ) const
     throw ( lang::exceptions::IndexOutOfBoundsException ) {
 
     try{
@@ -259,7 +268,7 @@ ShortBuffer& ShortArrayBuffer::put( shor
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ShortBuffer& ShortArrayBuffer::put( std::size_t index, short value )
+ShortBuffer& ShortArrayBuffer::put( int index, short value )
     throw( decaf::lang::exceptions::IndexOutOfBoundsException,
            decaf::nio::ReadOnlyBufferException ) {
 
@@ -292,7 +301,7 @@ ShortBuffer* ShortArrayBuffer::slice() c
 
     try{
 
-        return new ShortArrayBuffer( *(this->_array),
+        return new ShortArrayBuffer( this->_array,
                                      this->offset + this->position(),
                                      this->remaining(),
                                      this->isReadOnly() );



Mime
View raw message