00001 /* 00002 * Copyright (c) 2004 CSIRO ICT Centre 00003 * 00004 * $Id: ObjectConsumer.h 587 2004-12-03 15:06:33Z nch $ 00005 */ 00006 00007 /* 00008 * A consumer of objects. This class counts the number 00009 * of objects reported and forwards them to the writer 00010 * provided to the constructir, if any. 00011 * 00012 * When finished called, the number of objects processed 00013 * is printed to stdout. 00014 * 00015 * This class should not be subclassed since there is 00016 * nothing more to be done with "single" (unmatched) 00017 * objects, unlike the case for pairs of objects. 00018 * 00019 * This class owns the ObjectWriter and deletes it in the destructor. 00020 */ 00021 00022 #ifndef OBJECTCONSUMER_DEFINED 00023 #define OBJECTCONSUMER_DEFINED 00024 00025 #include "String.h" 00026 #include "ObjectWriter.h" 00027 00028 class Object; 00029 00030 00031 class ObjectConsumer 00032 { 00033 public: 00034 ObjectConsumer(String const & name, ObjectWriter * writer=0); 00035 ~ObjectConsumer(); 00036 String const & getName() const { return m_name; }; 00037 void report(Object const * object) 00038 { 00039 if (m_writer != 0) 00040 m_writer->write(object); 00041 m_count++; 00042 }; 00043 void finished(); 00044 00045 private: 00046 String m_name; 00047 ObjectWriter * m_writer; 00048 unsigned long long m_count; 00049 00050 ObjectConsumer(); 00051 ObjectConsumer(ObjectConsumer const &); 00052 ObjectConsumer & operator=(ObjectConsumer const &); 00053 }; 00054 00055 #endif // ifndef OBJECTCONSUMER_DEFINED