00001 /* 00002 * Copyright (c) 2004 CSIRO ICT Centre 00003 * 00004 * $Id: Matcher.cpp 587 2004-12-03 15:06:33Z nch $ 00005 */ 00006 00007 #include "Matcher.h" 00008 #include "Object.h" 00009 #include "ObjectPairConsumer.h" 00010 #include "ObjectProducer.h" 00011 #include "Profiler.h" 00012 #include "Timer.h" 00013 00014 class Refine; 00015 00016 00017 Matcher::Matcher(ObjectPairConsumer * cons, bool hasFilter) 00018 : pairCons(cons), 00019 profiler(0), 00020 hasOwnFilter(hasFilter), 00021 numObjects(0) 00022 { 00023 } 00024 00025 Matcher::~Matcher() 00026 { 00027 } 00028 00029 void Matcher::getReady() 00030 { 00031 #ifdef PROFILE 00032 /* Set up and start profiler */ 00033 profiler = new Profiler(getName()); 00034 profiler->runTimer(); 00035 #endif // PROFILE; 00036 } 00037 00038 void Matcher::finished() 00039 { 00040 pairCons->finished(); 00041 00042 #ifdef PROFILE 00043 /* stop the profiler and output the results. */ 00044 profiler->pauseTimer(); 00045 profiler->outputResults(); 00046 00047 delete profiler; 00048 #endif // PROFILE 00049 } 00050 00051 bool Matcher::test(Object const * testObject, 00052 Object const * activeObject) 00053 { 00054 return pairCons->report(testObject, activeObject); 00055 } 00056 00057 Object const * Matcher::nextObject(ObjectProducer * producer) 00058 { 00059 Object const * next = 0; 00060 00061 if (producer->hasNext()) 00062 { 00063 next = producer->next(); 00064 incObjectCount(); 00065 } 00066 00067 return next; 00068 } 00069 00070 void Matcher::incObjectCount() 00071 { 00072 #ifdef PLOT_TIMES 00073 #ifdef TIMER 00074 if (++numObjects % 500 == 0) 00075 { 00076 Timer::globalTimer()->pause(); 00077 printf("%lld %f\n", numObjects, Timer::globalTimer()->cpu()); 00078 Timer::globalTimer()->cont(); 00079 } 00080 #endif 00081 #endif 00082 }