0031353: TDocStd_Application does not have api to set progress indicator
[occt.git] / src / PCDM / PCDM_ReadWriter_1.cxx
index f0081f3..500f485 100644 (file)
@@ -16,7 +16,6 @@
 
 
 #include <CDM_Document.hxx>
-#include <CDM_MessageDriver.hxx>
 #include <CDM_MetaData.hxx>
 #include <CDM_ReferenceIterator.hxx>
 #include <OSD_Path.hxx>
@@ -25,6 +24,7 @@
 #include <PCDM_ReadWriter_1.hxx>
 #include <PCDM_Reference.hxx>
 #include <PCDM_TypeOfFileDriver.hxx>
+#include <Message_Messenger.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Type.hxx>
 #include <Storage_Data.hxx>
@@ -36,6 +36,8 @@
 #include <TColStd_SequenceOfExtendedString.hxx>
 #include <UTL.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(PCDM_ReadWriter_1,PCDM_ReadWriter)
+
 #define START_REF "START_REF"
 #define END_REF "END_REF"
 #define START_EXT "START_EXT"
@@ -54,7 +56,7 @@ static Standard_Integer RemoveExtraSeparator(TCollection_AsciiString& aString) {
   Standard_Integer i, j, len ;
 
   len = aString.Length() ;
-#ifdef WNT
+#ifdef _WIN32
   // Case of network path, such as \\MACHINE\dir
   for (i = j = 2 ; j <= len ; i++,j++) {
 #else
@@ -75,7 +77,7 @@ static TCollection_AsciiString AbsolutePath(
                             const TCollection_AsciiString& aRelFilePath)
 {
   TCollection_AsciiString EmptyString = "" ;
-#ifdef WNT
+#ifdef _WIN32
   if (aRelFilePath.Search(":") == 2 ||
       (aRelFilePath.Search("\\") == 1 && aRelFilePath.Value(2) == '\\'))
 #else
@@ -86,7 +88,7 @@ static TCollection_AsciiString AbsolutePath(
   TCollection_AsciiString DirPath = aDirPath, RelFilePath = aRelFilePath  ;
   Standard_Integer i,len ;
   
-#ifdef WNT
+#ifdef _WIN32
   if(DirPath.Search(":") != 2 &&
      (DirPath.Search("\\") != 1 || DirPath.Value(2) != '\\'))
 #else
@@ -94,7 +96,7 @@ static TCollection_AsciiString AbsolutePath(
 #endif
     return EmptyString ;
 
-#ifdef WNT
+#ifdef _WIN32
   DirPath.ChangeAll('\\','/') ;
   RelFilePath.ChangeAll('\\','/') ;      
 #endif
@@ -125,7 +127,7 @@ static TCollection_AsciiString GetDirFromFile(const TCollection_ExtendedString&
   TCollection_AsciiString theCFile(aFileName);
   TCollection_AsciiString theDirectory;
   Standard_Integer i=theCFile.SearchFromEnd("/");
-#ifdef WNT    
+#ifdef _WIN32    
 //    if(i==-1) i=theCFile.SearchFromEnd("\\");
   if(theCFile.SearchFromEnd("\\") > i)
     i=theCFile.SearchFromEnd("\\");
@@ -222,13 +224,13 @@ void PCDM_ReadWriter_1::WriteVersion(const Handle(Storage_Data)& aData, const Ha
 //purpose  : 
 //=======================================================================
 
-Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver) const {
+Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_ExtendedString& aFileName, const Handle(Message_Messenger)& theMsgDriver) const {
 
   static Standard_Integer theReferencesCounter ;
   theReferencesCounter=0;
   static Standard_Integer i ;
 
-  PCDM_BaseDriverPointer theFileDriver;
+  Handle(Storage_BaseDriver) theFileDriver;
   TCollection_AsciiString aFileNameU(aFileName);
   if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
     return theReferencesCounter;
@@ -238,32 +240,35 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_Exten
 
   try {
     OCC_CATCH_SIGNALS
-    PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
+    PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
     theFileIsOpen=Standard_True;
    
     Handle(Storage_Schema) s = new Storage_Schema;
-    Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
-    const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
+    Storage_HeaderData hd;
+    hd.Read (theFileDriver);
+    const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
     
     for ( i =1; i<=  refUserInfo.Length() ; i++) {
       if(refUserInfo(i).Search(REFERENCE_COUNTER) != -1) {
        try { OCC_CATCH_SIGNALS theReferencesCounter=refUserInfo(i).Token(" ",2).IntegerValue();}
-       catch (Standard_Failure) { 
-//       cout << "warning: could not read the reference counter in " << aFileName << endl;
+    catch (Standard_Failure const&) {
+//       std::cout << "warning: could not read the reference counter in " << aFileName << std::endl;
          TCollection_ExtendedString aMsg("Warning: ");
          aMsg = aMsg.Cat("could not read the reference counter in ").Cat(aFileName).Cat("\0");
          if(!theMsgDriver.IsNull()) 
-           theMsgDriver->Write(aMsg.ToExtString());
+           theMsgDriver->Send(aMsg.ToExtString());
        }
       }
     }
     
   }
-  catch (Standard_Failure) {}
+  catch (Standard_Failure const&) {}
 
-  if(theFileIsOpen)  theFileDriver->Close();
+  if(theFileIsOpen)
+  {
+    theFileDriver->Close();
+  }
 
-  delete theFileDriver;
   return theReferencesCounter;
 }
   
@@ -272,7 +277,7 @@ Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_Exten
 //purpose  : 
 //=======================================================================
 
-void PCDM_ReadWriter_1::ReadReferences(const TCollection_ExtendedString& aFileName, PCDM_SequenceOfReference& theReferences, const Handle(CDM_MessageDriver)& theMsgDriver) const  {
+void PCDM_ReadWriter_1::ReadReferences(const TCollection_ExtendedString& aFileName, PCDM_SequenceOfReference& theReferences, const Handle(Message_Messenger)& theMsgDriver) const  {
 
   TColStd_SequenceOfExtendedString ReadReferences;
   
@@ -302,10 +307,10 @@ void PCDM_ReadWriter_1::ReadReferences(const TCollection_ExtendedString& aFileNa
        if(!theAbsolutePath.IsEmpty()) thePath=theAbsolutePath;
       }
       if(!theMsgDriver.IsNull()) {
-//      cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion;
+//      std::cout << "reference found; ReferenceIdentifier: " << theReferenceIdentifier << "; File:" << thePath << ", version:" << theDocumentVersion;
        TCollection_ExtendedString aMsg("Warning: ");
        aMsg = aMsg.Cat("reference found; ReferenceIdentifier:  ").Cat(theReferenceIdentifier).Cat("; File:").Cat(thePath).Cat(", version:").Cat(theDocumentVersion).Cat("\0");
-       theMsgDriver->Write(aMsg.ToExtString());
+       theMsgDriver->Send(aMsg.ToExtString());
       }
       TCollection_ExtendedString aPathW(thePath);
       theReferences.Append(PCDM_Reference (theReferenceIdentifier,aPathW,theDocumentVersion));
@@ -320,7 +325,7 @@ void PCDM_ReadWriter_1::ReadReferences(const TCollection_ExtendedString& aFileNa
 //purpose  : 
 //=======================================================================
 
-void PCDM_ReadWriter_1::ReadExtensions(const TCollection_ExtendedString& aFileName, TColStd_SequenceOfExtendedString& theExtensions, const Handle(CDM_MessageDriver)& theMsgDriver) const {
+void PCDM_ReadWriter_1::ReadExtensions(const TCollection_ExtendedString& aFileName, TColStd_SequenceOfExtendedString& theExtensions, const Handle(Message_Messenger)& theMsgDriver) const {
   
   ReadUserInfo(aFileName,START_EXT,END_EXT,theExtensions, theMsgDriver);
 }
@@ -335,18 +340,19 @@ void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName
                                      const TCollection_AsciiString& Start,
                                      const TCollection_AsciiString& End,
                                      TColStd_SequenceOfExtendedString& theUserInfo,
-                                     const Handle(CDM_MessageDriver)&) {
-
+                                     const Handle(Message_Messenger)&)
+{
   static Standard_Integer i ;
-  PCDM_BaseDriverPointer theFileDriver;
+  Handle(Storage_BaseDriver) theFileDriver;
   TCollection_AsciiString aFileNameU(aFileName);
   if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
     return;
 
-  PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
+  PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
   Handle(Storage_Schema) s = new Storage_Schema;
-  Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
-  const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
+  Storage_HeaderData hd;
+  hd.Read (theFileDriver);
+  const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
 
   Standard_Integer debut=0,fin=0;
   
@@ -362,7 +368,6 @@ void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName
     }
   }
   theFileDriver->Close();
-  delete theFileDriver;
 }
 
 //=======================================================================
@@ -370,12 +375,12 @@ void PCDM_ReadWriter_1::ReadUserInfo(const TCollection_ExtendedString& aFileName
 //purpose  : 
 //=======================================================================
 
-Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_ExtendedString& aFileName, const Handle(CDM_MessageDriver)& theMsgDriver) const {
+Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_ExtendedString& aFileName, const Handle(Message_Messenger)& theMsgDriver) const {
 
   static Standard_Integer theVersion ;
   theVersion=-1;
 
-  PCDM_BaseDriverPointer theFileDriver;
+  Handle(Storage_BaseDriver) theFileDriver;
   TCollection_AsciiString aFileNameU(aFileName);
   if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
     return theVersion;
@@ -385,31 +390,35 @@ Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_Extend
 
   try {
     OCC_CATCH_SIGNALS
-    PCDM_ReadWriter::Open(*theFileDriver,aFileName,Storage_VSRead);
+    PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
     theFileIsOpen=Standard_True;
     Handle(Storage_Schema) s = new Storage_Schema;
-    Handle(Storage_HeaderData) hd = s->ReadHeaderSection(*theFileDriver);
-    const TColStd_SequenceOfAsciiString &refUserInfo = hd->UserInfo();
+    Storage_HeaderData hd;
+    hd.Read (theFileDriver);
+    const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
 
     static Standard_Integer i ;
     for ( i =1; i<=  refUserInfo.Length() ; i++) {
       if(refUserInfo(i).Search(MODIFICATION_COUNTER) != -1) {
        try { OCC_CATCH_SIGNALS theVersion=refUserInfo(i).Token(" ",2).IntegerValue();}
-       catch (Standard_Failure) { 
-//       cout << "warning: could not read the version in " << aFileName << endl;
+    catch (Standard_Failure const&) {
+//       std::cout << "warning: could not read the version in " << aFileName << std::endl;
          TCollection_ExtendedString aMsg("Warning: ");
          aMsg = aMsg.Cat("could not read the version in ").Cat(aFileName).Cat("\0");
          if(!theMsgDriver.IsNull()) 
-           theMsgDriver->Write(aMsg.ToExtString());
+           theMsgDriver->Send(aMsg.ToExtString());
        }
 
       }
     }
   }
 
-  catch (Standard_Failure) {}
+  catch (Standard_Failure const&) {}
+
+  if(theFileIsOpen)
+  {
+    theFileDriver->Close();
+  }
 
-  if(theFileIsOpen) theFileDriver->Close();
-  delete theFileDriver;
   return theVersion;
 }