activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r603234 [2/2] - in /activemq/activemq-cpp/decaf/trunk/src/main: ./ decaf/internal/nio/ decaf/nio/
Date Tue, 11 Dec 2007 13:17:36 GMT
Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.h?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ShortArrayBuffer.h Tue Dec
11 05:17:35 2007
@@ -19,16 +19,247 @@
 #define _DECAF_INTERNAL_NIO_SHORTARRAYBUFFER_H_
 
 #include <decaf/nio/ShortBuffer.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 ShortArrayBuffer : public ShortBuffer{
+    class ShortArrayBuffer : public decaf::nio::ShortBuffer{
+    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:
 
-        ShortArrayBuffer();
+        /**
+         * Creates a ShortArrayBuffer 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
+         */
+        ShortArrayBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * Creates a ShortArrayBuffer 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
+         */
+        ShortArrayBuffer( short* 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 ShortArrayBuffer
+         * 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.
+         */
+        ShortArrayBuffer( ByteArrayPerspective& array,
+                        std::size_t offset, std::size_t capacity,
+                        bool readOnly = false )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Create a ShortArrayBuffer 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 ShortArrayBuffer this one is to mirror.
+         * @param readOnly - should this buffer be read-only, default as false
+         */
+        ShortArrayBuffer( const ShortArrayBuffer& other );
+
         virtual ~ShortArrayBuffer() {}
+
+    public:
+
+        /**
+         * Returns the short 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 short* 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 short 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 short buffer which the caller then owns.
+         */
+        virtual ShortBuffer* 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 ShortBuffer
+         * @throws ReadOnlyBufferException - If this buffer is read-only
+         */
+        virtual ShortBuffer& compact() throw( decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Creates a new short 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 short Buffer which the caller owns.
+         */
+        virtual ShortBuffer* duplicate();
+
+        /**
+         * Relative get method. Reads the value at this buffer's current position,
+         * and then increments the position.
+         * @returns the short at the current position
+         * @throws BufferUnderflowException if there no more data to return
+         */
+        virtual short get() throw ( decaf::nio::BufferUnderflowException );
+
+        /**
+         * Absolute get method. Reads the value at the given index.
+         * @param index - the index in the Buffer where the short is to be read
+         * @returns the short that is located at the given index
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual short get( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Tells whether or not this buffer is backed by an accessible short 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 ShortBuffer& put( short 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 ShortBuffer& put( std::size_t index, short value )
+            throw( lang::exceptions::IndexOutOfBoundsException,
+                   decaf::nio::ReadOnlyBufferException );
+
+        /**
+         * Creates a new ShortBuffer 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 ShortBuffer which the caller owns.
+         */
+        virtual ShortBuffer* 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/FloatBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/FloatBuffer.cpp Tue Dec 11 05:17:35
2007
@@ -35,13 +35,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string FloatBuffer::toString() const {
 
-    std::string strbuf;
+    std::ostringstream stream;
 
-    for( std::size_t i = this->position(); i < this->limit(); i++ ) {
-        strbuf.append( Float::valueOf( get( i ) ).toString() );
-    }
+    stream << "FloatBuffer, status: "
+           << "capacity =" << this->capacity()
+           << " position =" << this->position()
+           << " limit = " << this->limit();
 
-    return strbuf;
+    return stream.str();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/IntBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/IntBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/IntBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/IntBuffer.cpp Tue Dec 11 05:17:35
2007
@@ -35,13 +35,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string IntBuffer::toString() const {
 
-    std::string strbuf;
+    std::ostringstream stream;
 
-    for( std::size_t i = this->position(); i < this->limit(); i++ ) {
-        strbuf.append( Integer::valueOf( get( i ) ).toString() );
-    }
+    stream << "IntBuffer, status: "
+           << "capacity =" << this->capacity()
+           << " position =" << this->position()
+           << " limit = " << this->limit();
 
-    return strbuf;
+    return stream.str();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/LongBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/LongBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/LongBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/LongBuffer.cpp Tue Dec 11 05:17:35
2007
@@ -35,13 +35,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string LongBuffer::toString() const {
 
-    std::string strbuf;
+    std::ostringstream stream;
 
-    for( std::size_t i = this->position(); i < this->limit(); i++ ) {
-        strbuf.append( Long::valueOf( get( i ) ).toString() );
-    }
+    stream << "LongBuffer, status: "
+           << "capacity =" << this->capacity()
+           << " position =" << this->position()
+           << " limit = " << this->limit();
 
-    return strbuf;
+    return stream.str();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ShortBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ShortBuffer.cpp?rev=603234&r1=603233&r2=603234&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ShortBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ShortBuffer.cpp Tue Dec 11 05:17:35
2007
@@ -35,13 +35,14 @@
 ////////////////////////////////////////////////////////////////////////////////
 std::string ShortBuffer::toString() const {
 
-    std::string strbuf;
+    std::ostringstream stream;
 
-    for( std::size_t i = this->position(); i < this->limit(); i++ ) {
-        strbuf.append( Float::valueOf( get( i ) ).toString() );
-    }
+    stream << "ShortBuffer, status: "
+           << "capacity =" << this->capacity()
+           << " position =" << this->position()
+           << " limit = " << this->limit();
 
-    return strbuf;
+    return stream.str();
 }
 
 ////////////////////////////////////////////////////////////////////////////////



Mime
View raw message