00001 /* 00002 * Copyright (c) 2004 CSIRO ICT Centre 00003 * 00004 * $Id: Matcher.h 587 2004-12-03 15:06:33Z nch $ 00005 */ 00006 00007 /* 00008 * Matcher is the interface that every matching implementation must instantiate. 00009 * 00010 * A matcher assumes there are two object producers: one for active 00011 * objects placed onto the active list, and one for test object, which are 00012 * tested against the active objects in the active list. 00013 * 00014 * Matches of active objects are reported to the pair consumer while 00015 * those objects not involved in a match are reported appropriatly 00016 * via the reportActiveNoMatch and reportTestNoMatch methods. 00017 * 00018 * A matcher may implement its own specialised filter implementation: 00019 * the doFilter method. The filter class will call the getReady and 00020 * finished methods prior to and after filtering respectively. 00021 * 00022 * The getLowerBound and getUpperBound methods are the limits for the 00023 * active objects being in the active list, and are calculated in terms 00024 * of the current test object. 00025 * 00026 * The test method with objects is a "short cut" to testing if two 00027 * candidate objects meet the matching criteria. This is not normally 00028 * used (except by the NestedLoopFilter class). Instead, should use the 00029 * test method providing a single testObject to test against all 00030 * objects in the active list. 00031 * 00032 * The final two flush methods are for cleaning up when one or the other 00033 * producers are finished. 00034 * 00035 * These classes should be understood in conjunction with the Filter 00036 * classes. The aim has been to abstract the filtering from the 00037 * matching so that different matching algorithms may be used with 00038 * various filters in combination without exploding the number of 00039 * class required. The success of this approach will be measured as 00040 * more filter or matching classes are implemented. 00041 */ 00042 00043 #ifndef MATCHER_DEFINED 00044 #define MATCHER_DEFINED 00045 00046 #include "String.h" 00047 00048 #include "ObjectConsumer.h" 00049 00050 class Object; 00051 class ObjectProducer; 00052 class ObjectPairConsumer; 00053 class Profiler; 00054 00055 00056 class Matcher 00057 { 00058 public: 00059 virtual ~Matcher(); 00060 00061 virtual String const & getName() const=0; 00062 00063 bool hasFilter() const { return hasOwnFilter; }; 00064 00065 virtual void getReady(); 00066 virtual void finished(); 00067 virtual void doFilter() {}; 00068 00069 virtual Object const * nextActiveObject()=0; 00070 virtual Object const * nextTestObject()=0; 00071 00072 virtual double getLowerBound(Object const * testObject)=0; 00073 virtual double getUpperBound(Object const * testObject)=0; 00074 00075 virtual void addActiveObject(Object const * activeObject)=0; 00076 00077 virtual bool test(Object const * activeObject, 00078 Object const * testObject); 00079 virtual void test(Object const * testObject)=0; 00080 00081 virtual void reportActiveNoMatch(Object const * activeObject)=0; 00082 virtual void reportTestNoMatch(Object const * testObject)=0; 00083 00084 virtual void flushActiveObjects(double lowerBound)=0; 00085 virtual void flushActiveObjects(Object const * activeObject)=0; 00086 00087 protected: 00088 ObjectPairConsumer * pairCons; 00089 Profiler * profiler; 00090 00091 Matcher(ObjectPairConsumer * pairCons, bool hasFilter=false); 00092 00093 Object const * nextObject(ObjectProducer * producer); 00094 void reportNoMatch(ObjectConsumer * cons, Object const * obj) 00095 { cons->report(obj); }; 00096 00097 private: 00098 bool hasOwnFilter; 00099 unsigned long long numObjects; 00100 00101 Matcher(); 00102 Matcher(Matcher const &); 00103 Matcher & operator=(Matcher const &); 00104 00105 void incObjectCount(); 00106 }; 00107 00108 00109 #endif // ifndef MATCHER_DEFINED