activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r603234 [1/2] - in /activemq/activemq-cpp/decaf/trunk/src/main: ./ decaf/internal/nio/ decaf/nio/
Date Tue, 11 Dec 2007 13:17:36 GMT
Author: tabish
Date: Tue Dec 11 05:17:35 2007
New Revision: 603234

URL: http://svn.apache.org/viewvc?rev=603234&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-153

Working on implementing the NIO package

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/IntBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/LongBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ShortBuffer.cpp

Modified: activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am Tue Dec 11 05:17:35 2007
@@ -29,6 +29,10 @@
    decaf/internal/nio/ByteArrayBuffer.cpp \
    decaf/internal/nio/CharArrayBuffer.cpp \
    decaf/internal/nio/DoubleArrayBuffer.cpp \
+   decaf/internal/nio/FloatArrayBuffer.cpp \
+   decaf/internal/nio/LongArrayBuffer.cpp \
+   decaf/internal/nio/IntArrayBuffer.cpp \
+   decaf/internal/nio/ShortArrayBuffer.cpp \
    decaf/net/ServerSocket.cpp \
    decaf/net/SocketOutputStream.cpp \
    decaf/net/BufferedSocket.cpp \
@@ -203,6 +207,10 @@
    decaf/internal/nio/ByteArrayBuffer.h \
    decaf/internal/nio/CharArrayBuffer.h \
    decaf/internal/nio/DoubleArrayBuffer.h \
+   decaf/internal/nio/FloatArrayBuffer.h \
+   decaf/internal/nio/LongArrayBuffer.h \
+   decaf/internal/nio/IntArrayBuffer.h \
+   decaf/internal/nio/ShortArrayBuffer.h \
    decaf/nio/Buffer.h \
    decaf/nio/ByteBuffer.h \
    decaf/nio/CharBuffer.h \

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.cpp Tue Dec 11 05:17:35 2007
@@ -50,3 +50,35 @@
 
     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;
+}

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h Tue Dec 11 05:17:35 2007
@@ -81,6 +81,50 @@
         ByteArrayPerspective( double* array, std::size_t capacity, bool own = false )
             throw( lang::exceptions::NullPointerException );
 
+        /**
+         * Creates a array 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 capacity - size of the array, this is the limit we read and write to.
+         * @param own - is this class now the owner of the pointer.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayPerspective( float* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a array 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 capacity - size of the array, this is the limit we read and write to.
+         * @param own - is this class now the owner of the pointer.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayPerspective( long long* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a array 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 capacity - size of the array, this is the limit we read and write to.
+         * @param own - is this class now the owner of the pointer.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayPerspective( int* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a array 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 capacity - size of the array, this is the limit we read and write to.
+         * @param own - is this class now the owner of the pointer.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayPerspective( short* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
         virtual ~ByteArrayPerspective() {}
 
         /**

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h Tue Dec 11 05:17:35 2007
@@ -45,7 +45,7 @@
     public:
 
         /**
-         * Creates a CharArrayBuffer object that has its backing array allocated internally
+         * Creates a DoubleArrayBuffer 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.
@@ -54,7 +54,7 @@
         DoubleArrayBuffer( std::size_t capactiy, bool readOnly = false );
 
         /**
-         * Creates a CharArrayBuffer object that wraps the given array.  If the own flag
+         * Creates a DoubleArrayBuffer 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.
@@ -68,7 +68,7 @@
 
         /**
          * Creates a byte buffer that wraps the passed ByteArrayPerspective and
-         * start at the given offset.  The capacity and limit of the new CharArrayBuffer
+         * start at the given offset.  The capacity and limit of the new DoubleArrayBuffer
          * 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
@@ -83,10 +83,10 @@
             throw( decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
-         * Create a CharArrayBuffer that mirros this one, meaning it shares a
+         * Create a DoubleArrayBuffer 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 CharArrayBuffer this one is to mirror.
+         * @param other - the DoubleArrayBuffer this one is to mirror.
          * @param readOnly - should this buffer be read-only, default as false
          */
         DoubleArrayBuffer( const DoubleArrayBuffer& other );

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp Tue Dec 11 05:17:35 2007
@@ -18,9 +18,266 @@
 #include "FloatArrayBuffer.h"
 
 using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::internal;
 using namespace decaf::internal::nio;
