NeighboursBinaryFileWriter.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 //-----------------------------------------------------------------------------
00005 // Initial version: 07/09/2005
00006 // CVS: $Revision: 2989 $, $Date: 2006-10-12 17:31:45 +0100 (Thu, 12 Oct 2006) $, $Author: rsc $
00007 //-----------------------------------------------------------------------------
00008 #ifndef NEIGHBOURSBINARYFILEWRITER_DEFINED
00009 #define NEIGHBOURSBINARYFILEWRITER_DEFINED
00010 
00011 #include "Datum.h"
00012 #include "FileObjectWriter.h"
00013 #include "FileUtil.h"
00014 #include "ObjectPairWriter.h"
00015 
00016 class Object;
00017 //-----------------------------------------------------------------------------
00019 
00024 class NeighboursBinaryFileWriter : public ObjectPairWriter
00025 {
00026 public:
00031   NeighboursBinaryFileWriter(char const* aFileNameStr,
00032                                   bool aIsLarge = false);
00033   virtual ~NeighboursBinaryFileWriter() {}
00034 
00036   virtual void open();
00037 
00039   virtual void close();
00040 
00045   virtual void write(Object const* aMasterObjectPtr,
00046                      Object const* aSlaveObjectPtr)
00047   {
00048     Datum const* masterDatumPtr = (Datum const*) aMasterObjectPtr;
00049     Datum const*  slaveDatumPtr = (Datum const*) aSlaveObjectPtr;
00050     mRecord.field.masterObjId = masterDatumPtr->getId();
00051     mRecord.field.slaveObjId  =  slaveDatumPtr->getId();
00052     mRecord.field.distanceMins = aMasterObjectPtr->
00053                                    gcDistanceMins(*aSlaveObjectPtr);
00054     fwrite(mRecord.bytes, sizeof(char), mcRecordSize, mFilePtr);
00055     // For every match also record the reverse match
00056     mRecord.field.masterObjId = mRecord.field.slaveObjId;
00057     mRecord.field.slaveObjId = masterDatumPtr->getId();
00058     fwrite(mRecord.bytes, sizeof(char), mcRecordSize, mFilePtr);
00059   }
00060 
00061 protected:
00063   static const unsigned mcRecordSize = 20;
00064 
00066   union {
00067     char bytes[mcRecordSize];
00068     struct {
00069       long long masterObjId;
00070       long long slaveObjId;
00071       float distanceMins;
00072     } field;
00073   } mRecord;
00074 
00075   FILE*       mFilePtr;
00076   char const* mFileNameStr;
00077   bool        mIsLarge;
00078 
00079 private:
00080   // Prevent default construction and copying
00081   NeighboursBinaryFileWriter();
00082   NeighboursBinaryFileWriter(NeighboursBinaryFileWriter const& aCopy);
00083   NeighboursBinaryFileWriter& operator=
00084                                 (NeighboursBinaryFileWriter const& aCopy);
00085 };
00086 //-----------------------------------------------------------------------------
00087 #endif
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3