activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r600402 [1/2] - in /activemq/activemq-cpp/decaf/trunk/src/main: ./ decaf/internal/nio/ decaf/nio/
Date Sun, 02 Dec 2007 22:58:25 GMT
Author: tabish
Date: Sun Dec  2 14:58:25 2007
New Revision: 600402

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

Implementing the NIO Package.

Added:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp
      - copied, changed from r600350, activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h
      - copied, changed from r600350, activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.h
Removed:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.h
Modified:
    activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am
    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/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am?rev=600402&r1=600401&r2=600402&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/Makefile.am Sun Dec  2 14:58:25 2007
@@ -24,8 +24,9 @@
    decaf/internal/util/FloatingPointParser.cpp \
    decaf/internal/util/HexStringParser.cpp \
    decaf/internal/util/ByteArray.cpp \
+   decaf/internal/nio/BufferFactory.cpp \
    decaf/internal/nio/ByteArrayPerspective.cpp \
-   decaf/internal/nio/ByteBuffer.cpp \
+   decaf/internal/nio/ByteArrayBuffer.cpp \
    decaf/net/ServerSocket.cpp \
    decaf/net/SocketOutputStream.cpp \
    decaf/net/BufferedSocket.cpp \
@@ -195,8 +196,9 @@
    decaf/internal/util/BitOps.h \
    decaf/internal/util/BigInt.h \
    decaf/internal/util/ByteArray.h \
+   decaf/internal/nio/BufferFactory.h \
    decaf/internal/nio/ByteArrayPerspective.h \
-   decaf/internal/nio/ByteBuffer.h \
+   decaf/internal/nio/ByteArrayBuffer.h \
    decaf/nio/Buffer.h \
    decaf/nio/ByteBuffer.h \
    decaf/nio/CharBuffer.h \

Added: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp?rev=600402&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp (added)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.cpp Sun Dec
 2 14:58:25 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "BufferFactory.h"
