activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r600744 - in /activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio: ByteArrayAdapter.cpp ByteArrayAdapter.h
Date Tue, 04 Dec 2007 00:33:53 GMT
Author: tabish
Date: Mon Dec  3 16:33:52 2007
New Revision: 600744

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

Working on implementing the NIO package

Added:
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.cpp
    activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.h

Added: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.cpp?rev=600744&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.cpp (added)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.cpp Mon
Dec  3 16:33:52 2007
@@ -0,0 +1,80 @@
+/*
+ * 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 "ByteArrayAdapter.h"
+
+using namespace decaf;
+using namespace decaf::internal;
+using namespace decaf::internal::util;
+using namespace decaf::internal::nio;
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( int capacity ) : ByteArray( capacity ){
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( unsigned char* array, std::size_t capacity, bool own
)
+    throw( lang::exceptions::NullPointerException )
+        : ByteArray( array, capacity, own ) {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( char* array, std::size_t capacity, bool own )
+    throw( lang::exceptions::NullPointerException )
+    : ByteArray( reinterpret_cast<unsigned char*>( array ), capacity, own ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( double* array, std::size_t capacity, bool own )
+    throw( lang::exceptions::NullPointerException )
+    : ByteArray( reinterpret_cast<unsigned char*>( array ),
+                 capacity * sizeof( double ), own ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( float* array, std::size_t capacity, bool own )
+    throw( lang::exceptions::NullPointerException )
+    : ByteArray( reinterpret_cast<unsigned char*>( array ),
+                 capacity * sizeof( float ), own ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( long long* array, std::size_t capacity, bool own )
+    throw( lang::exceptions::NullPointerException )
+    : ByteArray( reinterpret_cast<unsigned char*>( array ),
+                 capacity * sizeof( long long ), own ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( int* array, std::size_t capacity, bool own )
+    throw( lang::exceptions::NullPointerException )
+    : ByteArray( reinterpret_cast<unsigned char*>( array ),
+                 capacity * sizeof( int ), own ) {
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+ByteArrayAdapter::ByteArrayAdapter( short* array, std::size_t capacity, bool own )
+    throw( lang::exceptions::NullPointerException )
+    : ByteArray( reinterpret_cast<unsigned char*>( array ),
+                 capacity * sizeof( short ), own ) {
+
+}

Added: activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.h?rev=600744&view=auto
==============================================================================
--- activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.h (added)
+++ activemq/activemq-cpp/decaf/trunk/src/main/decaf/internal/nio/ByteArrayAdapter.h Mon Dec
 3 16:33:52 2007
@@ -0,0 +1,286 @@
+/*
+ * 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_BYTEARRAYADAPTER_H_
+#define _DECAF_INTERNAL_NIO_BYTEARRAYADAPTER_H_
+
+#include <decaf/internal/util/ByteArray.h>
+
+namespace decaf{
+namespace internal{
+namespace nio{
+
+    /**
+     * This class is used by the class in this package which are realizations
+     * of the interfaces in the <code>decaf::nio</code> pacakge.  This class
+     * adapts primitve type arrays to a base byte array so that the classes
+     * can interoperate on the same base byte array without copying data.
+     * <p>
+     * Methods in this class that do not return a specifc value return a
+     * reference to this object so that calls can be chained.
+     */
+    class ByteArrayAdapter : public util::ByteArray {
+    public:
+
+        /**
+         * Creates a byte array object that is allocated internally and is then owned
+         * and deleted when this object is deleted.  The array is initially created
+         * with all elements initialized to zero.
+         * @param capacity - size of the array, this is the limit we read and write to.
+         */
+        ByteArrayAdapter( int capacity );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( unsigned char* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( char* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( double* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( float* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( long long* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( int* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        /**
+         * Creates a byte array object that wraps the given array.  If the own flag
+         * is set then it will delete this array when this object is deleted.
+         * @param array - array to wrap
+         * @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.
+         * @throws NullPointerException if buffer is NULL
+         */
+        ByteArrayAdapter( short* array, std::size_t capacity, bool own = false )
+            throw( lang::exceptions::NullPointerException );
+
+        virtual ~ByteArrayAdapter() {}
+
+        /**
+         * 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
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual unsigned char get( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads one byte at the given index and returns it
+         * @param index - the index in the Buffer where the byte is to be read
+         * @returns the char at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If index is not smaller than the
+         * buffer's limit
+         */
+        virtual char getChar( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException ) {
+
+            return (char)this->get( index );
+        }
+
+        /**
+         * Reads eight bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the double at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual double getDouble( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads four bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the float at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual float getFloat( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads eight bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the long long at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual long long getLong( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads four bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the int at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual int getInt( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Reads two bytes at the given index and returns it
+         * @param index - the index in the Buffer where the bytes are to be read
+         * @returns the short at the given index in the buffer
+         * @throws IndexOutOfBoundsException - If there are not enough bytes
+         * remaining to fill the requested Data Type
+         */
+        virtual short getShort( std::size_t index ) const
+            throw ( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes the given byte into this buffer at the given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the byte to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& put( std::size_t index, unsigned char value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes one byte containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putChar( std::size_t index, char value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putDouble( std::size_t index, double value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putFloat( std::size_t index, float value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes eight bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putLong( std::size_t index, long long value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes four bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putInt( std::size_t index, int value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+        /**
+         * Writes two bytes containing the given value, into this buffer at the
+         * given index.
+         * @param index - position in the Buffer to write the data
+         * @param value - the value to write.
+         * @returns a reference to this buffer
+         * @throw IndexOutOfBoundsException - If index greater than the buffer's limit
+         * minus the size of the type being written.
+         */
+        virtual ByteArrayAdapter& putShort( std::size_t index, short value )
+            throw( lang::exceptions::IndexOutOfBoundsException );
+
+    };
+
+}}}
+
+#endif /*_DECAF_INTERNAL_NIO_BYTEARRAYADAPTER_H_*/



Mime
View raw message