#include <coherence/util/SortedBag.hpp>
Inherits Object, and Comparator.
Public Types | |
typedef spec::Handle | Handle |
WrapperComparator Handle definition. | |
typedef spec::View | View |
WrapperComparator View definition. | |
typedef spec::Holder | Holder |
WrapperComparator Holder definition. | |
Public Member Functions | |
virtual int32_t | compare (Object::View v1, Object::View v2) const |
Compare two Objects. If both Objects are comparable with this Comparator, return < 0, 0 or > 0 if the first Object is less than, equal to, or greater than the second Object. The general contract for this method is:
A typical implementation of Comparator may look as follows: int32_t MyTypeComparator::compare(Object::View v1, Object::View v2) const { // compares instances of class MyType only if (!v1 || !v2) { COH_THROW(NullPointerException()); } MyType::View vTypedObj1 = cast<MyType::View>(v1); MyType::View vTypedObj2 = cast<MyType::View>(v2); if (!vTypedObj1 || !vTypedObj1) { COH_THROW(IllegalArgumentException("Instances of MyType expected")); } // here we suppose that the state of the MyType is defined by // single field of integer type if (vTypedObj1->m_intField == vTypedObj2->m_intField) { return 0; } else if (vTypedObj1->m_intField < vTypedObj2->m_intField) { return -1; } else { return 1; } } | |
Protected Attributes | |
FinalView< Comparator > | f_vComparator |
The underlying "logical" comparator. |