+
+#include <decaf/internal/nio/ByteArrayBuffer.h>
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::nio;
+using namespace decaf::nio;
+using namespace decaf::lang;
+using namespace decaf::lang::exceptions;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* BufferFactory::createByteBuffer( std::size_t capacity ) {
+
+    try{
+        return new ByteArrayBuffer( capacity );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* BufferFactory::createByteBuffer( unsigned char* buffer,
+                                             std::size_t offset,
+                                             std::size_t length )
+    throw( lang::exceptions::NullPointerException ) {
+
+    try{
+        return new ByteArrayBuffer( buffer, offset, length, false );
+    }
+    DECAF_CATCH_RETHROW( NullPointerException )
+    DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
+    DECAF_CATCHALL_THROW( NullPointerException )
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteBuffer* BufferFactory::createByteBuffer( std::vector<unsigned char>& buffer
) {
+
+    try{
+        return new ByteArrayBuffer( &buffer[0], 0, buffer.size(), false );
+    }
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
+}

Added: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h?rev=600402&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h (added)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/BufferFactory.h Sun Dec
 2 14:58:25 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _DECAF_INTERNAL_NIO_BUFFERFACTORY_H_
+#define _DECAF_INTERNAL_NIO_BUFFERFACTORY_H_
+
+#include <decaf/nio/ByteBuffer.h>
+#include <decaf/nio/CharBuffer.h>
+#include <decaf/nio/DoubleBuffer.h>
+#include <decaf/nio/FloatBuffer.h>
+#include <decaf/nio/LongBuffer.h>
+#include <decaf/nio/IntBuffer.h>
+#include <decaf/nio/ShortBuffer.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+    /**
+     * Factory class used by static methods in the decaf::nio package to
+     * create the various default version of the NIO interfaces.
+     */
+    class BufferFactory {
+    public:
+
+        virtual ~BufferFactory() {}
+
+        /**
+         * Allocates a new byte buffer whose position will be zero its limit will
+         * be its capacity and its mark is not set.
+         * @param capacity - the internal buffer's capacity.
+         * @returns a newly allocated ByteBuffer which the caller owns.
+         */
+        static decaf::nio::ByteBuffer* createByteBuffer( std::size_t capacity );
+
+        /**
+         * Wraps the passed buffer with a new ByteBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; that is, modifications
+         * to the buffer will cause the array to be modified and vice versa. The new
+         * buffer's capacity will be array.length, its position will be offset, its limit
+         * will be offset + length, and its mark will be undefined. Its backing array
+         * will be the given array, and its array offset will be zero.
+         * @param buffer - The array that will back the new buffer
+         * @param offset - The offset of the subarray to be used
+         * @param length - The length of the subarray to be used
+         * @returns a new ByteBuffer that is backed by buffer, caller owns.
+         */
+        static decaf::nio::ByteBuffer* createByteBuffer( unsigned char* buffer,
+                                                         std::size_t offset,
+                                                         std::size_t length )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Wraps the passed STL Byte Vector in a ByteBuffer.
+         * <p>
+         * The new buffer will be backed by the given byte array; modifications to the
+         * buffer will cause the array to be modified and vice versa. The new buffer's
+         * capacity and limit will be buffer.size(), its position will be zero, and its
+         * mark will be undefined. Its backing array will be the given array, and its
+         * array offset will be zero.
+         * @param buffer - The vector that will back the new buffer, the vector must
+         * have been sized to the desired size already by calling vector.resize( N ).
+         * @returns a new ByteBuffer that is backed by buffer, caller owns.
+         */
+        static decaf::nio::ByteBuffer* createByteBuffer( std::vector<unsigned char>&
buffer );
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BUFFERFACTORY_H_*/

Copied: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp
(from r600350, activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.cpp)
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp?p2=activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp&p1=activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.cpp&r1=600350&r2=600402&rev=600402&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.cpp (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.cpp Sun
Dec  2 14:58:25 2007
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-#include "ByteBuffer.h"
+#include "ByteArrayBuffer.h"
 #include "decaf/lang/Short.h"
 #include "decaf/lang/Integer.h"
 #include "decaf/lang/Long.h"
@@ -40,14 +40,14 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 ByteArrayBuffer::ByteArrayBuffer( unsigned char* array, std::size_t offset,
-                        std::size_t capacity, bool own, bool readOnly )
+                                  std::size_t capacity, bool readOnly )
     throw( decaf::lang::exceptions::NullPointerException )
     : decaf::nio::ByteBuffer( capacity ) {
 
     try{
 
         // Allocate using the ByteArray, not read-only initially.
-        this->_array = new ByteArrayPerspective( array, capacity, own );
+        this->_array = new ByteArrayPerspective( array, capacity, false );
         this->offset = offset;
         this->readOnly = readOnly;
     }
@@ -58,7 +58,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 ByteArrayBuffer::ByteArrayBuffer( ByteArrayPerspective& array, std::size_t offset,
-                        std::size_t length, bool readOnly )
+                                  std::size_t length, bool readOnly )
     throw( decaf::lang::exceptions::IndexOutOfBoundsException )
     : decaf::nio::ByteBuffer( length ) {
 

Copied: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h (from
r600350, activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.h)
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h?p2=activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h&p1=activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.h&r1=600350&r2=600402&rev=600402&view=diff
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteBuffer.h (original)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayBuffer.h Sun Dec
 2 14:58:25 2007
@@ -124,12 +124,11 @@
          * @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
          */
         ByteArrayBuffer( unsigned char* array, std::size_t offset,
-                    std::size_t capacity, bool own, bool readOnly = false )
+                         std::size_t capacity, bool readOnly = false )
             throw( decaf::lang::exceptions::NullPointerException );
 
         /**
@@ -143,9 +142,9 @@
          * @throws NullPointerException if buffer is NULL
          * @throws IndexOutOfBoundsException if offset is greater than array capacity.
          */
-        ByteArrayBuffer( internal::nio::ByteArrayPerspective& array,
-                    std::size_t offset, std::size_t length,
-                    bool readOnly = false )
+        ByteArrayBuffer( ByteArrayPerspective& array,
+                         std::size_t offset, std::size_t length,
+                         bool readOnly = false )
             throw( decaf::lang::exceptions::IndexOutOfBoundsException );
 
         /**
@@ -158,8 +157,6 @@
         ByteArrayBuffer( const ByteArrayBuffer& other );
 
         virtual ~ByteArrayBuffer();
-
-    public:
 
         /**
          * Tells whether or not this buffer is read-only.

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=600402&r1=600401&r2=600402&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 Dec  2 14:58:25
2007
@@ -16,7 +16,7 @@
  */
 
 #include "ByteBuffer.h"
-#include "decaf/internal/nio/ByteBuffer.h"
+#include "decaf/internal/nio/BufferFactory.h"
 #include "decaf/lang/Short.h"
 #include "decaf/lang/Integer.h"
 #include "decaf/lang/Long.h"
@@ -26,6 +26,7 @@
 using namespace std;
 using namespace decaf;
 using namespace decaf::nio;
+using namespace decaf::internal::nio;
 using namespace decaf::lang;
 using namespace decaf::lang::exceptions;
 
@@ -34,22 +35,14 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-ByteBuffer* ByteBuffer::allocate( std::size_t capacity )
-    throw( lang::exceptions::IllegalArgumentException ) {
+ByteBuffer* ByteBuffer::allocate( std::size_t capacity ) {
 
     try{
 
-        if( capacity == 0 ) {
-            throw IllegalArgumentException(
-                __FILE__, __LINE__,
-                "ByteBuffer::allocate - Can't allocate zero sized ByteBuffer" );
-        }
-
-        return new internal::nio::ByteArrayBuffer( capacity );
+        return BufferFactory::createByteBuffer( capacity );
     }
-    DECAF_CATCH_RETHROW( IllegalArgumentException )
-    DECAF_CATCH_EXCEPTION_CONVERT( Exception, IllegalArgumentException )
-    DECAF_CATCHALL_THROW( IllegalArgumentException )
+    DECAF_CATCH_RETHROW( Exception )
+    DECAF_CATCHALL_THROW( Exception )
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -64,7 +57,7 @@
                 "ByteBuffer::wrap - Passed Buffer is Null.");
         }
 
-        return new internal::nio::ByteArrayBuffer( buffer, offset, length, false );
+        return BufferFactory::createByteBuffer( buffer, offset, length );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )
@@ -82,7 +75,7 @@
                 "ByteBuffer::wrap - Passed Buffer is Empty.");
         }
 
-        return internal::nio::ByteArrayBuffer::wrap( &buffer[0], 0, buffer.size() );
+        return BufferFactory::createByteBuffer( &buffer[0], 0, buffer.size() );
     }
     DECAF_CATCH_RETHROW( NullPointerException )
     DECAF_CATCH_EXCEPTION_CONVERT( Exception, NullPointerException )



Mime
View raw message