activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r594887 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio: Buffer.h ByteBuffer.cpp ByteBuffer.h
Date Wed, 14 Nov 2007 14:03:14 GMT
Author: tabish
Date: Wed Nov 14 06:03:12 2007
New Revision: 594887

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

Starting the NIO implementation

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=594887&r1=594886&r2=594887&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 Wed Nov 14 06:03:12 2007
@@ -148,7 +148,7 @@
         /**
          * @returns the current position in the buffer
          */
-        virtual std::size_t postion() const {
+        virtual std::size_t position() const {
             return this->_position;
         }
 

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=594887&r1=594886&r2=594887&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 Wed Nov 14 06:03:12
2007
@@ -245,3 +245,69 @@
     DECAF_CATCHALL_THROW( BufferUnderflowException )
 }
 
+////////////////////////////////////////////////////////////////////////////////
+int ByteBuffer::compareTo( const ByteBuffer& value ) const {
+
+    try{
+
+        std::size_t compareRemaining =
+            ( remaining() < value.remaining() ) ?
+                remaining() : value.remaining();
+
+        std::size_t thisPos = this->position();
+        std::size_t otherPos = value.position();
+
+        unsigned char thisByte, otherByte = 0;
+
+        while( compareRemaining > 0 ) {
+            thisByte = this->get( thisPos );
+            otherByte = value.get( otherPos );
+
+            if( thisByte != otherByte ) {
+                return thisByte < otherByte ? -1 : 1;
+            }
+
+            thisPos++;
+            otherPos++;
+            compareRemaining--;
+        }
+
+        return (int)( remaining() - value.remaining() );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ByteBuffer::equals( const ByteBuffer& value ) const {
+
+    try{
+
+        if( this->remaining() != value.remaining()) {
+            return false;
+        }
+
+        std::size_t myPosition = this->position();
+        std::size_t otherPosition = value.position();
+
+        while( myPosition < this->limit() ) {
+            if( get( myPosition++ ) != value.get( otherPosition++ ) ) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ByteBuffer::operator==( const ByteBuffer& value ) const {
+    return this->equals( value );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+bool ByteBuffer::operator<( const ByteBuffer& value ) const {
+    return this->compareTo( value ) == -1;
+}

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=594887&r1=594886&r2=594887&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 Wed Nov 14 06:03:12
2007
@@ -94,7 +94,8 @@
      *   buffer of the same type; and
      *
      */
-    class DECAF_API ByteBuffer : public Buffer {
+    class DECAF_API ByteBuffer : public Buffer,
+                                 public lang::Comparable<ByteBuffer> {
     protected:
 
         bool readOnly;
@@ -396,7 +397,7 @@
          * @throws BufferUnderflowException - If the buffer's current position is not
          * smaller than its limit
          */
-        virtual unsigned char get() throw( BufferUnderflowException ) = 0;
+        virtual unsigned char get() const throw( BufferUnderflowException ) = 0;
 
         /**
          * Writes the given byte into this buffer at the current position, and then
@@ -417,7 +418,7 @@
          * @throws IndexOutOfBoundsException - If index is not smaller than the
          * buffer's limit
          */
-        virtual unsigned char get( std::size_t index )
+        virtual unsigned char get( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -436,7 +437,7 @@
          * @throws IndexOutOfBoundsException - If index is not smaller than the
          * buffer's limit
          */
-        virtual char getChar( std::size_t index )
+        virtual char getChar( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -455,7 +456,7 @@
          * @throws IndexOutOfBoundsException - If there are not enough bytes
          * remaining to fill the requested Data Type
          */
-        virtual double getDouble( std::size_t index )
+        virtual double getDouble( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -474,7 +475,7 @@
          * @throws IndexOutOfBoundsException - If there are not enough bytes
          * remaining to fill the requested Data Type
          */
-        virtual float getFloat( std::size_t index )
+        virtual float getFloat( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -493,7 +494,7 @@
          * @throws IndexOutOfBoundsException - If there are not enough bytes
          * remaining to fill the requested Data Type
          */
-        virtual long long getLong( std::size_t index )
+        virtual long long getLong( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -512,7 +513,7 @@
          * @throws IndexOutOfBoundsException - If there are not enough bytes
          * remaining to fill the requested Data Type
          */
-        virtual int getInt( std::size_t index )
+        virtual int getInt( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -531,7 +532,7 @@
          * @throws IndexOutOfBoundsException - If there are not enough bytes
          * remaining to fill the requested Data Type
          */
-        virtual short getShort( std::size_t index )
+        virtual short getShort( std::size_t index ) const
             throw ( lang::exceptions::IndexOutOfBoundsException ) = 0;
 
         /**
@@ -717,6 +718,38 @@
          * @returns the newly create ByteBuffer which the caller owns.
          */
         virtual ByteBuffer* slice() const = 0;
+
+    public:  // Comparable
+
+        /**
+         * Compares this object with the specified object for order. Returns a
+         * negative integer, zero, or a positive integer as this object is less
+         * than, equal to, or greater than the specified object.
+         * @param value - the Object to be compared.
+         * @returns a negative integer, zero, or a positive integer as this
+         * object is less than, equal to, or greater than the specified object.
+         */
+        virtual int compareTo( const ByteBuffer& value ) const;
+
+        /**
+         * @return true if this value is considered equal to the passed value.
+         */
+        virtual bool equals( const ByteBuffer& value ) const;
+
+        /**
+         * Compares equality between this object and the one passed.
+         * @param value - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator==( const ByteBuffer& value ) const;
+
+        /**
+         * Compares this object to another and returns true if this object
+         * is considered to be less than the one passed.  This
+         * @param value - the value to be compared to this one.
+         * @return true if this object is equal to the one passed.
+         */
+        virtual bool operator<( const ByteBuffer& value ) const;
 
     public:
 



Mime
View raw message