activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r943481 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang: ArrayPointer.h System.cpp System.h
Date Wed, 12 May 2010 13:33:34 GMT
Author: tabish
Date: Wed May 12 13:33:34 2010
New Revision: 943481

URL: http://svn.apache.org/viewvc?rev=943481&view=rev
Log:
Fix some issues and add a clone method to ArrayPointer.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/ArrayPointer.h
    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/ArrayPointer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/ArrayPointer.h?rev=943481&r1=943480&r2=943481&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/ArrayPointer.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/ArrayPointer.h Wed May 12
13:33:34 2010
@@ -19,6 +19,7 @@
 #define _DECAF_LANG_ARRAYPOINTER_H_
 
 #include <decaf/util/Config.h>
+#include <decaf/lang/System.h>
 #include <decaf/lang/exceptions/NullPointerException.h>
 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
 #include <decaf/lang/exceptions/IllegalArgumentException.h>
@@ -219,6 +220,23 @@ namespace lang {
         }
 
         /**
+         * Creates a new ArrayPointer instance that is a clone of the value contained in
this
+         * ArrayPointer.
+         *
+         * @return an ArrayPointer that contains a copy of the data in this ArrayPointer.
+         */
+        ArrayPointer clone() {
+
+            if( this->array->length == 0 ){
+                return ArrayPointer();
+            }
+
+            ArrayPointer copy( this->array->length );
+            decaf::lang::System::arraycopy( this->array->value, 0, copy.get(), 0, this->array->length
);
+            return copy;
+        }
+
+        /**
          * Assigns the value of right to this Pointer and increments the reference Count.
          * @param right - Pointer on the right hand side of an operator= call to this.
          */
@@ -263,7 +281,7 @@ namespace lang {
 
             return this->array->value[index];
         }
-        ReferenceType operator[]( int index ) const {
+        const ReferenceType operator[]( int index ) const {
             if( this->array->value == NULL ) {
                 throw decaf::lang::exceptions::NullPointerException(
                     __FILE__, __LINE__, "ArrayPointer operator& - Pointee is NULL." );
@@ -271,7 +289,7 @@ namespace lang {
 
             if( index < 0 || this->array->length <= index ) {
                 throw decaf::lang::exceptions::IndexOutOfBoundsException(
-                    __FILE__, __LINE__, "Array Index %d is out of bounds for this array.",
*( this->array->length ) );
+                    __FILE__, __LINE__, "Array Index %d is out of bounds for this array.",
this->array->length );
             }
 
             return this->array->value[index];

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=943481&r1=943480&r2=943481&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 Wed May 12 13:33:34
2010
@@ -73,8 +73,7 @@ AprPool& System::getAprPool() {
 
 ////////////////////////////////////////////////////////////////////////////////
 void System::arraycopy( const unsigned char* src, std::size_t srcPos,
-                        unsigned char* dest, std::size_t destPos, std::size_t length )
-    throw( decaf::lang::exceptions::NullPointerException ){
+                        unsigned char* dest, std::size_t destPos, std::size_t length ) {
 
     if( src == NULL ) {
         throw NullPointerException(
@@ -95,7 +94,29 @@ void System::arraycopy( const unsigned c
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void System::unsetenv( const std::string& name ) throw ( lang::Exception ) {
+void System::arraycopy( const int* src, std::size_t srcPos,
+                        int* 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( int ) );
+    } else {
+        ::memmove( dest + destPos, src + srcPos, length * sizeof( int ) );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void System::unsetenv( const std::string& name ) {
 
     apr_status_t result = APR_SUCCESS;
 
@@ -115,7 +136,7 @@ void System::unsetenv( const std::string
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string System::getenv( const std::string& name ) throw ( Exception ) {
+std::string System::getenv( const std::string& name ) {
 
     char* value = NULL;
     apr_status_t result = APR_SUCCESS;
@@ -145,8 +166,7 @@ std::string System::getenv( const std::s
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void System::setenv( const std::string& name, const std::string& value )
-    throw ( lang::Exception ) {
+void System::setenv( const std::string& name, const std::string& value ) {
 
     apr_status_t result = APR_SUCCESS;
 
@@ -217,7 +237,7 @@ long long System::nanoTime() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-const Map<string, string>& System::getenv() throw ( Exception ) {
+const Map<string, string>& System::getenv() {
 
     static StlMap<string, string> values;
     values.clear();

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=943481&r1=943480&r2=943481&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 Wed May 12 13:33:34
2010
@@ -58,44 +58,54 @@ namespace lang{
          * @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
)
-            throw( decaf::lang::exceptions::NullPointerException );
+                               unsigned char* dest, std::size_t destPos, std::size_t length
);
+        static void arraycopy( const int* src, std::size_t srcPos,
+                               int* dest, std::size_t destPos, std::size_t length );
 
         /**
          * Enumerates the system environment and returns a map of env variable
          * names to the string values they hold.
+         *
          * @return A Map of all environment variables.
-         * @throw Exception if an error occurs
+         *
+         * @throw Exception if an error occurs while getting the Environment Map.
          */
-        static const util::Map<std::string, std::string>& getenv()
-            throw ( lang::Exception );
+        static const util::Map<std::string, std::string>& getenv();
 
         /**
          * Reads an environment value from the system and returns it as a
          * string object
-         * @param name - the env var to read
-         * @return a string with the value from the var or ""
+         *
+         * @param name
+         *      The environment variable to read.
+         *
+         * @return a string with the value from the variables or ""
+         *
          * @throws an Exception if an error occurs while reading the Env.
          */
-        static std::string getenv( const std::string& name )
-            throw ( lang::Exception );
+        static std::string getenv( const std::string& name );
 
         /**
-         * Clears a set env value if one is set.
-         * @param name - the env var to clear
-         * @throws an Exception if an error occurs while reading the Env.
+         * Clears a set environment value if one is set.
+         *
+         * @param name
+         *      The environment variables to clear.
+         *
+         * @throws an Exception if an error occurs while reading the environment.
          */
-        static void unsetenv( const std::string& name )
-            throw ( lang::Exception );
+        static void unsetenv( const std::string& name );
 
         /**
-         * Sets the specified system property to the value given
-         * @param name - name of the env val to set
-         * @param value - value to assign to name
-         * @throws an Exception if an error occurs
+         * Sets the specified system property to the value given.
+         *
+         * @param name
+         *      The name of the environment variables to set.
+         * @param value
+         *      The value to assign to name.
+         *
+         * @throws an Exception if an error occurs when setting the environment variable.
          */
-        static void setenv( const std::string& name, const std::string& value )
-            throw ( lang::Exception );
+        static void setenv( const std::string& name, const std::string& value );
 
         /**
          * Returns the current time in milliseconds. Note that while the unit of time of
@@ -136,7 +146,7 @@ namespace lang{
         static long long nanoTime();
 
         /**
-         * Returns the number of processors available for exection of Decaf Threads.
+         * Returns the number of processors available for execution of Decaf Threads.
          *
          * This value may change during a particular execution of a Decaf based application.
Applications
          * that are sensitive to the number of available processors should therefore occasionally
poll
@@ -152,12 +162,15 @@ namespace lang{
          * Enumerates the environment and return an array of strings
          * with the values.  Caller owns the array.  The array is terminated
          * by an element that holds the value NULL
-         * @returns a vector of env name=value paris.
+         *
+         * @returns a vector of environment name / value pairs.
          */
         static std::vector< std::string > getEnvArray();
 
         /**
          * Gets the one and only APR Pool instance
+         *
+         * @returns a reference to the global APR Pool.
          */
         static internal::AprPool& getAprPool();
 



Mime
View raw message