activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r602611 - in /activemq/activemq-cpp/decaf/trunk/src/main: ./ decaf/internal/nio/ decaf/nio/
Date Sun, 09 Dec 2007 02:11:16 GMT
Author: tabish
Date: Sat Dec  8 18:11:16 2007
New Revision: 602611

URL: http://svn.apache.org/viewvc?rev=602611&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/BufferFactory.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h
    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.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.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=602611&r1=602610&r2=602611&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am Sat Dec  8 18:11:16 2007
@@ -28,6 +28,7 @@
    decaf/internal/nio/ByteArrayPerspective.cpp \
    decaf/internal/nio/ByteArrayBuffer.cpp \
    decaf/internal/nio/CharArrayBuffer.cpp \
+   decaf/internal/nio/DoubleArrayBuffer.cpp \
    decaf/net/ServerSocket.cpp \
    decaf/net/SocketOutputStream.cpp \
    decaf/net/BufferedSocket.cpp \
@@ -201,6 +202,7 @@
    decaf/internal/nio/ByteArrayPerspective.h \
    decaf/internal/nio/ByteArrayBuffer.h \
    decaf/internal/nio/CharArrayBuffer.h \
+   decaf/internal/nio/DoubleArrayBuffer.h \
    decaf/nio/Buffer.h \
    decaf/nio/ByteBuffer.h \
    decaf/nio/CharBuffer.h \

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp?rev=602611&r1=602610&r2=602611&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp Sat Dec
 8 18:11:16 2007
@@ -19,6 +19,7 @@
 
 #include <decaf/internal/nio/ByteArrayBuffer.h>
 #include <decaf/internal/nio/CharArrayBuffer.h>
+#include <decaf/internal/nio/DoubleArrayBuffer.h>
 
 using namespace decaf;
 using namespace decaf::internal;
