activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r594306 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio: Buffer.cpp Buffer.h
Date Mon, 12 Nov 2007 21:32:13 GMT
Author: tabish
Date: Mon Nov 12 13:32:13 2007
New Revision: 594306

URL: http://svn.apache.org/viewvc?rev=594306&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.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/Buffer.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=594306&r1=594305&r2=594306&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 Mon Nov 12 13:32:13 2007
@@ -17,11 +17,16 @@
 
 #include "Buffer.h"
 
+#include <decaf/lang/exception/IllegalArgumentException.h>
+
 using namespace decaf;
 using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
 
 ////////////////////////////////////////////////////////////////////////////////
-Buffer::Buffer() {
+Buffer::Buffer( std::size_t capacity ) {
+    this->capacity = this->limit = capacity;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -32,11 +37,39 @@
 Buffer& Buffer::position( int newPosition )
     throw( lang::exceptions::IllegalArgumentException ) {
 
+    if( newPosition > this->limit ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__,
+            "Buffer::position - New Position is greater than set limit" );
+    }
+
+    this->position = newPosition;
+    if( this->markSet && ( this->mark > newPosition ) ) {
+        this->mark = 0;
+        this->markSet = false;
+    }
+
     return *this;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-virtual Buffer& Buffer::limit( int newLimit ) throw( IllegalArgumentException ) {
+virtual Buffer& Buffer::limit( std::size_t newLimit ) throw( IllegalArgumentException
) {
+
+    if( newLimit > capacity ) {
+        throw IllegalArgumentException(
+            __FILE__, __LINE__,
+            "Buffer::limit - new limit is larger than the capacity." );
+    }
+
+    this->limit = newLimit;
+    if( this->position > newLimit ) {
+        this->position = newLimit;
+    }
+
+    if( this->markSet && ( this->mark > newLimit ) ) {
+        this->mark = 0;
+        this->markSet = false;
+    }
 
     return *this;
 }
@@ -44,24 +77,43 @@
 ////////////////////////////////////////////////////////////////////////////////
 virtual Buffer& Buffer::mark() {
 
+    this->mark = this->position;
+    this->mark = true;
+
     return *this;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 virtual Buffer& Buffer::reset() throw ( InvalidMarkException ) {
 
+    if( !this->markSet ) {
+        throw new InvalidMarkException(
+            __FILE__, __LINE__,
+            "Buffer::reset - Buffer has not been Marked." );
+    }
+
+    this->position = this->mark;
+
     return *this;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 virtual Buffer& Buffer::clear() {
 
+    this->position = 0;
+    this->mark = 0;
+    this->markSet = false;
+    this->limit = this->capacity;
     return *this;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 virtual Buffer& Buffer::flip() {
 
+    this->limit = this->position;
+    this->position = 0;
+    this->mark = 0;
+    this->markSet = false;
     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=594306&r1=594305&r2=594306&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 12 13:32:13 2007
@@ -124,14 +124,15 @@
     class DECAF_API Buffer {
     private:
 
-        int capacity;
-        int position;
-        int limit;
-        int mark;
+        std::size_t capacity;
+        std::size_t position;
+        std::size_t limit;
+        std::size_t mark;
+        bool markSet;
 
     public:
 
-        Buffer();
+        Buffer( std::size_t capacity );
         virtual ~Buffer();
 
     public:



Mime
View raw message