+ ProgressMethodArgDelete = method;
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief Set the end method to call when the parsing of the directory ends
+ * @param method Method to call
+ * @param arg Argument to pass to the method
+ * @param argDelete Argument
+ * \warning In python : the arg parameter isn't considered
+ */
+void DicomDir::SetEndMethod(Method* method, void* arg,
+ Method* argDelete )
+{
+ if( EndArg && EndMethodArgDelete )
+ {
+ EndMethodArgDelete( EndArg );
+ }
+
+ EndMethod = method;
+ EndArg = arg;
+ EndMethodArgDelete = argDelete;
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief Set the method to delete the argument
+ * The argument is destroyed when the method is changed or when the class
+ * is destroyed
+ * @param method Method to call to delete the argument
+ */
+void DicomDir::SetEndMethodArgDelete(Method* method)
+{
+ EndMethodArgDelete = method;
+}
+
+/**
+ * \ingroup DicomDir
+ * \brief writes on disc a DICOMDIR
+ * \ warning does NOT add the missing elements in the header :
+ * it's up to the user doing it !
+ * \todo : to be re-written using the DICOMDIR tree-like structure
+ * *not* the chained list
+ * (does NOT exist if the DICOMDIR is user-forged !)
+ * @param fileName file to be written to
+ * @return false only when fail to open
+ */
+
+bool DicomDir::WriteDicomDir(std::string const& fileName)
+{
+ uint16_t sq[4] = { 0x0004, 0x1220, 0xffff, 0xffff };
+ uint16_t sqt[4]= { 0xfffe, 0xe0dd, 0xffff, 0xffff };
+
+ std::ofstream* fp = new std::ofstream(fileName.c_str(),
+ std::ios::out | std::ios::binary);
+ if( !fp )
+ {
+ printf("Failed to open(write) File [%s] \n", fileName.c_str());
+ return false;
+ }
+
+ uint8_t filePreamble[128];
+ memset(filePreamble, 0, 128);
+ fp->write((char*)filePreamble, 128);
+ fp->write("DICM",4);
+
+ DicomDirMeta *ptrMeta = GetDicomDirMeta();
+ ptrMeta->Write(fp, ExplicitVR);
+
+ // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta
+ fp->write((char*)&sq[0],8);
+
+ for(ListDicomDirPatient::iterator cc = Patients.begin();
+ cc != Patients.end();
+ ++cc )
+ {
+ (*cc)->Write( fp, ExplicitVR );
+ }
+
+ // force writing Sequence Delimitation Item
+ fp->write((char*)&sqt[0],8); // fffe e0dd ffff ffff
+
+ fp->close();
+ return true;