@@ -90,6 +91,40 @@
 
     try{
         return new CharArrayBuffer( &buffer[0], 0, buffer.size(), false );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* BufferFactory::createDoubleBuffer( std::size_t capacity ) {
+
+    try{
+        return new DoubleArrayBuffer( capacity );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* BufferFactory::createDoubleBuffer( double* buffer,
+                                                 std::size_t offset,
+                                                 std::size_t length )
+    throw( lang::exceptions::NullPointerException ) {
+
+    try{
+        return new DoubleArrayBuffer( buffer, offset, length, false );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* BufferFactory::createDoubleBuffer( std::vector<double>& buffer )
{
+
+    try{
+        return new DoubleArrayBuffer( &buffer[0], 0, buffer.size(), false );
     }
     DECAF_CATCH_RETHROW( Exception )
     DECAF_CATCHALL_THROW( Exception )

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h?rev=602611&r1=602610&r2=602611&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h Sat Dec
 8 18:11:16 2007
@@ -119,6 +119,46 @@
          */
         static decaf::nio::CharBuffer* createCharBuffer( std::vector<char>& buffer
);
 
+        /**
+         * Allocates a new char buffer whose position will be zero its limit will
+         * be its capacity and its mark is not set.
+         * @param capacity - the internal buffer's capacity.
+         * @returns a newly allocated DoubleBuffer which the caller owns.
+         */
+        static decaf::nio::DoubleBuffer* createDoubleBuffer( std::size_t capacity );
+
+        /**
+         * Wraps the passed buffer with a new DoubleBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; that is, modifications
+         * to the buffer will cause the array to be modified and vice versa. The new
+         * buffer's capacity will be array.length, its position will be offset, its limit
+         * will be offset + length, and its mark will be undefined. Its backing array
+         * will be the given array, and its array offset will be zero.
+         * @param buffer - The array that will back the new buffer
+         * @param offset - The offset of the subarray to be used
+         * @param length - The length of the subarray to be used
+         * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+         */
+        static decaf::nio::DoubleBuffer* createDoubleBuffer( double* buffer,
+                                                             std::size_t offset,
+                                                             std::size_t length )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Wraps the passed STL Double Vector in a DoubleBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; modifications to the
+         * buffer will cause the array to be modified and vice versa. The new buffer's
+         * capacity and limit will be buffer.size(), its position will be zero, and its
+         * mark will be undefined. Its backing array will be the given array, and its
+         * array offset will be zero.
+         * @param buffer - The vector that will back the new buffer, the vector must
+         * have been sized to the desired size already by calling vector.resize( N ).
+         * @returns a new DoubleBuffer that is backed by buffer, caller owns.
+         */
+        static decaf::nio::DoubleBuffer* createDoubleBuffer( std::vector<double>&
buffer );
+
     };
 
 }}}

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=602611&r1=602610&r2=602611&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
Sat Dec  8 18:11:16 2007
@@ -42,3 +42,11 @@
 
     this->references = 1;
 }
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayPerspective::ByteArrayPerspective( double* 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=602611&r1=602610&r2=602611&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 Sat
Dec  8 18:11:16 2007
@@ -70,6 +70,17 @@
         ByteArrayPerspective( char* 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( double* 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.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp?rev=602611&r1=602610&r2=602611&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp Sat
Dec  8 18:11:16 2007
@@ -18,9 +18,265 @@
 #include "DoubleArrayBuffer.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;
 
 ///////////////////////////////////////////////////////////////////////////////
-DoubleArrayBuffer::DoubleArrayBuffer() {
+DoubleArrayBuffer::DoubleArrayBuffer( std::size_t capacity, bool readOnly )
+    : DoubleBuffer( capacity ){
+
+    // Allocate using the ByteArray, not read-only initially.  Take a reference to it.
+    this->_array = new ByteArrayPerspective( capacity );
+    this->offset = 0;
+    this->readOnly = readOnly;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DoubleArrayBuffer::DoubleArrayBuffer( double* array, std::size_t offset,
+                                      std::size_t capacity, bool readOnly )
+    throw( decaf::lang::exceptions::NullPointerException ) : DoubleBuffer( 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DoubleArrayBuffer::DoubleArrayBuffer( ByteArrayPerspective& array,
+                                      std::size_t offset, std::size_t length,
+                                      bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : DoubleBuffer( length ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::DoubleArrayBuffer - 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DoubleArrayBuffer::DoubleArrayBuffer( const DoubleArrayBuffer& other )
+    : DoubleBuffer( 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;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+double* DoubleArrayBuffer::array()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::array - Buffer is Read-Only" );
+        }
+
+        return this->_array->getDoubleArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+std::size_t DoubleArrayBuffer::arrayOffset()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* DoubleArrayBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        DoubleArrayBuffer* buffer = new DoubleArrayBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DoubleBuffer& DoubleArrayBuffer::compact() throw( decaf::nio::ReadOnlyBufferException
) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::compact() - Buffer is Read Only." );
+        }
+
+        // copy from the current pos to the beginning all the remaining bytes
+        // the set pos to the
+        memcpy( this->array() + offset,
+                this->array() + offset + this->position(),
+                this->remaining() );
+
+        this->position( this->limit() - this->position() );
+        this->limit( this->capacity() );
+        this->_markSet = false;
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( decaf::nio::ReadOnlyBufferException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, decaf::nio::ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( decaf::nio::ReadOnlyBufferException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* DoubleArrayBuffer::duplicate() {
+
+    try{
+        return new DoubleArrayBuffer( *this );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+double DoubleArrayBuffer::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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+double DoubleArrayBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( ( index + sizeof(double) ) >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::get - Not enough data to fill request." );
+        }
+
+        return this->_array->getDouble( offset + index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer& DoubleArrayBuffer::put( double 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer& DoubleArrayBuffer::put( std::size_t index, double value )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::put(i,i) - Buffer is Read Only." );
+        }
+
+        if( index + sizeof(double) >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "DoubleArrayBuffer::put(i,i) - Not enough data to fill request." );
+        }
+
+        this->_array->putDouble( 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* DoubleArrayBuffer::slice() const {
+
+    try{
+
+        return new DoubleArrayBuffer( *(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/DoubleArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h?rev=602611&r1=602610&r2=602611&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 Sat
Dec  8 18:11:16 2007
@@ -19,16 +19,247 @@
 #define _DECAF_INTERNAL_NIO_DOUBLEARRAYBUFFER_H_
 
 #include <decaf/nio/DoubleBuffer.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 DoubleArrayBuffer : public DoubleBuffer{
+    class DoubleArrayBuffer : public decaf::nio::DoubleBuffer{
+    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:
 
-        DoubleArrayBuffer();
+        /**
+         * Creates a CharArrayBuffer 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
+         */
+        DoubleArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * Creates a CharArrayBuffer 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
+         */
+        DoubleArrayBuffer( double* 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 CharArrayBuffer
+         * will be that of the remaining capacity of the passed buffer.
+         * @param array - the ByteArrayPerspective to wrap
+         * @param offset - the offset into array where the buffer starts
+         * @param length - the length of the array we are wrapping or limit.
+         * @param readOnly - is this a readOnly buffer.
+         * @throws NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         */
+        DoubleArrayBuffer( ByteArrayPerspective& array,
+                           std::size_t offset, std::size_t length,
+                           bool readOnly = false )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Create a CharArrayBuffer 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 readOnly - should this buffer be read-only, default as false
+         */
+        DoubleArrayBuffer( const DoubleArrayBuffer& other );
+
         virtual ~DoubleArrayBuffer() {}
+
+    public:
+
+        /**
+         * Returns the double 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 double* 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 double 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 double buffer which the caller then owns.
+         */
+        virtual DoubleBuffer* 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 DoubleBuffer
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual DoubleBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Creates a new double 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 double Buffer which the caller owns.
+         */
+        virtual DoubleBuffer* duplicate();
+
+        /**
+         * Relative get method. Reads the value at this buffer's current position,
+         * and then increments the position.
+         * @returns the double at the current position
+         * @throws BufferUnderflowException if there no more data to return
+         */
+        virtual double get() throw ( decaf::nio::BufferUnderflowException );
+
+        /**
+         * Absolute get method. Reads the value at the given index.
+         * @param index - the index in the Buffer where the double is to be read
+         * @returns the double that is located at the given index
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual double get( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Tells whether or not this buffer is backed by an accessible double 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 DoubleBuffer& put( double 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 DoubleBuffer& put( std::size_t index, double value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Creates a new DoubleBuffer 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 DoubleBuffer which the caller owns.
+         */
+        virtual DoubleBuffer* 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/nio/DoubleBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp?rev=602611&r1=602610&r2=602611&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/DoubleBuffer.cpp Sat Dec  8 18:11:16
2007
@@ -19,10 +19,12 @@
 
 #include <decaf/lang/Double.h>
 #include <decaf/lang/Math.h>
+#include "decaf/internal/nio/BufferFactory.h"
 
 using namespace std;
 using namespace decaf;
 using namespace decaf::nio;
+using namespace decaf::internal::nio;
 using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
@@ -30,6 +32,54 @@
 DoubleBuffer::DoubleBuffer( std::size_t capacity )
  :  Buffer( capacity ) {
 
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* DoubleBuffer::allocate( std::size_t capacity ) {
+
+    try{
+
+        return BufferFactory::createDoubleBuffer( capacity );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* DoubleBuffer::wrap( double* buffer, std::size_t offset, std::size_t length
)
+    throw( lang::exceptions::NullPointerException ) {
+
+    try{
+
+        if( buffer == NULL ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "CharBuffer::wrap - Passed Buffer is Null.");
+        }
+
+        return BufferFactory::createDoubleBuffer( buffer, offset, length );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleBuffer* DoubleBuffer::wrap( std::vector<double>& buffer ) {
+
+    try{
+
+        if( buffer.empty() ) {
+            throw NullPointerException(
+                __FILE__, __LINE__,
+                "DoubleBuffer::wrap - Passed Buffer is Empty.");
+        }
+
+        return BufferFactory::createDoubleBuffer( &buffer[0], 0, buffer.size() );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
 }
 
 ////////////////////////////////////////////////////////////////////////////////



Mime
View raw message