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 2009/02/04 23:11:25 UTC
svn commit: r740916 - in /activemq/activemq-cpp/trunk/src:
main/decaf/lang/Pointer.h test/decaf/lang/PointerTest.cpp
Author: tabish
Date: Wed Feb 4 22:11:25 2009
New Revision: 740916
URL: http://svn.apache.org/viewvc?rev=740916&view=rev
Log:
Adds the ability to define what the comparison is for map keys, defaults to the standard std::less comparator. Completes the definition of the Comparator interface in Util, adds a PointerComparator to the Pointer class so that the elements in a Pointer can be compared based on the actual contained objects and not just the underlying pointer value. Adds some test cases to validate these classes.
Modified:
activemq/activemq-cpp/trunk/src/main/decaf/lang/Pointer.h
activemq/activemq-cpp/trunk/src/test/decaf/lang/PointerTest.cpp
Modified: activemq/activemq-cpp/trunk/src/main/decaf/lang/Pointer.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/decaf/lang/Pointer.h?rev=740916&r1=740915&r2=740916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/decaf/lang/Pointer.h (original)
+++ activemq/activemq-cpp/trunk/src/main/decaf/lang/Pointer.h Wed Feb 4 22:11:25 2009
@@ -382,7 +382,7 @@
// Requires that the type in the pointer is an instance of a Comparable.
virtual int compare( const Pointer<T,R>& left, const Pointer<T,R>& right ) const {
- return left->compareTo( *right );
+ return *left < *right ? -1 : *right < *left ? 1 : 0;
}
};
Modified: activemq/activemq-cpp/trunk/src/test/decaf/lang/PointerTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test/decaf/lang/PointerTest.cpp?rev=740916&r1=740915&r2=740916&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test/decaf/lang/PointerTest.cpp (original)
+++ activemq/activemq-cpp/trunk/src/test/decaf/lang/PointerTest.cpp Wed Feb 4 22:11:25 2009
@@ -327,6 +327,25 @@
CPPUNIT_ASSERT( testMap.find( pointer1 ) != testMap.end() );
CPPUNIT_ASSERT( testMap.find( pointer2 ) != testMap.end() );
+
+ Pointer< int > one( new int );
+ Pointer< int > two( new int );
+ Pointer< int > three( new int );
+
+ *one = 1;
+ *two = 2;
+ *three = 3;
+
+ std::map< Pointer<int>, int, PointerComparator<int> > testMap2;
+
+ CPPUNIT_ASSERT( testMap2.size() == 0 );
+ testMap2.insert( std::make_pair( three, 3 ) );
+ testMap2.insert( std::make_pair( two, 2 ) );
+ testMap2.insert( std::make_pair( one, 1 ) );
+ CPPUNIT_ASSERT( testMap2.size() == 3 );
+
+ CPPUNIT_ASSERT( *( testMap2.begin()->first ) == 1 );
+ CPPUNIT_ASSERT( *( testMap2.rbegin()->first ) == 3 );
}
////////////////////////////////////////////////////////////////////////////////