0028691: Storage of Ocaf documents in XML file format in old document version
[occt.git] / src / XmlLDrivers / XmlLDrivers.cxx
index 372db4c..705f524 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <XmlLDrivers.ixx>
 
-#include <XmlLDrivers_DocumentStorageDriver.hxx>
+#include <CDM_MessageDriver.hxx>
+#include <Plugin_Macro.hxx>
+#include <Standard_GUID.hxx>
+#include <TDocStd_Application.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <XmlLDrivers.hxx>
 #include <XmlLDrivers_DocumentRetrievalDriver.hxx>
-#include <XmlMDF_ADriverTable.hxx>
-#include <XmlMDF.hxx>
+#include <XmlLDrivers_DocumentStorageDriver.hxx>
 #include <XmlMDataStd.hxx>
+#include <XmlMDF.hxx>
+#include <XmlMDF_ADriverTable.hxx>
 #include <XmlMDocStd.hxx>
 #include <XmlMFunction.hxx>
-#include <Standard_GUID.hxx>
 
 #include <locale.h>
 #include <time.h>
-#include <Plugin_Macro.hxx>
-
 static Standard_GUID XmlLStorageDriver  ("13a56820-8269-11d5-aab2-0050044b1af1");
 static Standard_GUID XmlLRetrievalDriver("13a56822-8269-11d5-aab2-0050044b1af1");
-#define CURRENT_DOCUMENT_VERSION 7
+
+static int CURRENT_DOCUMENT_VERSION(9);
 
 //=======================================================================
 //function : Factory
 //purpose  : PLUGIN FACTORY
 //=======================================================================
-Handle(Standard_Transient) XmlLDrivers::Factory(const Standard_GUID& theGUID)
+const Handle(Standard_Transient)& XmlLDrivers::Factory(const Standard_GUID& theGUID)
 {
   if (theGUID == XmlLStorageDriver)
   {
-#ifdef XMLLDRIVERS_DEB
+#ifdef OCCT_DEBUG
     cout << "XmlLDrivers : Storage Plugin" << endl;
 #endif
-    static Handle(XmlLDrivers_DocumentStorageDriver) model_sd =
+    static Handle(Standard_Transient) model_sd =
       new XmlLDrivers_DocumentStorageDriver
         ("Copyright: Open Cascade, 2001-2002"); // default copyright
     return model_sd;
@@ -51,16 +54,15 @@ Handle(Standard_Transient) XmlLDrivers::Factory(const Standard_GUID& theGUID)
 
   if (theGUID == XmlLRetrievalDriver)
   {
-#ifdef XMLLDRIVERS_DEB
+#ifdef OCCT_DEBUG
     cout << "XmlLDrivers : Retrieval Plugin" << endl;
 #endif
-    static Handle (XmlLDrivers_DocumentRetrievalDriver) model_rd =
+    static Handle (Standard_Transient) model_rd =
       new XmlLDrivers_DocumentRetrievalDriver ();
     return model_rd;
   }
  
-  Standard_Failure::Raise ("XmlLDrivers : unknown GUID");
-  return NULL;
+  throw Standard_Failure("XmlLDrivers : unknown GUID");
 }
 
 #define SLENGTH 80
@@ -76,7 +78,7 @@ TCollection_AsciiString XmlLDrivers::CreationDate ()
 
   if (time(&nowbin) == (time_t) - 1)
   {
-#ifdef XMLLDRIVERS_DEB
+#ifdef OCCT_DEBUG
     cerr << "Storage ERROR : Could not get time of day from time()" << endl;
 #endif
   }
@@ -85,7 +87,7 @@ TCollection_AsciiString XmlLDrivers::CreationDate ()
   
   if (strftime(nowstr, SLENGTH, "%Y-%m-%d", nowstruct) == (size_t) 0)
   {
-#ifdef XMLLDRIVERS_DEB
+#ifdef OCCT_DEBUG
     cerr << "Storage ERROR : Could not get string from strftime()" << endl;
 #endif
   }
@@ -93,6 +95,17 @@ TCollection_AsciiString XmlLDrivers::CreationDate ()
   return nowstr;
 }
 
+//=======================================================================
+//function : DefineFormat
+//purpose  : 
+//=======================================================================
+void XmlLDrivers::DefineFormat (const Handle(TDocStd_Application)& theApp)
+{
+  theApp->DefineFormat ("XmlLOcaf", "Xml Lite OCAF Document", "xmll",
+                        new XmlLDrivers_DocumentRetrievalDriver, 
+                        new XmlLDrivers_DocumentStorageDriver ("Copyright: Open Cascade, 2001-2002"));
+}
+
 //=======================================================================
 //function : AttributeDrivers
 //purpose  : 
@@ -115,15 +128,14 @@ Handle(XmlMDF_ADriverTable) XmlLDrivers::AttributeDrivers
 //purpose  : Document storage version
 //=======================================================================
 
-TCollection_AsciiString XmlLDrivers::StorageVersion()
+int XmlLDrivers::StorageVersion()
 {
-  TCollection_AsciiString aVersionStr (CURRENT_DOCUMENT_VERSION);
-  return aVersionStr;
+  return CURRENT_DOCUMENT_VERSION;
+}
+void XmlLDrivers::SetStorageVersion(const int version)
+{
+  CURRENT_DOCUMENT_VERSION = version;
 }
-
-#ifdef _MSC_VER
-#pragma warning(disable:4190) /* disable warning on C++ type returned by C function; should be OK for C++ usage */
-#endif
 
 // Declare entry point PLUGINFACTORY
 PLUGIN(XmlLDrivers)