00001 00002 00003 00004 //----------------------------------------------------------------------------- 00005 // Initial version: 20/09/2005 00006 // CVS: $Revision: 2989 $, $Date: 2006-10-12 17:31:45 +0100 (Thu, 12 Oct 2006) $, $Author: rsc $ 00007 //----------------------------------------------------------------------------- 00008 #ifndef CROSSNEIGHBOURSBINARYFILEWRITER_DEFINED 00009 #define CROSSNEIGHBOURSBINARYFILEWRITER_DEFINED 00010 00011 #include "Datum.h" 00012 #include "FileObjectWriter.h" 00013 #include "FileUtil.h" 00014 #include "ObjectPairWriter.h" 00015 00016 class Object; 00017 //----------------------------------------------------------------------------- 00019 00023 class CrossNeighboursBinaryFileWriter : public ObjectPairWriter 00024 { 00025 public: 00030 CrossNeighboursBinaryFileWriter(char const* aFileNameStr, 00031 bool aIsLarge = false, 00032 bool aIsSwapped = false); 00033 virtual ~CrossNeighboursBinaryFileWriter() {} 00034 00036 virtual void open(); 00037 00039 virtual void close(); 00040 00045 virtual void write(Object const* aExternObjectPtr, 00046 Object const* aMainObjectPtr) 00047 { 00048 Datum const* mainDatumPtr = (Datum const*) aMainObjectPtr; 00049 Datum const* externDatumPtr = (Datum const*) aExternObjectPtr; 00050 if (!mIsSwapped) 00051 { 00052 mRecord.field.mainID = mainDatumPtr->getId(); 00053 mRecord.field.externalID = externDatumPtr->getId(); 00054 } 00055 else 00056 { 00057 mRecord.field.mainID = externDatumPtr->getId(); 00058 mRecord.field.externalID = mainDatumPtr->getId(); 00059 } 00060 mRecord.field.distanceMins = aMainObjectPtr-> 00061 gcDistanceMins(*aExternObjectPtr); 00062 fwrite(mRecord.bytes, sizeof(char), mcRecordSize, mFilePtr); 00063 } 00064 00065 protected: 00067 static const unsigned mcRecordSize = 20; 00068 00070 union { 00071 char bytes[mcRecordSize]; 00072 struct { 00073 long long mainID; 00074 long long externalID; 00075 float distanceMins; 00076 } field; 00077 } mRecord; 00078 00079 FILE* mFilePtr; 00080 char const* mFileNameStr; 00081 bool mIsLarge; 00082 bool mIsSwapped; 00083 00084 private: 00085 // Prevent default construction and copying 00086 CrossNeighboursBinaryFileWriter(); 00087 CrossNeighboursBinaryFileWriter(CrossNeighboursBinaryFileWriter const& aCopy); 00088 CrossNeighboursBinaryFileWriter& operator= 00089 (CrossNeighboursBinaryFileWriter const& aCopy); 00090 }; 00091 //----------------------------------------------------------------------------- 00092 #endif