activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r598479 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio: Buffer.h ByteBuffer.cpp ByteBuffer.h
Date Tue, 27 Nov 2007 00:44:11 GMT
Author: tabish
Date: Mon Nov 26 16:44:10 2007
New Revision: 598479

URL: http://svn.apache.org/viewvc?rev=598479&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.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.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.h?rev=598479&r1=598478&r2=598479&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 Mon Nov 26 16:44:10 2007
@@ -170,8 +170,8 @@
          * Sets this buffer's limit. If the position is larger than the new limit then
          * it is set to the new limit. If the mark is defined and larger than the new
          * limit then it is discarded.
-         * @param newLimit - The new limit value; must be non-negative and no larger
-         * than this buffer's capacity
+         * @param newLimit - The new limit value; must be no larger than this
+         * buffer's capacity
          * @returns A reference to This buffer
          * @throws IllegalArgumentException if preconditions on the new pos don't hold.
          */

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=598479&r1=598478&r2=598479&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 Mon Nov 26 16:44:10
2007
@@ -16,6 +16,11 @@
  */
 
 #include "ByteBuffer.h"
+#include "decaf/lang/Short.h"
+#include "decaf/lang/Integer.h"
+#include "decaf/lang/Long.h"
+#include "decaf/lang/Float.h"
+#include "decaf/lang/Double.h"
 
 using namespace std;
 using namespace decaf;