+using namespace decaf::internal::util;
+using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-FloatArrayBuffer::FloatArrayBuffer() {
+FloatArrayBuffer::FloatArrayBuffer( std::size_t capacity, bool readOnly )
+    : FloatBuffer( capacity ){
+
+    // 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->offset = 0;
+    this->readOnly = readOnly;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+FloatArrayBuffer::FloatArrayBuffer( float* array, std::size_t offset,
+                                      std::size_t capacity, bool readOnly )
+    throw( decaf::lang::exceptions::NullPointerException ) : FloatBuffer( 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+FloatArrayBuffer::FloatArrayBuffer( ByteArrayPerspective& array,
+                                      std::size_t offset, std::size_t capacity,
+                                      bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : FloatBuffer( capacity ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::FloatArrayBuffer - 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+FloatArrayBuffer::FloatArrayBuffer( const FloatArrayBuffer& other )
+    : FloatBuffer( 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;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+float* FloatArrayBuffer::array()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::array - Buffer is Read-Only" );
+        }
+
+        return this->_array->getFloatArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+std::size_t FloatArrayBuffer::arrayOffset()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::arrayOffset() - Buffer is Read Only." );
+        }
+
+        return this->offset;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+FloatBuffer* FloatArrayBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        FloatArrayBuffer* buffer = new FloatArrayBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+FloatBuffer& FloatArrayBuffer::compact() throw( decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::compact() - Buffer is Read Only." );
+        }
+
+        // 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 ) {
+            this->put( ix, this->get( this->position() + ix ) );
+        }
+
+        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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+FloatBuffer* FloatArrayBuffer::duplicate() {
+
+    try{
+        return new FloatArrayBuffer( *this );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+float FloatArrayBuffer::get() throw ( decaf::nio::BufferUnderflowException ) {
+
+    try{
+        return this->get( this->_position++ );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+float FloatArrayBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::get - Not enough data to fill request." );
+        }
+
+        return this->_array->getFloat( offset + index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer& FloatArrayBuffer::put( float value )
+    throw( BufferOverflowException, 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer& FloatArrayBuffer::put( std::size_t index, float value )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::put(i,i) - Buffer is Read Only." );
+        }
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "FloatArrayBuffer::put(i,i) - Not enough data to fill request." );
+        }
+
+        this->_array->putFloat( 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatBuffer* FloatArrayBuffer::slice() const {
+
+    try{
+
+        return new FloatArrayBuffer( *(this->_array),
+                                     this->offset + this->position(),
+                                     this->remaining(),
+                                     this->isReadOnly() );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h Tue Dec 11 05:17:35 2007
@@ -19,16 +19,247 @@
 #define _DECAF_INTERNAL_NIO_FLOATARRAYBUFFER_H_
 
 #include <decaf/nio/FloatBuffer.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>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
-    class FloatArrayBuffer : public FloatBuffer {
+    class FloatArrayBuffer : public decaf::nio::FloatBuffer{
+    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:
 
-        FloatArrayBuffer();
+        /**
+         * 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
+         */
+        FloatArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * 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
+         * @throws NullPointerException if buffer is NULL
+         */
+        FloatArrayBuffer( float* 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 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 NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         */
+        FloatArrayBuffer( ByteArrayPerspective& array,
+                          std::size_t offset, std::size_t capacity,
+                          bool readOnly = false )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Create a FloatArrayBuffer 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 FloatArrayBuffer this one is to mirror.
+         * @param readOnly - should this buffer be read-only, default as false
+         */
+        FloatArrayBuffer( const FloatArrayBuffer& other );
+
         virtual ~FloatArrayBuffer() {}
+
+    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.
+         */
+        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.
+         */
+        virtual std::size_t 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.
+         */
+        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
+         */
+        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.
+         */
+        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
+         */
+        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
+         */
+        virtual float get( std::size_t 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
+         */
+        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
+         */
+        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
+         */
+        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
+         */
+        virtual FloatBuffer& put( std::size_t 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.
+         */
+        virtual FloatBuffer* 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;
+        }
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.cpp Tue Dec 11 05:17:35 2007
@@ -18,9 +18,266 @@
 #include "IntArrayBuffer.h"
 
 using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::internal;
 using namespace decaf::internal::nio;
+using namespace decaf::internal::util;
+using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-IntArrayBuffer::IntArrayBuffer() {
+IntArrayBuffer::IntArrayBuffer( std::size_t capacity, bool readOnly )
+    : IntBuffer( capacity ){
+
+    // 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) );
+    this->offset = 0;
+    this->readOnly = readOnly;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+IntArrayBuffer::IntArrayBuffer( int* array, std::size_t offset,
+                                      std::size_t capacity, bool readOnly )
+    throw( decaf::lang::exceptions::NullPointerException ) : IntBuffer( 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+IntArrayBuffer::IntArrayBuffer( ByteArrayPerspective& array,
+                                      std::size_t offset, std::size_t capacity,
+                                      bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : IntBuffer( capacity ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::IntArrayBuffer - 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+IntArrayBuffer::IntArrayBuffer( const IntArrayBuffer& other )
+    : IntBuffer( 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;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+int* IntArrayBuffer::array()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::array - Buffer is Read-Only" );
+        }
+
+        return this->_array->getIntArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+std::size_t IntArrayBuffer::arrayOffset()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::arrayOffset() - Buffer is Read Only." );
+        }
+
+        return this->offset;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+IntBuffer* IntArrayBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        IntArrayBuffer* buffer = new IntArrayBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+IntBuffer& IntArrayBuffer::compact() throw( decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::compact() - Buffer is Read Only." );
+        }
+
+        // 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 ) {
+            this->put( ix, this->get( this->position() + ix ) );
+        }
+
+        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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+IntBuffer* IntArrayBuffer::duplicate() {
+
+    try{
+        return new IntArrayBuffer( *this );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+int IntArrayBuffer::get() throw ( decaf::nio::BufferUnderflowException ) {
+
+    try{
+        return this->get( this->_position++ );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+int IntArrayBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::get - Not enough data to fill request." );
+        }
+
+        return this->_array->getInt( offset + index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+IntBuffer& IntArrayBuffer::put( int value )
+    throw( BufferOverflowException, 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+IntBuffer& IntArrayBuffer::put( std::size_t index, int value )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::put(i,i) - Buffer is Read Only." );
+        }
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "IntArrayBuffer::put(i,i) - Not enough data to fill request." );
+        }
+
+        this->_array->putInt( 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+IntBuffer* IntArrayBuffer::slice() const {
+
+    try{
+
+        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/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.h?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/IntArrayBuffer.h Tue Dec 11 05:17:35 2007
@@ -19,16 +19,247 @@
 #define _DECAF_INTERNAL_NIO_INTARRAYBUFFER_H_
 
 #include <decaf/nio/IntBuffer.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>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
-    class IntArrayBuffer : public IntBuffer {
+    class IntArrayBuffer : public decaf::nio::IntBuffer {
+    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:
 
-        IntArrayBuffer();
+        /**
+         * 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
+         */
+        IntArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * 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
+         * @throws NullPointerException if buffer is NULL
+         */
+        IntArrayBuffer( int* 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 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 NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         */
+        IntArrayBuffer( ByteArrayPerspective& array,
+                        std::size_t offset, std::size_t capacity,
+                        bool readOnly = false )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Create a IntArrayBuffer 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 IntArrayBuffer this one is to mirror.
+         * @param readOnly - should this buffer be read-only, default as false
+         */
+        IntArrayBuffer( const IntArrayBuffer& other );
+
         virtual ~IntArrayBuffer() {}
+
+    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.
+         */
+        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.
+         */
+        virtual std::size_t 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.
+         */
+        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
+         */
+        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.
+         */
+        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
+         */
+        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
+         */
+        virtual int get( std::size_t 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
+         */
+        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
+         */
+        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
+         */
+        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
+         */
+        virtual IntBuffer& put( std::size_t 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.
+         */
+        virtual IntBuffer* 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;
+        }
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.cpp Tue Dec 11 05:17:35 2007
@@ -18,9 +18,266 @@
 #include "LongArrayBuffer.h"
 
 using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::internal;
 using namespace decaf::internal::nio;
+using namespace decaf::internal::util;
+using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-LongArrayBuffer::LongArrayBuffer() {
+LongArrayBuffer::LongArrayBuffer( std::size_t capacity, bool readOnly )
+    : LongBuffer( capacity ){
+
+    // 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->offset = 0;
+    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 ) {
+
+    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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+LongArrayBuffer::LongArrayBuffer( ByteArrayPerspective& array,
+                                      std::size_t offset, std::size_t capacity,
+                                      bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : LongBuffer( capacity ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::LongArrayBuffer - 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+LongArrayBuffer::LongArrayBuffer( const LongArrayBuffer& other )
+    : LongBuffer( 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;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+long long* LongArrayBuffer::array()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::array - Buffer is Read-Only" );
+        }
+
+        return this->_array->getLongArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+std::size_t LongArrayBuffer::arrayOffset()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::arrayOffset() - Buffer is Read Only." );
+        }
+
+        return this->offset;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+LongBuffer* LongArrayBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        LongArrayBuffer* buffer = new LongArrayBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+LongBuffer& LongArrayBuffer::compact() throw( decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::compact() - Buffer is Read Only." );
+        }
+
+        // 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 ) {
+            this->put( ix, this->get( this->position() + ix ) );
+        }
+
+        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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+LongBuffer* LongArrayBuffer::duplicate() {
+
+    try{
+        return new LongArrayBuffer( *this );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+long long LongArrayBuffer::get() throw ( decaf::nio::BufferUnderflowException ) {
+
+    try{
+        return this->get( this->_position++ );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+long long LongArrayBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::get - Not enough data to fill request." );
+        }
+
+        return this->_array->getLong( offset + index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LongBuffer& LongArrayBuffer::put( long long value )
+    throw( BufferOverflowException, 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LongBuffer& LongArrayBuffer::put( std::size_t index, long long value )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::put(i,i) - Buffer is Read Only." );
+        }
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "LongArrayBuffer::put(i,i) - Not enough data to fill request." );
+        }
+
+        this->_array->putLong( 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+LongBuffer* LongArrayBuffer::slice() const {
+
+    try{
+
+        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/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.h?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/LongArrayBuffer.h Tue Dec 11 05:17:35 2007
@@ -19,16 +19,247 @@
 #define _DECAF_INTERNAL_NIO_LONGARRAYBUFFER_H_
 
 #include <decaf/nio/LongBuffer.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>
 
 namespace decaf{
 namespace internal{
 namespace nio{
 
-    class LongArrayBuffer : public LongBuffer {
+    class LongArrayBuffer : public decaf::nio::LongBuffer {
+    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:
 
-        LongArrayBuffer();
+        /**
+         * 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
+         */
+        LongArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * 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
+         * @throws NullPointerException if buffer is NULL
+         */
+        LongArrayBuffer( long long* 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 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 NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         */
+        LongArrayBuffer( ByteArrayPerspective& array,
+                        std::size_t offset, std::size_t capacity,
+                        bool readOnly = false )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Create a LongArrayBuffer 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 LongArrayBuffer this one is to mirror.
+         * @param readOnly - should this buffer be read-only, default as false
+         */
+        LongArrayBuffer( const LongArrayBuffer& other );
+
         virtual ~LongArrayBuffer() {}
+
+    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.
+         */
+        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.
+         */
+        virtual std::size_t 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.
+         */
+        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
+         */
+        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.
+         */
+        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
+         */
+        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
+         */
+        virtual long long get( std::size_t 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
+         */
+        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
+         */
+        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
+         */
+        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
+         */
+        virtual LongBuffer& put( std::size_t 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.
+         */
+        virtual LongBuffer* 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;
+        }
 
     };
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.cpp Tue Dec 11 05:17:35 2007
@@ -18,9 +18,266 @@
 #include "ShortArrayBuffer.h"
 
 using namespace decaf;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 using namespace decaf::internal;
 using namespace decaf::internal::nio;
+using namespace decaf::internal::util;
+using namespace decaf::nio;
 
 ///////////////////////////////////////////////////////////////////////////////
-ShortArrayBuffer::ShortArrayBuffer() {
+ShortArrayBuffer::ShortArrayBuffer( std::size_t capacity, bool readOnly )
+    : ShortBuffer( capacity ){
+
+    // 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->offset = 0;
+    this->readOnly = readOnly;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ShortArrayBuffer::ShortArrayBuffer( short* array, std::size_t offset,
+                                      std::size_t capacity, bool readOnly )
+    throw( decaf::lang::exceptions::NullPointerException ) : ShortBuffer( 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ShortArrayBuffer::ShortArrayBuffer( ByteArrayPerspective& array,
+                                      std::size_t offset, std::size_t capacity,
+                                      bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : ShortBuffer( capacity ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::ShortArrayBuffer - 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ShortArrayBuffer::ShortArrayBuffer( const ShortArrayBuffer& other )
+    : ShortBuffer( 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;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+short* ShortArrayBuffer::array()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::array - Buffer is Read-Only" );
+        }
+
+        return this->_array->getShortArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+std::size_t ShortArrayBuffer::arrayOffset()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::arrayOffset() - Buffer is Read Only." );
+        }
+
+        return this->offset;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ShortBuffer* ShortArrayBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        ShortArrayBuffer* buffer = new ShortArrayBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ShortBuffer& ShortArrayBuffer::compact() throw( decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::compact() - Buffer is Read Only." );
+        }
+
+        // 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 ) {
+            this->put( ix, this->get( this->position() + ix ) );
+        }
+
+        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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+ShortBuffer* ShortArrayBuffer::duplicate() {
+
+    try{
+        return new ShortArrayBuffer( *this );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+short ShortArrayBuffer::get() throw ( decaf::nio::BufferUnderflowException ) {
+
+    try{
+        return this->get( this->_position++ );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+short ShortArrayBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::get - Not enough data to fill request." );
+        }
+
+        return this->_array->getShort( offset + index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ShortBuffer& ShortArrayBuffer::put( short value )
+    throw( BufferOverflowException, 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ShortBuffer& ShortArrayBuffer::put( std::size_t index, short value )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::put(i,i) - Buffer is Read Only." );
+        }
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ShortArrayBuffer::put(i,i) - Not enough data to fill request." );
+        }
+
+        this->_array->putShort( 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ShortBuffer* ShortArrayBuffer::slice() const {
+
+    try{
+
+        return new ShortArrayBuffer( *(this->_array),
+                                     this->offset + this->position(),
+                                     this->remaining(),
+                                     this->isReadOnly() );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
 }



Mime
View raw message