activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r598078 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio: Buffer.cpp Buffer.h ByteBuffer.cpp ByteBuffer.h
Date Sun, 25 Nov 2007 22:57:58 GMT
Author: tabish
Date: Sun Nov 25 14:57:57 2007
New Revision: 598078

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

Working on the NIO package

Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.cpp?rev=598078&r1=598077&r2=598078&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.cpp Sun Nov 25 14:57:57 2007
@@ -26,15 +26,10 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 Buffer::Buffer( std::size_t capacity ) {
-    this->_capacity = capacity;
     this->_limit = capacity;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-Buffer::~Buffer() {
-}
-
-////////////////////////////////////////////////////////////////////////////////
 Buffer& Buffer::position( std::size_t newPosition )
     throw( lang::exceptions::IllegalArgumentException ) {
 
@@ -56,7 +51,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 Buffer& Buffer::limit( std::size_t newLimit ) throw( IllegalArgumentException ) {
 
-    if( newLimit > this->_capacity ) {
+    if( newLimit > this->capacity() ) {
         throw IllegalArgumentException(
             __FILE__, __LINE__,
             "Buffer::limit - new limit is larger than the capacity." );
@@ -104,7 +99,7 @@
     this->_position = 0;
     this->_mark = 0;
     this->markSet = false;
-    this->_limit = this->_capacity;
+    this->_limit = this->capacity();
     return *this;
 }
 

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h?rev=598078&r1=598077&r2=598078&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h Sun Nov 25 14:57:57 2007
@@ -125,25 +125,22 @@
     class DECAF_API Buffer {
     protected:
 
-        std::size_t _capacity;
-        std::size_t _position;
+        mutable std::size_t _position;
         std::size_t _limit;
         std::size_t _mark;
         bool markSet;
 
     public:
 
-        Buffer( std::size_t capacity );
-        virtual ~Buffer();
+        Buffer( std::size_t capactiy );
+        virtual ~Buffer() {}
 
     public:
 
         /**
          * @returns this buffer's capacity.
          */
-        virtual int capacity() const {
-            return this->_capacity;
-        }
+        virtual std::size_t capacity() const = 0;
 
         /**
          * @returns the current position in the buffer

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp?rev=598078&r1=598077&r2=598078&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.cpp Sun Nov 25 14:57:57
2007
@@ -22,13 +22,62 @@
 using namespace decaf::nio;
 using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
+using namespace decaf::internal::nio;
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteBuffer::ByteBuffer() : Buffer(0) {
+ByteBuffer::ByteBuffer( std::size_t capacity, bool readOnly ) : Buffer( 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;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer::ByteBuffer( unsigned char* array, std::size_t offset,
+                        std::size_t capacity, bool own, bool readOnly )
+    throw( decaf::lang::exceptions::NullPointerException ) : Buffer( capacity ) {
+
+    try{
+
+        // Allocate using the ByteArray, not read-only initially.
+        this->_array = new ByteArrayPerspective( array, capacity, own );
+        this->offset = offset;
+        this->readOnly = readOnly;
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer::ByteBuffer( const ByteBuffer& other )
+ :  Buffer( other.capacity() ),
+    Comparable<ByteBuffer>() {
+
+    // get the byte buffer of the caller and take a reference
+    this->_array = other._array->takeRef();
+    this->offset = other.offset;
+    this->readOnly = other.readOnly;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 ByteBuffer::~ByteBuffer() {
+
+    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()
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -43,7 +92,7 @@
                 "ByteBuffer::allocate - Can't allocate zero sized ByteBuffer" );
         }
 
-        return NULL;
+        return new ByteBuffer( capacity );
     }
     DECAF_CATCH_RETHROW( IllegalArgumentException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalArgumentException )
@@ -62,7 +111,7 @@
                 "ByteBuffer::wrap - Passed Buffer is Null.");
         }
 
-        return NULL;
+        return new ByteBuffer( buffer, offset, length, false );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
@@ -88,6 +137,59 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+unsigned char* ByteBuffer::array()
+    throw( ReadOnlyBufferException, UnsupportedOperationException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "ByteBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::array() - Buffer is Read Only." );
+        }
+
+        return this->_array->getByteArray();
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( ReadOnlyBufferException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteBuffer::arrayOffset() const
+    throw( ReadOnlyBufferException,
+           lang::exceptions::UnsupportedOperationException ) {
+
+    try{
+
+        if( !this->hasArray() ) {
+            throw UnsupportedOperationException(
+                __FILE__, __LINE__,
+                "ByteBuffer::arrayOffset() - This Buffer has no backing array." );
+        }
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::arrayOffset() - Buffer is Read Only." );
+        }
+
+        return this->offset;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( UnsupportedOperationException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( ReadOnlyBufferException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
 ByteBuffer& ByteBuffer::get( std::vector<unsigned char> buffer )
     throw ( BufferUnderflowException ) {
 
@@ -321,4 +423,64 @@
     stream << " position=" << this->position();
     stream << " limit=" << this->limit();
     return stream.str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* ByteBuffer::asReadOnlyBuffer() const {
+
+    try{
+
+        ByteBuffer* buffer = new ByteBuffer( *this );
+        buffer->setReadOnly( true );
+
+        return buffer;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::compact() throw( ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::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( ReadOnlyBufferException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( ReadOnlyBufferException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char ByteBuffer::get() const throw( BufferUnderflowException ) {
+
+    try{
+
+        if( this->position() == this->limit() ) {
+            throw BufferUnderflowException(
+                __FILE__, __LINE__,
+                "ByteBuffer::get - Not enough data to fill request." );
+        }
+
+        return (*(this->_array))[this->offset + this->_position++];
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, ReadOnlyBufferException )
+    DECAF_CATCHALL_THROW( ReadOnlyBufferException )
 }

Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h?rev=598078&r1=598077&r2=598078&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/ByteBuffer.h Sun Nov 25 14:57:57
2007
@@ -25,6 +25,7 @@
 #include <decaf/nio/BufferUnderflowException.h>
 #include <decaf/nio/BufferOverflowException.h>
 #include <decaf/nio/ReadOnlyBufferException.h>
+#include <decaf/internal/nio/ByteArrayPerspective.h>
 
 namespace decaf{
 namespace nio{
@@ -98,11 +99,49 @@
                                  public lang::Comparable<ByteBuffer> {
     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:
 
-        ByteBuffer();
+        /**
+         * Creates a ByteBuffer 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
+         */
+        ByteBuffer( std::size_t capactiy, bool readOnly = false );
+
+        /**
+         * Creates a ByteBuffer 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 own - is this class now the owner of the pointer.
+         * @param readOnly - should this buffer be read-only, default as false
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteBuffer( unsigned char* array, std::size_t offset,
+                    std::size_t capacity, bool own, bool readOnly = false )
+            throw( decaf::lang::exceptions::NullPointerException );
+
+        /**
+         * Create a ByteBuffer 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 ByteBuffer this one is to mirror.
+         * @param readOnly - should this buffer be read-only, default as false
+         */
+        ByteBuffer( const ByteBuffer& other );
+
         virtual ~ByteBuffer();
 
         /**
@@ -113,6 +152,21 @@
     public:
 
         /**
+         * @returns this buffer's capacity.
+         */
+        virtual std::size_t capacity() const {
+            return this->_array->getCapacity() - this->offset;
+        }
+
+        /**
+         * 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;
+        }
+
+        /**
          * Returns the byte array that backs this buffer
          * <p>
          * Modifications to this buffer's content will cause the returned array's
@@ -128,7 +182,7 @@
          */
         unsigned char* array()
             throw( ReadOnlyBufferException,
-                   lang::exceptions::UnsupportedOperationException ) {return NULL;}
+                   lang::exceptions::UnsupportedOperationException );
 
         /**
          * Returns the offset within this buffer's backing array of the first element
@@ -148,16 +202,17 @@
          */
         virtual int arrayOffset() const
             throw( ReadOnlyBufferException,
-                   lang::exceptions::UnsupportedOperationException ) {return 0;}
+                   lang::exceptions::UnsupportedOperationException );
 
         /**
          * Tells whether or not this buffer is backed by an accessible byte array.
          * If this method returns true then the array and arrayOffset methods may safely
-         * be invoked.
+         * 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 false;}
+        virtual bool hasArray() const { return true; }
 
         /**
          * Relative bulk get method.
@@ -268,7 +323,7 @@
          * The new buffer will be read-only if, and only if, this buffer is read-only.
          * @returns the new Char Buffer, which the caller then owns.
          */
-        virtual CharBuffer* asCharBuffer() const = 0;
+        //virtual CharBuffer* asCharBuffer() const = 0;
 
         /**
          * Creates a view of this byte buffer as a double buffer.
@@ -283,7 +338,7 @@
          * buffer is read-only.
          * @returns the new double Buffer, which the caller then owns.
          */
-        virtual DoubleBuffer* asDoubleBuffer() const = 0;
+        //virtual DoubleBuffer* asDoubleBuffer() const = 0;
 
         /**
          * Creates a view of this byte buffer as a float buffer.
@@ -298,7 +353,7 @@
          * buffer is read-only.
          * @returns the new float Buffer, which the caller then owns.
          */
-        virtual FloatBuffer* asFloatBuffer() const = 0;
+        //virtual FloatBuffer* asFloatBuffer() const = 0;
 
         /**
          * Creates a view of this byte buffer as a int buffer.
@@ -313,7 +368,7 @@
          * buffer is read-only.
          * @returns the new int Buffer, which the caller then owns.
          */
-        virtual IntBuffer* asIntBuffer() const = 0;
+        //virtual IntBuffer* asIntBuffer() const = 0;
 
         /**
          * Creates a view of this byte buffer as a long buffer.
@@ -328,7 +383,7 @@
          * buffer is read-only.
          * @returns the new long Buffer, which the caller then owns.
          */
-        virtual LongBuffer* asLongBuffer() const = 0;
+        //virtual LongBuffer* asLongBuffer() const = 0;
 
         /**
          * Creates a view of this byte buffer as a short buffer.
@@ -343,7 +398,7 @@
          * buffer is read-only.
          * @returns the new short Buffer, which the caller then owns.
          */
-        virtual ShortBuffer* asShortBuffer() const = 0;
+        //virtual ShortBuffer* asShortBuffer() const = 0;
 
         /**
          * Creates a new, read-only byte buffer that shares this buffer's content.
@@ -361,7 +416,7 @@
          * identical to those of this buffer.
          * @return The new, read-only byte buffer which the caller then owns.
          */
-        virtual ByteBuffer* asReadOnlyBuffer() const = 0;
+        virtual ByteBuffer* asReadOnlyBuffer() const;
 
         /**
          * Compacts this buffer
@@ -379,7 +434,7 @@
          * @returns a reference to this ByteBuffer
          * @throws ReadOnlyBufferException - If this buffer is read-only
          */
-        virtual ByteBuffer& compact() throw( ReadOnlyBufferException ) = 0;
+        virtual ByteBuffer& compact() throw( ReadOnlyBufferException );
 
         /**
          * Creates a new byte buffer that shares this buffer's content.
@@ -393,7 +448,9 @@
          * this buffer is read-only.
          * @returns a new Byte Buffer which the caller owns.
          */
-        virtual ByteBuffer* duplicate() = 0;
+        virtual ByteBuffer* duplicate() {
+            return new ByteBuffer( *this );
+        }
 
         /**
          * Relative get method. Reads the byte at this buffer's current position, and
@@ -402,7 +459,7 @@
          * @throws BufferUnderflowException - If the buffer's current position is not
          * smaller than its limit
          */
-        virtual unsigned char get() const throw( BufferUnderflowException ) = 0;
+        virtual unsigned char get() const throw( BufferUnderflowException );
 
         /**
          * Writes the given byte into this buffer at the current position, and then
@@ -414,7 +471,7 @@
          * @throws ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& put( unsigned char value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Absolute get method. Reads the byte at the given index.
@@ -424,7 +481,7 @@
          * buffer's limit
          */
         virtual unsigned char get( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
 
         /**
          * Reads the next byte at this buffer's current position, and then increments
@@ -433,7 +490,7 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual char getChar() throw( BufferUnderflowException ) = 0;
+        virtual char getChar() throw( BufferUnderflowException ) { return 0; }
 
         /**
          * Reads one byte at the given index and returns it
@@ -443,7 +500,7 @@
          * buffer's limit
          */
         virtual char getChar( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
 
         /**
          * Reads the next eight bytes at this buffer's current position, and then
@@ -452,7 +509,7 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual double getDouble() throw( BufferUnderflowException ) = 0;
+        virtual double getDouble() throw( BufferUnderflowException ) { return 0; }
 
         /**
          * Reads eight bytes at the given index and returns it
@@ -462,7 +519,7 @@
          * remaining to fill the requested Data Type
          */
         virtual double getDouble( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
 
         /**
          * Reads the next four bytes at this buffer's current position, and then
@@ -471,7 +528,7 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual float getFloat() throw( BufferUnderflowException ) = 0;
+        virtual float getFloat() throw( BufferUnderflowException ) { return 0; }
 
         /**
          * Reads four bytes at the given index and returns it
@@ -481,7 +538,7 @@
          * remaining to fill the requested Data Type
          */
         virtual float getFloat( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
 
         /**
          * Reads the next eight bytes at this buffer's current position, and then
@@ -490,7 +547,7 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual long long getLong() throw( BufferUnderflowException ) = 0;
+        virtual long long getLong() throw( BufferUnderflowException ) { return 0; }
 
         /**
          * Reads eight bytes at the given index and returns it
@@ -500,7 +557,7 @@
          * remaining to fill the requested Data Type
          */
         virtual long long getLong( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
 
         /**
          * Reads the next four bytes at this buffer's current position, and then
@@ -509,7 +566,7 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual int getInt() throw( BufferUnderflowException ) = 0;
+        virtual int getInt() throw( BufferUnderflowException )  { return 0; }
 
         /**
          * Reads four bytes at the given index and returns it
@@ -519,7 +576,7 @@
          * remaining to fill the requested Data Type
          */
         virtual int getInt( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
 
         /**
          * Reads the next two bytes at this buffer's current position, and then
@@ -528,7 +585,7 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual short getShort() throw( BufferUnderflowException ) = 0;
+        virtual short getShort() throw( BufferUnderflowException ) { return 0; }
 
         /**
          * Reads two bytes at the given index and returns it
@@ -538,7 +595,7 @@
          * remaining to fill the requested Data Type
          */
         virtual short getShort( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
+            throw ( lang::exceptions::IndexOutOfBoundsException )  { return 0; }
 
         /**
          * Writes the given byte into this buffer at the given index.
@@ -551,7 +608,7 @@
          */
         virtual ByteBuffer& put( std::size_t index, unsigned char value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes one byte containing the given value, into this buffer at the
@@ -563,7 +620,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putChar( char value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes one byte containing the given value, into this buffer at the
@@ -577,7 +634,7 @@
          */
         virtual ByteBuffer& putChar( std::size_t index, char value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -589,7 +646,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putDouble( double value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -603,7 +660,7 @@
          */
         virtual ByteBuffer& putDouble( std::size_t index, double value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -615,7 +672,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putFloat( float value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -629,7 +686,7 @@
          */
         virtual ByteBuffer& putFloat( std::size_t index, float value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -641,7 +698,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putLong( long long value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -655,7 +712,7 @@
          */
         virtual ByteBuffer& putLong( std::size_t index, long long value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -667,7 +724,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putInt( int value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -681,7 +738,7 @@
          */
         virtual ByteBuffer& putInt( std::size_t index, int value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes two bytes containing the given value, into this buffer at the
@@ -693,7 +750,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putShort( short value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) = 0;
+            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
 
         /**
          * Writes two bytes containing the given value, into this buffer at the
@@ -707,7 +764,7 @@
          */
         virtual ByteBuffer& putShort( std::size_t index, short value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) = 0;
+                   ReadOnlyBufferException ) { return *this; }
 
         /**
          * Creates a new byte buffer whose content is a shared subsequence of this
@@ -722,7 +779,7 @@
          * new buffer will be read-only if, and only if, this buffer is read-only.
          * @returns the newly create ByteBuffer which the caller owns.
          */
-        virtual ByteBuffer* slice() const = 0;
+        virtual ByteBuffer* slice() const  { return 0; }
 
     public:  // Comparable
 
@@ -797,6 +854,16 @@
          * @returns a new ByteBuffer that is backed by buffer, caller owns.
          */
         static ByteBuffer* wrap( std::vector<unsigned char>& buffer );
+
+    protected:
+
+        /**
+         * Sets this ByteBuffer as Read-Only.
+         * @param value - true if this buffer is to be read-only.
+         */
+        virtual void setReadOnly( bool value ) {
+            this->readOnly = value;
+        }
 
     };
 



Mime
View raw message