1/* 2 File: CItemComparer.h 3 4 Contains: Interface to the CItemComparer class 5 6 7*/ 8 9#ifndef __CITEMCOMPARER_H 10#define __CITEMCOMPARER_H 11 12#include "IrDATypes.h" 13 14enum CompareResult { 15 kItemLessThanCriteria = -1, 16 kItemEqualCriteria = 0, 17 kItemGreaterThanCriteria = 1 18}; 19 20 21// NOTE 22// CItemComparer::TestItem should return 23// kItemLessThanCriteria if (fItem < criteria) 24// kItemGreaterThanCriteria for (fItem > criteria) 25// kItemEqualCriteria for (fItem == criteria) 26// this will keep the CSortedList sorted in ascending order 27 28// Change the value of itsForward in CArrayIterator::CArrayIterator 29// to FALSE to view a list in descending order. 30 31 32//-------------------------------------------------------------------------------- 33// CItemComparer 34//-------------------------------------------------------------------------------- 35class CItemComparer : public OSObject 36{ 37 OSDeclareDefaultStructors(CItemComparer); 38 39public: 40 static CItemComparer * cItemComparer(const void* testItem = nil, const void* keyValue = nil); 41 42 Boolean init(const void* testItem, const void* keyValue = nil); 43 44 void SetTestItem(const void* testItem); 45 void SetKeyValue(const void* keyValue); 46 47 // functions that wrap inline methods so they can be used by external callers 48 void FXUSetTestItem(const void* testItem); 49 void FXUSetKeyValue(const void* keyValue); 50 51 virtual CompareResult TestItem(const void* criteria) const; 52 53protected: 54 55 const void* fItem; 56 const void* fKey; 57 58private: 59 60}; // CItemComparer 61 62//-------------------------------------------------------------------------------- 63// CItemComparer inlines 64//-------------------------------------------------------------------------------- 65 66inline void CItemComparer::SetTestItem(const void* testItem) 67 { fItem = testItem; } 68 69inline void CItemComparer::SetKeyValue(const void* keyValue) 70 { fKey = keyValue; } 71 72#endif /* __CITEMCOMPARER_H */ 73