[prev in list] [next in list] [prev in thread] [next in thread]
List: activemq-commits
Subject: svn commit: r599958 - in
From: tabish () apache ! org
Date: 2007-11-30 21:01:15
Message-ID: 20071130210116.5D0FE1A9832 () eris ! apache ! org
[Download RAW message or body]
Author: tabish
Date: Fri Nov 30 13:01:13 2007
New Revision: 599958
URL: http://svn.apache.org/viewvc?rev=599958&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/ByteBuffer.cpp
activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp
activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h
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=599958&r1=599957&r2=599958&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 Fri Nov 30 \
13:01:13 2007 @@ -224,12 +224,10 @@
try{
- if( buffer.empty() ) {
- return *this;
+ if( !buffer.empty() ) {
+ this->get( &buffer[0], 0, buffer.size() );
}
- this->get( &buffer[0], 0, buffer.size() );
-
return *this;
}
DECAF_CATCH_RETHROW( BufferUnderflowException )
@@ -361,11 +359,9 @@
try{
- if( buffer.empty() ) {
- return *this;
+ if( !buffer.empty() ) {
+ this->put( &buffer[0], 0, buffer.size() );
}
-
- this->put( &buffer[0], 0, buffer.size() );
return *this;
}
Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp?rev=599958&r1=599957&r2=599958&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.cpp Fri Nov 30 \
13:01:13 2007 @@ -16,11 +16,8 @@
*/
#include "CharBuffer.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"
+#include <decaf/lang/Character.h>
+#include <decaf/lang/Math.h>
using namespace std;
using namespace decaf;
@@ -37,21 +34,47 @@
////////////////////////////////////////////////////////////////////////////////
std::string CharBuffer::toString() const {
- return ""; //TODO
+ std::string strbuf;
+
+ for( std::size_t i = this->position(); i < this->limit(); i++ ) {
+ strbuf.append( Character::valueOf( get( i ) ).toString() );
+ }
+
+ return strbuf;
}
////////////////////////////////////////////////////////////////////////////////
CharBuffer& CharBuffer::append( char value )
throw ( BufferOverflowException, ReadOnlyBufferException ) {
- return *this; //TODO
+ try{
+
+ this->put( value );
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
CharBuffer& CharBuffer::append( const CharSequence* value )
throw ( BufferOverflowException, ReadOnlyBufferException ) {
- return *this; //TODO
+ try{
+
+ if( value != NULL ) {
+ return this->put( value->toString() );
+ }
+
+ return this->put( "null" );
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -59,21 +82,51 @@
throw ( decaf::lang::exceptions::IndexOutOfBoundsException,
BufferOverflowException, ReadOnlyBufferException ) {
- return *this; //TODO
+ try{
+
+ if( value != NULL ) {
+ CharSequence* temp = value->subSequence( start, end );
+ this->append( temp );
+ delete temp;
+
+ return *this;
+ }
+
+ return this->put( "null" );
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
char CharBuffer::charAt( std::size_t index )
throw( decaf::lang::exceptions::IndexOutOfBoundsException ) {
- return (char)index; // TODO
+ try{
+
+ return this->get( index );
+ }
+ DECAF_CATCH_RETHROW( IndexOutOfBoundsException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IndexOutOfBoundsException )
+ DECAF_CATCHALL_THROW( IndexOutOfBoundsException )
}
////////////////////////////////////////////////////////////////////////////////
CharBuffer& CharBuffer::get( std::vector<char> buffer )
throw ( BufferUnderflowException ) {
- return *this; //TODO
+ try{
+
+ if( !buffer.empty() ) {
+ this->get( &buffer[0], 0, buffer.size() );
+ }
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+ DECAF_CATCHALL_THROW( BufferUnderflowException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -81,7 +134,33 @@
throw( BufferUnderflowException,
lang::exceptions::NullPointerException ) {
- return *this; //TODO
+ try{
+
+ if( length == 0 ) {
+ return *this;
+ }
+
+ if( buffer == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__,
+ "CharBuffer::get - Passed Buffer is Null" );
+ }
+
+ if( length > remaining() ) {
+ throw BufferUnderflowException(
+ __FILE__, __LINE__,
+ "CharBuffer::get - Not enough data to fill length = %d", length );
+ }
+
+ for( std::size_t ix = 0; ix < length; ++ix ){
+ buffer[offset + ix] = this->get();
+ }
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferUnderflowException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferUnderflowException )
+ DECAF_CATCHALL_THROW( BufferUnderflowException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -89,7 +168,37 @@
throw( BufferOverflowException, ReadOnlyBufferException,
lang::exceptions::IllegalArgumentException ) {
- return *this; //TODO
+ try{
+
+ if( this == &src ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - Can't put Self" );
+ }
+
+ if( this->isReadOnly() ) {
+ throw ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - This buffer is Read Only.");
+ }
+
+ if( src.remaining() > this->remaining() ) {
+ throw BufferOverflowException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - Not enough space remaining to put src." );
+ }
+
+ while( src.hasRemaining() ) {
+ this->put( src.get() );
+ }
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( IllegalArgumentException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -97,14 +206,60 @@
throw( BufferOverflowException, ReadOnlyBufferException,
lang::exceptions::NullPointerException ) {
- return *this; //TODO
+ try{
+
+ if( length == 0 ) {
+ return *this;
+ }
+
+ if( this->isReadOnly() ) {
+ throw ReadOnlyBufferException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - This buffer is Read Only.");
+ }
+
+ if( buffer == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - Passed Buffer is Null.");
+ }
+
+ if( length > this->remaining() ) {
+ throw BufferOverflowException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - Not Enough space to store requested Data.");
+ }
+
+ // read length bytes starting from the offset
+ for( std::size_t ix = 0; ix < length; ++ix ) {
+ this->put( buffer[ix + offset] );
+ }
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_RETHROW( NullPointerException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
CharBuffer& CharBuffer::put( std::vector<char>& buffer )
throw( BufferOverflowException, ReadOnlyBufferException ) {
- return *this; //TODO
+ try{
+
+ if( !buffer.empty() ) {
+ this->put( &buffer[0], 0, buffer.size() );
+ }
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
@@ -112,33 +267,127 @@
throw( BufferOverflowException, ReadOnlyBufferException,
decaf::lang::exceptions::IndexOutOfBoundsException ) {
- return *this; //TODO
+ try{
+
+ if( ( start > end ) || ( src.size() < ( end - start ) ) ) {
+ throw IndexOutOfBoundsException(
+ __FILE__, __LINE__,
+ "CharBuffer::put - invalid start and end pos; start = %d, end = %d",
+ start, end );
+ }
+
+ this->put( src.substr( start, end-start ) );
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
CharBuffer& CharBuffer::put( const std::string src )
throw( BufferOverflowException, ReadOnlyBufferException ) {
- return *this; //TODO
+ try{
+
+ if( !src.empty() ) {
+ this->put( src.c_str(), 0, src.size() );
+ }
+
+ return *this;
+ }
+ DECAF_CATCH_RETHROW( BufferOverflowException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, BufferOverflowException )
+ DECAF_CATCHALL_THROW( BufferOverflowException )
}
////////////////////////////////////////////////////////////////////////////////
std::size_t CharBuffer::read( CharBuffer* target )
throw ( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IllegalArgumentException,
ReadOnlyBufferException ) {
- return string::npos; //TODO
+ try{
+
+ if( target == this ) {
+ throw IllegalArgumentException(
+ __FILE__, __LINE__,
+ "CharBuffer::read - Cannot read to self" );
+ }
+
+ if( target == NULL ) {
+ throw NullPointerException(
+ __FILE__, __LINE__,
+ "CharBuffer::read - Null CharBuffer Passed" );
+ }
+
+ if( this->remaining() == 0 ) {
+ return target->remaining() == 0 ? 0 : string::npos;
+ }
+
+ std::size_t result = Math::min( target->remaining(), this->remaining() );
+ char* chars = new char[result];
+ get( chars, 0, result );
+ target->put( chars, 0, result );
+
+ return result;
+ }
+ DECAF_CATCH_RETHROW( NullPointerException )
+ DECAF_CATCH_RETHROW( IllegalArgumentException )
+ DECAF_CATCH_RETHROW( ReadOnlyBufferException )
+ DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalArgumentException )
+ DECAF_CATCHALL_THROW( IllegalArgumentException )
}
////////////////////////////////////////////////////////////////////////////////
int CharBuffer::compareTo( const CharBuffer& value ) const {
- return 0; //TODO
+ int compareRemaining = Math::min( remaining(), value.remaining() );
+
+ std::size_t thisPos = this->position();
+ std::size_t otherPos = value.position();
+ char thisByte, otherByte;
+
+ while( compareRemaining > 0 ) {
+
+ thisByte = get( thisPos );
+ otherByte = value.get( otherPos );
+
+ if( thisByte != otherByte ) {
+ return thisByte < otherByte ? -1 : 1;
+ }
+
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+
+ return remaining() - value.remaining();
}
////////////////////////////////////////////////////////////////////////////////
bool CharBuffer::equals( const CharBuffer& value ) const {
- return false; //TODO
+
+ if( &value == this ) {
+ return true;
+ }
+
+ if( this->remaining() != value.remaining() ) {
+ return false;
+ }
+
+ std::size_t myPosition = this->position();
+ std::size_t otherPosition = value.position();
+ bool equalSoFar = true;
+
+ while( equalSoFar && ( myPosition < this->limit() ) ) {
+ equalSoFar = get( myPosition++ ) == value.get( otherPosition++ );
+ }
+
+ return equalSoFar;
}
////////////////////////////////////////////////////////////////////////////////
Modified: activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h?rev=599958&r1=599957&r2=599958&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/nio/CharBuffer.h Fri Nov 30 \
13:01:13 2007 @@ -410,10 +410,12 @@
* @returns The number of characters added to the buffer, or string::npos if \
this
* source of characters is at its end
* @throws NullPointerException - If target is Null
+ * @throws IllegalArgumentException - If target is this
* @throws ReadOnlyBufferException - If this buffer is read-only
*/
virtual std::size_t read( CharBuffer* target )
throw ( decaf::lang::exceptions::NullPointerException,
+ decaf::lang::exceptions::IllegalArgumentException,
ReadOnlyBufferException );
/**
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic