You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/11/29 21:05:28 UTC

svn commit: r1040257 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang: System.cpp System.h

Author: tabish
Date: Mon Nov 29 20:05:27 2010
New Revision: 1040257

URL: http://svn.apache.org/viewvc?rev=1040257&view=rev
Log:
Adds a complete set of arraycopy methods and a generic version for non-primitive type arrays.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp?rev=1040257&r1=1040256&r2=1040257&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.cpp Mon Nov 29 20:05:27 2010
@@ -112,6 +112,28 @@ AprPool& System::getAprPool() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void System::arraycopy( const char* src, std::size_t srcPos,
+                        char* dest, std::size_t destPos, std::size_t length ) {
+
+    if( src == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Given Source Pointer was null." );
+    }
+
+    if( src == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Given Source Pointer was null." );
+    }
+
+    // Now we try and copy, could still segfault.
+    if( src != dest ) {
+        ::memcpy( dest + destPos, src + srcPos, length );
+    } else {
+        ::memmove( dest + destPos, src + srcPos, length );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void System::arraycopy( const unsigned char* src, std::size_t srcPos,
                         unsigned char* dest, std::size_t destPos, std::size_t length ) {
 
@@ -200,6 +222,50 @@ void System::arraycopy( const long long*
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void System::arraycopy( const float* src, std::size_t srcPos,
+                        float* dest, std::size_t destPos, std::size_t length ) {
+
+    if( src == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Given Source Pointer was null." );
+    }
+
+    if( src == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Given Source Pointer was null." );
+    }
+
+    // Now we try and copy, could still segfault.
+    if( src != dest ) {
+        ::memcpy( dest + destPos, src + srcPos, length * sizeof( float ) );
+    } else {
+        ::memmove( dest + destPos, src + srcPos, length * sizeof( float ) );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void System::arraycopy( const double* src, std::size_t srcPos,
+                        double* dest, std::size_t destPos, std::size_t length ) {
+
+    if( src == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Given Source Pointer was null." );
+    }
+
+    if( src == NULL ) {
+        throw NullPointerException(
+            __FILE__, __LINE__, "Given Source Pointer was null." );
+    }
+
+    // Now we try and copy, could still segfault.
+    if( src != dest ) {
+        ::memcpy( dest + destPos, src + srcPos, length * sizeof( double ) );
+    } else {
+        ::memmove( dest + destPos, src + srcPos, length * sizeof( double ) );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void System::unsetenv( const std::string& name ) {
 
     apr_status_t result = APR_SUCCESS;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h?rev=1040257&r1=1040256&r2=1040257&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/System.h Mon Nov 29 20:05:27 2010
@@ -71,6 +71,27 @@ namespace lang{
          *
          * @throws NullPointerException if src or dest are NULL.
          */
+        static void arraycopy( const char* src, std::size_t srcPos,
+                               char* dest, std::size_t destPos, std::size_t length );
+
+        /**
+         * Copies the number of elements specified by length from the source array starting at
+         * the given source offset specified by srcPos to the dest array starting at the given
+         * destination offset given by destPos.
+         *
+         * @param src
+         *      The source array to copy from.
+         * @param srcPos
+         *      The position in the array to start copying from.
+         * @param dest
+         *      The destination array to copy to.
+         * @param destPos
+         *      The position in the destination array to start writing at.
+         * @param length
+         *      The number of elements to copy from src to dest.
+         *
+         * @throws NullPointerException if src or dest are NULL.
+         */
         static void arraycopy( const unsigned char* src, std::size_t srcPos,
                                unsigned char* dest, std::size_t destPos, std::size_t length );
 
@@ -138,6 +159,85 @@ namespace lang{
                                long long* dest, std::size_t destPos, std::size_t length );
 
         /**
+         * Copies the number of elements specified by length from the source array starting at
+         * the given source offset specified by srcPos to the dest array starting at the given
+         * destination offset given by destPos.
+         *
+         * @param src
+         *      The source array to copy from.
+         * @param srcPos
+         *      The position in the array to start copying from.
+         * @param dest
+         *      The destination array to copy to.
+         * @param destPos
+         *      The position in the destination array to start writing at.
+         * @param length
+         *      The number of elements to copy from src to dest.
+         *
+         * @throws NullPointerException if src or dest are NULL.
+         */
+        static void arraycopy( const float* src, std::size_t srcPos,
+                               float* dest, std::size_t destPos, std::size_t length );
+
+        /**
+         * Copies the number of elements specified by length from the source array starting at
+         * the given source offset specified by srcPos to the dest array starting at the given
+         * destination offset given by destPos.
+         *
+         * @param src
+         *      The source array to copy from.
+         * @param srcPos
+         *      The position in the array to start copying from.
+         * @param dest
+         *      The destination array to copy to.
+         * @param destPos
+         *      The position in the destination array to start writing at.
+         * @param length
+         *      The number of elements to copy from src to dest.
+         *
+         * @throws NullPointerException if src or dest are NULL.
+         */
+        static void arraycopy( const double* src, std::size_t srcPos,
+                               double* dest, std::size_t destPos, std::size_t length );
+
+        /**
+         * Copies the number of elements specified by length from the source array starting at
+         * the given source offset specified by srcPos to the dest array starting at the given
+         * destination offset given by destPos.
+         *
+         * @param src
+         *      The source array to copy from.
+         * @param srcPos
+         *      The position in the array to start copying from.
+         * @param dest
+         *      The destination array to copy to.
+         * @param destPos
+         *      The position in the destination array to start writing at.
+         * @param length
+         *      The number of elements to copy from src to dest.
+         *
+         * @throws NullPointerException if src or dest are NULL.
+         */
+        template< typename E >
+        static void arraycopy( const E* src, std::size_t srcPos,
+                               E* dest, std::size_t destPos, std::size_t length ) {
+
+            if( src == NULL ) {
+                throw decaf::lang::exceptions::NullPointerException(
+                    __FILE__, __LINE__, "Given Source Pointer was null." );
+            }
+
+            if( src == NULL ) {
+                throw decaf::lang::exceptions::NullPointerException(
+                    __FILE__, __LINE__, "Given Source Pointer was null." );
+            }
+
+            for( std::size_t i = 0; i < length; ++i ) {
+                dest[destPos+i] = src[srcPos+i];
+            }
+        }
+
+        /**
          * Enumerates the system environment and returns a map of env variable
          * names to the string values they hold.
          *