activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1044092 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/lang/ArrayPointer.h test/decaf/lang/ArrayPointerTest.cpp test/decaf/lang/ArrayPointerTest.h
Date Thu, 09 Dec 2010 19:09:48 GMT
Author: tabish
Date: Thu Dec  9 19:09:47 2010
New Revision: 1044092

URL: http://svn.apache.org/viewvc?rev=1044092&view=rev
Log:
Add an optional constructor to all for array init using a specified value.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/ArrayPointer.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.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=1044092&r1=1044091&r2=1044092&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 Thu Dec  9
19:09:47 2010
@@ -25,6 +25,7 @@
 #include <decaf/lang/exceptions/IllegalArgumentException.h>
 #include <decaf/util/concurrent/atomic/AtomicRefCounter.h>
 #include <decaf/util/Comparator.h>
+#include <decaf/util/Arrays.h>
 #include <memory>
 #include <typeinfo>
 #include <algorithm>
@@ -121,6 +122,36 @@ namespace lang {
         }
 
         /**
+         * Create a new ArrayPointer instance and allocates an internal array that is sized
+         * using the passed in size value.  The array elements are initialized with the given
+         * value.
+         *
+         * @param size
+         *      The size of the array to allocate for this ArrayPointer instance.
+         * @param fillWith
+         *      The value to initialize each element of the newly allocated array with.
+         */
+        ArrayPointer( int size, const T& fillWith ) :
+            REFCOUNTER(), array( NULL ), onDelete( onDeleteFunc ) {
+
+            if( size == 0 ) {
+                return;
+            }
+
+            try{
+                T* value = new T[size];
+                decaf::util::Arrays::fill( value, size, 0, size, fillWith );
+                this->array = new ArrayData( value, size );
+            } catch( std::exception& ex ) {
+                REFCOUNTER::release();
+                throw ex;
+            } catch(...) {
+                REFCOUNTER::release();
+                throw std::bad_alloc();
+            }
+        }
+
+        /**
          * Explicit Constructor, creates an ArrayPointer that contains value with a
          * single reference.  This object now has ownership until a call to release.
          *

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.cpp?rev=1044092&r1=1044091&r2=1044092&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.cpp Thu
Dec  9 19:09:47 2010
@@ -176,6 +176,41 @@ void ArrayPointerTest::testBasics() {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
+void ArrayPointerTest::testConstructor1() {
+
+    const int SIZE = 50;
+
+    ArrayPointer<int> array( SIZE );
+
+    CPPUNIT_ASSERT_EQUAL( SIZE, array.length() );
+    CPPUNIT_ASSERT( array.get() != NULL );
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ArrayPointerTest::testConstructor2() {
+
+    const int SIZE = 50;
+
+    ArrayPointer<bool> trueArray( SIZE, true );
+
+    CPPUNIT_ASSERT_EQUAL( SIZE, trueArray.length() );
+    CPPUNIT_ASSERT( trueArray.get() != NULL );
+
+    for( int ix = 0; ix < SIZE; ix++ ) {
+        CPPUNIT_ASSERT_EQUAL( true, trueArray[ix] );
+    }
+
+    ArrayPointer<bool> falseArray( SIZE, true );
+
+    CPPUNIT_ASSERT_EQUAL( SIZE, falseArray.length() );
+    CPPUNIT_ASSERT( falseArray.get() != NULL );
+
+    for( int ix = 0; ix < SIZE; ix++ ) {
+        CPPUNIT_ASSERT_EQUAL( true, falseArray[ix] );
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
 void ArrayPointerTest::testClone() {
 
     const int SIZE = 50;

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.h?rev=1044092&r1=1044091&r2=1044092&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ArrayPointerTest.h Thu Dec
 9 19:09:47 2010
@@ -28,6 +28,8 @@ namespace lang {
 
         CPPUNIT_TEST_SUITE( ArrayPointerTest );
         CPPUNIT_TEST( testBasics );
+        CPPUNIT_TEST( testConstructor1 );
+        CPPUNIT_TEST( testConstructor2 );
         CPPUNIT_TEST( testClone );
         CPPUNIT_TEST( testAssignment );
         CPPUNIT_TEST( testComparisons );
@@ -45,6 +47,8 @@ namespace lang {
         virtual ~ArrayPointerTest() {}
 
         void testBasics();
+        void testConstructor1();
+        void testConstructor2();
         void testClone();
         void testAssignment();
         void testComparisons();



Mime
View raw message