Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 95348 invoked from network); 9 Dec 2010 19:10:09 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 9 Dec 2010 19:10:09 -0000 Received: (qmail 19524 invoked by uid 500); 9 Dec 2010 19:10:09 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 19458 invoked by uid 500); 9 Dec 2010 19:10:09 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 19451 invoked by uid 99); 9 Dec 2010 19:10:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Dec 2010 19:10:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Dec 2010 19:10:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 334CC23888EA; Thu, 9 Dec 2010 19:09:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@activemq.apache.org From: tabish@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101209190948.334CC23888EA@eris.apache.org> 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 #include #include +#include #include #include #include @@ -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 array( SIZE ); + + CPPUNIT_ASSERT_EQUAL( SIZE, array.length() ); + CPPUNIT_ASSERT( array.get() != NULL ); +} + +//////////////////////////////////////////////////////////////////////////////// +void ArrayPointerTest::testConstructor2() { + + const int SIZE = 50; + + ArrayPointer 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 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();