activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r652104 [3/29] - in /activemq/activemq-cpp/trunk: ./ m4/ src/examples/ src/examples/consumers/ src/main/ src/main/decaf/ src/main/decaf/internal/ src/main/decaf/internal/net/ src/main/decaf/internal/nio/ src/main/decaf/internal/util/ src/ma...
Date Tue, 29 Apr 2008 20:52:37 GMT
Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/ByteArrayPerspective.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_BYTEARRAYPERSPECTIVE_H_
+#define _DECAF_INTERNAL_NIO_BYTEARRAYPERSPECTIVE_H_
+
+#include <decaf/internal/util/ByteArrayAdapter.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+    /**
+     * This class extends ByteArray to create a reference counted byte array
+     * that can be held and used by several differen ByteBuffers and allow them
+     * to know on destruction whose job it is to delete the perspective.
+     * <p>
+     * Creating an instance of this class implicity takes a reference to it, so
+     * a creator must return its ref before the count will be zero.
+     */
+    class DECAF_API ByteArrayPerspective : public util::ByteArrayAdapter {
+    private:
+
+        // Count of the number of perspectives into this array.
+        int references;
+
+    public:
+
+        /**
+         * Creates a byte array object that is 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.
+         */
+        ByteArrayPerspective( int capacity );
+
+        /**
+         * Creates a byte 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( unsigned 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( 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 );
+
+        /**
+         * 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() {}
+
+        /**
+         * Takes a reference to this Perspective and returns a pointer to this
+         * so that a caller can take a ref and get a ref in one call.
+         * @returns this
+         */
+        ByteArrayPerspective* takeRef() {
+            this->references++;
+            return this;
+        }
+
+        /**
+         * Returns a reference to this Perspective, when the count is zero
+         * it should be deleted
+         */
+        void returnRef() { this->references--; }
+
+        /**
+         * @returns the current number of reference on this perspective
+         */
+        int getReferences() const { return this->references; }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BYTEARRAYPERSPECTIVE_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,331 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "CharArrayBuffer.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;
+
+///////////////////////////////////////////////////////////////////////////////
+CharArrayBuffer::CharArrayBuffer( std::size_t capacity, bool readOnly )
+    : CharBuffer( 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;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+CharArrayBuffer::CharArrayBuffer( char* array, std::size_t offset,
+                                  std::size_t capacity, bool readOnly )
+    throw( decaf::lang::exceptions::NullPointerException ) : CharBuffer( 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+CharArrayBuffer::CharArrayBuffer( ByteArrayPerspective& array,
+                                  std::size_t offset, std::size_t length,
+                                  bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : CharBuffer( length ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::CharArrayBuffer - 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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+CharArrayBuffer::CharArrayBuffer( const CharArrayBuffer& other )
+    : CharBuffer( 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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CharArrayBuffer::~CharArrayBuffer() {
+
+    try{
+
+        // Return this object's reference to the buffer.
+        this->_array->returnRef();
+
+        // If there are no other Buffers out there that reference it then we
+        // delete it now, the internal unsigned char* array will be deleted
+        // if we where the owner.
+        if( this->_array->getReferences() == 0 ) {
+            delete this->_array;
+        }
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+///////////////////////////////////////////////////////////////////////////////
+char* CharArrayBuffer::array()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::array - Buffer is Read-Only" );
+        }
+
+        return this->_array->getCharArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, UnsupportedOperationException )
+    DECAF_CATCHALL_THROW( UnsupportedOperationException )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+std::size_t CharArrayBuffer::arrayOffset()
+    throw( decaf::lang::exceptions::UnsupportedOperationException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+CharBuffer* CharArrayBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        CharArrayBuffer* buffer = new CharArrayBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+CharBuffer& CharArrayBuffer::compact()  throw( decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+CharBuffer* CharArrayBuffer::duplicate() {
+
+    try{
+        return new CharArrayBuffer( *this );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+char CharArrayBuffer::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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+char CharArrayBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( ( index ) >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::get - Not enough data to fill request." );
+        }
+
+        return this->_array->getChar( offset + index );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CharBuffer& CharArrayBuffer::put( char 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CharBuffer& CharArrayBuffer::put( std::size_t index, char value )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+           decaf::nio::ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw decaf::nio::ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::put(i,i) - Buffer is Read Only." );
+        }
+
+        if( index >= this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::put(i,i) - Not enough data to fill request." );
+        }
+
+        this->_array->putChar( 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CharBuffer* CharArrayBuffer::slice() const {
+
+    try{
+
+        return new CharArrayBuffer( *(this->_array),
+                                    this->offset + this->position(),
+                                    this->remaining(),
+                                    this->isReadOnly() );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+CharSequence* CharArrayBuffer::subSequence( std::size_t start, std::size_t end ) const
+    throw ( decaf::lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( start > end ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::subSequence - start > end" );
+        }
+
+        if( start > this->limit() || end > this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "CharArrayBuffer::subSequence - Sequence exceed limit" );
+        }
+
+        CharArrayBuffer* buffer = new CharArrayBuffer( *this );
+
+        buffer->position( this->position() + start );
+        buffer->limit( this->position() + end );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/CharArrayBuffer.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,289 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_CHARARRAYBUFFER_H_
+#define _DECAF_INTERNAL_NIO_CHARARRAYBUFFER_H_
+
+#include <decaf/nio/CharBuffer.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 DECAF_API CharArrayBuffer : public decaf::nio::CharBuffer {
+    protected:
+
+        // Read / Write flag
+        bool readOnly;
+
+        // The reference array object that backs this buffer.
+        internal::nio::ByteArrayPerspective* _array;
+
+        // Offset into the array that we are to start from
+        std::size_t offset;
+
+    public:
+
+        /**
+         * Creates a 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
+         */
+        CharArrayBuffer( 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
+         */
+        CharArrayBuffer( char* array, std::size_t offset,
+                         std::size_t capacity, bool readOnly = false )
+            throw( decaf::lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte buffer that wraps the passed ByteArrayPerspective and
+         * start at the given offset.  The capacity and limit of the new 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.
+         */
+        CharArrayBuffer( 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
+         */
+        CharArrayBuffer( const CharArrayBuffer& other );
+
+        virtual ~CharArrayBuffer();
+
+    public:  // Overrides
+
+        /**
+         * Returns the character 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 char* 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 char 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 char buffer which the caller then owns.
+         */
+        virtual CharBuffer* 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 CharBuffer
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual CharBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Creates a new char 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 char Buffer which the caller owns.
+         */
+        virtual CharBuffer* duplicate();
+
+        /**
+         * Relative get method. Reads the character at this buffer's current position,
+         * and then increments the position.
+         * @returns the char at the current position
+         * @throws BufferUnderflowException if there no more data to return
+         */
+        virtual char get() throw ( decaf::nio::BufferUnderflowException );
+
+        /**
+         * Absolute get method. Reads the char at the given index.
+         * @param index - the index in the Buffer where the char is to be read
+         * @returns the char that is located at the given index
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual char get( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Tells whether or not this buffer is backed by an accessible char 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 char into this buffer at the current position, and then
+         * increments the position.
+         * @param value - the char 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 CharBuffer& put( char value )
+            throw( decaf::nio::BufferOverflowException,
+                   decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Writes the given char into this buffer at the given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the char 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 CharBuffer& put( std::size_t index, char value )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException,
+                   decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Creates a new CharBuffer 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 CharBuffer which the caller owns.
+         */
+        virtual CharBuffer* slice() const;
+
+        /**
+         * Creates a new character buffer that represents the specified subsequence of
+         * this buffer, relative to the current position.
+         * <p>
+         * The new buffer will share this buffer's content; that is, if the content of
+         * this buffer is mutable then modifications to one buffer will cause the other
+         * to be modified. The new buffer's capacity will be that of this buffer, its
+         * position will be position() + start, and its limit will be position() + end.
+         * The new Buffer will be read-only if, and only if, this buffer is read-only.
+         * @param start - The index, relative to the current position, of the first
+         * character in the subsequence; must be non-negative and no larger than
+         * remaining()
+         * @param end - The index, relative to the current position, of the character
+         * following the last character in the subsequence; must be no smaller than start
+         * and no larger than remaining()
+         * @return The new character buffer, caller owns
+         * @throws IndexOutOfBoundsException - If the preconditions on start and end fail
+         */
+        virtual lang::CharSequence* subSequence( std::size_t start, std::size_t end ) const
+            throw ( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+    protected:
+
+        /**
+         * Sets this ByteArrayBuffer as Read-Only.
+         * @param value - true if this buffer is to be read-only.
+         */
+        virtual void setReadOnly( bool value ) {
+            this->readOnly = value;
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_CHARARRAYBUFFER_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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( std::size_t capacity, bool readOnly )
+    : DoubleBuffer( 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(double) );
+    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 capacity,
+                                      bool readOnly )
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+    : DoubleBuffer( capacity ) {
+
+    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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+DoubleArrayBuffer::~DoubleArrayBuffer() {
+
+    try{
+
+        // Return this object's reference to the buffer.
+        this->_array->returnRef();
+
+        // If there are no other Buffers out there that reference it then we
+        // delete it now, the internal unsigned char* array will be deleted
+        // if we where the owner.
+        if( this->_array->getReferences() == 0 ) {
+            delete this->_array;
+        }
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+///////////////////////////////////////////////////////////////////////////////
+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
+        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 )
+}
+
+///////////////////////////////////////////////////////////////////////////////
+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 >= 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 >= 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 )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/DoubleArrayBuffer.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_DOUBLEARRAYBUFFER_H_
+#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 DECAF_API 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:
+
+        /**
+         * 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.
+         * @param readOnly - should this buffer be read-only, default as false
+         */
+        DoubleArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * 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.
+         * @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 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
+         * @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 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 DoubleArrayBuffer 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;
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_DOUBLEARRAYBUFFER_H_*/

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.cpp Tue Apr 29 13:52:30 2008
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "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( 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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+FloatArrayBuffer::~FloatArrayBuffer() {
+
+    try{
+
+        // Return this object's reference to the buffer.
+        this->_array->returnRef();
+
+        // If there are no other Buffers out there that reference it then we
+        // delete it now, the internal unsigned char* array will be deleted
+        // if we where the owner.
+        if( this->_array->getReferences() == 0 ) {
+            delete this->_array;
+        }
+    }
+    DECAF_CATCH_NOTHROW( Exception )
+    DECAF_CATCHALL_NOTHROW()
+}
+
+///////////////////////////////////////////////////////////////////////////////
+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 )
+}

Added: activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h?rev=652104&view=auto
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h (added)
+++ activemq/activemq-cpp/trunk/src/main/decaf/internal/nio/FloatArrayBuffer.h Tue Apr 29 13:52:30 2008
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_FLOATARRAYBUFFER_H_
+#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 DECAF_API 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:
+
+        /**
+         * 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;
+        }
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_FLOATARRAYBUFFER_H_*/



Mime
View raw message