@@ -51,6 +56,29 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+ByteBuffer::ByteBuffer( ByteArrayPerspective& array, std::size_t offset, bool readOnly
)
+    throw( decaf::lang::exceptions::IndexOutOfBoundsException )
+ :  Buffer( array.getCapacity() - offset ) {
+
+    try{
+        if( offset > array.getCapacity() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteBuffer::ByteBuffer - 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 )
+}
+
+////////////////////////////////////////////////////////////////////////////////
 ByteBuffer::ByteBuffer( const ByteBuffer& other )
  :  Buffer( other.capacity() ),
     Comparable<ByteBuffer>() {
@@ -81,7 +109,7 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-static ByteBuffer* allocate( std::size_t capacity )
+ByteBuffer* ByteBuffer::allocate( std::size_t capacity )
     throw( lang::exceptions::IllegalArgumentException ) {
 
     try{
@@ -472,15 +500,496 @@
 
     try{
 
-        if( this->position() == this->limit() ) {
-            throw BufferUnderflowException(
+        return this->get( this->_position++ );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+unsigned char ByteBuffer::get( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( (offset + index) > this->limit() ) {
+            throw IndexOutOfBoundsException(
                 __FILE__, __LINE__,
                 "ByteBuffer::get - Not enough data to fill request." );
         }
 
-        return (*(this->_array))[this->offset + this->_position++];
+        return (*(this->_array))[offset + index];
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double ByteBuffer::getDouble() throw( BufferUnderflowException ) {
+
+    try{
+
+        unsigned long long lvalue = this->getLong();
+        return Double::longBitsToDouble( lvalue );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+double ByteBuffer::getDouble( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        unsigned long long lvalue = this->getLong( index );
+        return Double::longBitsToDouble( lvalue );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float ByteBuffer::getFloat() throw( BufferUnderflowException ) {
+    return 0;
+
+    try{
+
+        unsigned int ivalue = this->getInt();
+        return Float::intBitsToFloat( ivalue );
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+float ByteBuffer::getFloat( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        unsigned int ivalue = this->getInt( index );
+        return Float::intBitsToFloat( ivalue );
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ByteBuffer::getLong() throw( BufferUnderflowException ) {
+
+    try{
+
+        long long value = this->getLong( this->_position );
+        this->_position += sizeof(value);
+        return value;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+long long ByteBuffer::getLong( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( (offset + index + sizeof(long long)) > this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteBuffer::getLong(i) - Not enough data to fill a long long." );
+        }
+
+        unsigned long long value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        this->_array->read( buffer, offset+index, sizeof(value) );
+
+        // Have to do it this way because on Solaris and Cygwin we get all
+        // kinds of warnings when shifting a byte up into a long long.
+        unsigned long long byte1 = buffer[0] & 0x00000000000000FFULL;
+        unsigned long long byte2 = buffer[1] & 0x00000000000000FFULL;
+        unsigned long long byte3 = buffer[2] & 0x00000000000000FFULL;
+        unsigned long long byte4 = buffer[3] & 0x00000000000000FFULL;
+        unsigned long long byte5 = buffer[4] & 0x00000000000000FFULL;
+        unsigned long long byte6 = buffer[5] & 0x00000000000000FFULL;
+        unsigned long long byte7 = buffer[6] & 0x00000000000000FFULL;
+        unsigned long long byte8 = buffer[7] & 0x00000000000000FFULL;
+
+        value = ( byte1 << 56 | byte2 << 48 | byte3 << 40 | byte4 <<
32 |
+                  byte5 << 24 | byte6 << 16 | byte7 << 8  | byte8 <<
0 );
+
+        return value;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteBuffer::getInt() throw( BufferUnderflowException )  {
+
+    try{
+
+        int value = this->getInt( this->_position );
+        this->_position += sizeof(value);
+        return value;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+int ByteBuffer::getInt( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+    try{
+
+        if( (offset + index + sizeof(int)) > this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteBuffer::getInt(i) - Not enough data to fill an int." );
+        }
+
+        unsigned int value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        this->_array->read( buffer, offset+index, sizeof(value) );
+        value |= (buffer[0] << 24 | buffer[1] << 16 |
+                  buffer[2] << 8 | buffer[3] << 0);
+
+        return value;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short ByteBuffer::getShort() throw( BufferUnderflowException ) {
+
+    try{
+
+        short value = this->getShort( this->_position );
+        this->_position += sizeof(value);
+        return value;
+    }
+    DECAF_CATCH_RETHROW( BufferUnderflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+    DECAF_CATCHALL_THROW( BufferUnderflowException );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+short ByteBuffer::getShort( std::size_t index ) const
+    throw ( lang::exceptions::IndexOutOfBoundsException )  {
+
+    try{
+
+        if( (offset + index + sizeof(short)) > this->limit() ) {
+            throw IndexOutOfBoundsException(
+                __FILE__, __LINE__,
+                "ByteBuffer::getShort(i) - Not enough data to fill a short." );
+        }
+
+        short value = 0;
+        unsigned char buffer[sizeof(value)] = {0};
+        this->_array->read( buffer, offset+index, sizeof(value) );
+        value |= (buffer[0] << 8 | buffer[1] << 0);
+
+        return value;
+    }
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::put( unsigned char value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->put( this->_position++, value );
+        return *this;
     }
     DECAF_CATCH_RETHROW( ReadOnlyBufferException )
-    DECAF_CATCH_EXCEPTION_CONVERT( Exception, ReadOnlyBufferException )
-    DECAF_CATCHALL_THROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::put( std::size_t index, unsigned char value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::put() - Buffer is Read Only." );
+        }
+
+        (*(this->_array))[this->offset + index] = value;
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putChar( char value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->put( this->_position++, value );
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putChar( std::size_t index, char value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        this->put( index, value );
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putDouble( double value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->putDouble( this->_position, value );
+        this->_position += sizeof(value);
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putDouble( std::size_t index, double value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        this->putLong( index, Double::doubleToLongBits( value ) );
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putFloat( float value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->putFloat( this->_position, value );
+        this->_position += sizeof(value);
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putFloat( std::size_t index, float value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        this->putInt( index, Float::floatToIntBits( value ) );
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putLong( long long value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->putLong( this->_position, value );
+        this->_position += sizeof(value);
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putLong( std::size_t index, long long value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::putLong() - Buffer is Read Only." );
+        }
+
+        unsigned char buffer[sizeof(value)];
+
+        buffer[0] = (unsigned char)((value & 0xFF00000000000000ULL) >> 56);
+        buffer[1] = (unsigned char)((value & 0x00FF000000000000ULL) >> 48);
+        buffer[2] = (unsigned char)((value & 0x0000FF0000000000ULL) >> 40);
+        buffer[3] = (unsigned char)((value & 0x000000FF00000000ULL) >> 32);
+        buffer[4] = (unsigned char)((value & 0x00000000FF000000ULL) >> 24);
+        buffer[5] = (unsigned char)((value & 0x0000000000FF0000ULL) >> 16);
+        buffer[6] = (unsigned char)((value & 0x000000000000FF00ULL) >> 8);
+        buffer[7] = (unsigned char)((value & 0x00000000000000FFULL) >> 0);
+
+        this->_array->write( buffer, offset+index, sizeof(value) );
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putInt( int value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->putInt( this->_position, value );
+        this->_position += sizeof(value);
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putInt( std::size_t index, int value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::putInt() - Buffer is Read Only." );
+        }
+
+        unsigned char buffer[sizeof(value)];
+
+        buffer[0] = (value & 0xFF000000) >> 24;
+        buffer[1] = (value & 0x00FF0000) >> 16;
+        buffer[2] = (value & 0x0000FF00) >> 8;
+        buffer[3] = (value & 0x000000FF) >> 0;
+
+        this->_array->write( buffer, offset+index, sizeof(value) );
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putShort( short value )
+    throw( BufferOverflowException, ReadOnlyBufferException ) {
+
+    try{
+
+        this->putShort( this->_position, value );
+        this->_position += sizeof(value);
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( BufferOverflowException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+    DECAF_CATCHALL_THROW( BufferOverflowException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer& ByteBuffer::putShort( std::size_t index, short value )
+    throw( lang::exceptions::IndexOutOfBoundsException,
+           ReadOnlyBufferException ) {
+
+    try{
+
+        if( this->isReadOnly() ) {
+            throw ReadOnlyBufferException(
+                __FILE__, __LINE__,
+                "ByteBuffer::putShort() - Buffer is Read Only." );
+        }
+
+        unsigned char buffer[sizeof(value)];
+
+        buffer[0] = (value & 0xFF00) >> 8;
+        buffer[1] = (value & 0x00FF) >> 0;
+
+        this->_array->write( buffer, offset+index, sizeof(value) );
+
+        return *this;
+    }
+    DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+    DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+    DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* ByteBuffer::slice() const {
+
+    try{
+        return new ByteBuffer( *(this->_array),
+                               this->offset + this->position(),
+                               this->isReadOnly() );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
 }

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=598479&r1=598478&r2=598479&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 Mon Nov 26 16:44:10
2007
@@ -97,7 +97,7 @@
      */
     class DECAF_API ByteBuffer : public Buffer,
                                  public lang::Comparable<ByteBuffer> {
-    protected:
+    private:
 
         // Read / Write flag
         bool readOnly;
@@ -134,6 +134,20 @@
             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 ByteBuffer
+         * 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 readOnly - is this a readOnly buffer.
+         * @throws NullPointerException if buffer is NULL
+         * @throws IndexOutOfBoundsException if offset is greater than array capacity.
+         */
+        ByteBuffer( internal::nio::ByteArrayPerspective& array,
+                    std::size_t offset, bool readOnly = false )
+            throw( decaf::lang::exceptions::IndexOutOfBoundsException );
+
+        /**
          * 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.
@@ -462,18 +476,6 @@
         virtual unsigned char get() const throw( BufferUnderflowException );
 
         /**
-         * Writes the given byte into this buffer at the current position, and then
-         * increments the position.
-         * @param value - the byte 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 ByteBuffer& put( unsigned char value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
-
-        /**
          * Absolute get method. Reads the byte at the given index.
          * @param index - the index in the Buffer where the byte is to be read
          * @returns the byte that is located at the given index
@@ -481,7 +483,7 @@
          * buffer's limit
          */
         virtual unsigned char get( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Reads the next byte at this buffer's current position, and then increments
@@ -490,7 +492,9 @@
          * @throws BufferUnderflowException - If there are no more bytes remaining in
          * this buffer, meaning we have reached the set limit.
          */
-        virtual char getChar() throw( BufferUnderflowException ) { return 0; }
+        virtual char getChar() throw( BufferUnderflowException ) {
+            return (char)this->get();
+        }
 
         /**
          * Reads one byte at the given index and returns it
@@ -500,7 +504,10 @@
          * buffer's limit
          */
         virtual char getChar( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+            return (char)this->get( index );
+        }
 
         /**
          * Reads the next eight bytes at this buffer's current position, and then
@@ -509,7 +516,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 ) { return 0; }
+        virtual double getDouble() throw( BufferUnderflowException );
 
         /**
          * Reads eight bytes at the given index and returns it
@@ -519,7 +526,7 @@
          * remaining to fill the requested Data Type
          */
         virtual double getDouble( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Reads the next four bytes at this buffer's current position, and then
@@ -528,7 +535,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 ) { return 0; }
+        virtual float getFloat() throw( BufferUnderflowException );
 
         /**
          * Reads four bytes at the given index and returns it
@@ -538,7 +545,7 @@
          * remaining to fill the requested Data Type
          */
         virtual float getFloat( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Reads the next eight bytes at this buffer's current position, and then
@@ -547,7 +554,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 ) { return 0; }
+        virtual long long getLong() throw( BufferUnderflowException );
 
         /**
          * Reads eight bytes at the given index and returns it
@@ -557,7 +564,7 @@
          * remaining to fill the requested Data Type
          */
         virtual long long getLong( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Reads the next four bytes at this buffer's current position, and then
@@ -566,7 +573,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 )  { return 0; }
+        virtual int getInt() throw( BufferUnderflowException );
 
         /**
          * Reads four bytes at the given index and returns it
@@ -576,7 +583,7 @@
          * remaining to fill the requested Data Type
          */
         virtual int getInt( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException ) { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException );
 
         /**
          * Reads the next two bytes at this buffer's current position, and then
@@ -585,7 +592,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 ) { return 0; }
+        virtual short getShort() throw( BufferUnderflowException );
 
         /**
          * Reads two bytes at the given index and returns it
@@ -595,7 +602,19 @@
          * remaining to fill the requested Data Type
          */
         virtual short getShort( std::size_t index ) const
-            throw ( lang::exceptions::IndexOutOfBoundsException )  { return 0; }
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes the given byte into this buffer at the current position, and then
+         * increments the position.
+         * @param value - the byte 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 ByteBuffer& put( unsigned char value )
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes the given byte into this buffer at the given index.
@@ -608,7 +627,7 @@
          */
         virtual ByteBuffer& put( std::size_t index, unsigned char value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Writes one byte containing the given value, into this buffer at the
@@ -620,7 +639,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putChar( char value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes one byte containing the given value, into this buffer at the
@@ -634,7 +653,7 @@
          */
         virtual ByteBuffer& putChar( std::size_t index, char value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -646,7 +665,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putDouble( double value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -660,7 +679,7 @@
          */
         virtual ByteBuffer& putDouble( std::size_t index, double value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -672,7 +691,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putFloat( float value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -686,7 +705,7 @@
          */
         virtual ByteBuffer& putFloat( std::size_t index, float value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -698,7 +717,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putLong( long long value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes eight bytes containing the given value, into this buffer at the
@@ -712,7 +731,7 @@
          */
         virtual ByteBuffer& putLong( std::size_t index, long long value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -724,7 +743,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putInt( int value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes four bytes containing the given value, into this buffer at the
@@ -738,7 +757,7 @@
          */
         virtual ByteBuffer& putInt( std::size_t index, int value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Writes two bytes containing the given value, into this buffer at the
@@ -750,7 +769,7 @@
          * @throw ReadOnlyBufferException - If this buffer is read-only
          */
         virtual ByteBuffer& putShort( short value )
-            throw( BufferOverflowException, ReadOnlyBufferException ) { return *this; }
+            throw( BufferOverflowException, ReadOnlyBufferException );
 
         /**
          * Writes two bytes containing the given value, into this buffer at the
@@ -764,11 +783,10 @@
          */
         virtual ByteBuffer& putShort( std::size_t index, short value )
             throw( lang::exceptions::IndexOutOfBoundsException,
-                   ReadOnlyBufferException ) { return *this; }
+                   ReadOnlyBufferException );
 
         /**
          * Creates a new byte buffer whose content is a shared subsequence of this
-         * <p>
          * 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
@@ -779,7 +797,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  { return 0; }
+        virtual ByteBuffer* slice() const;
 
     public:  // Comparable
 



Mime
View raw message