]> OCCT Git - occt-copy.git/commitdiff
Bug fixes in binary format storage and other improvements. CR26229_V6_7_1p1
authorstv <stv@opencascade.com>
Wed, 27 May 2015 17:56:26 +0000 (20:56 +0300)
committerstv <stv@opencascade.com>
Wed, 27 May 2015 17:56:26 +0000 (20:56 +0300)
13 files changed:
src/BinLDrivers/BinLDrivers_DocumentStorageDriver.cxx
src/BinObjMgt/BinObjMgt_Persistent.cxx
src/CDF/CDF_Store.cxx
src/Storage/Storage.cdl
src/Storage/Storage_File.cdl
src/Storage/Storage_File.cxx
src/Storage/Storage_IODevice.cdl
src/Storage/Storage_IODevice.cxx
src/Storage/Storage_IStream.cdl
src/Storage/Storage_IStream.cxx
src/Storage/Storage_OStream.cdl
src/Storage/Storage_OStream.cxx
src/XmlLDrivers/XmlLDrivers_DocumentStorageDriver.cxx

index 911b7921de2ab2fe4ac09421111eee2d27b2a767..a6210cb206d52bc365389e12bcce9af044cd1796 100644 (file)
@@ -100,29 +100,15 @@ void BinLDrivers_DocumentStorageDriver::Write
         return;
     }
 
-    theDevice->Open( Storage_VSWrite );
+    theDevice->Open( Storage_VSAppend );
+    Standard_Size aP = theDevice->Tell();
 
-    /*
-#if defined(_WIN32)
-    ofstream anOS ((const wchar_t*) theFileName.ToExtString(), ios::in | ios::binary | ios::ate);
-#elif !defined(IRIX) // 10.10.2005
-    ofstream anOS (aFileName.ToCString(), ios::in | ios::binary | ios::ate);
-#else
-    ofstream anOS (aFileName.ToCString(), ios::ate);
-    //ofstream anOS (aFileName.ToCString(), ios::out| ios::binary | ios::ate);
-#endif
-#ifdef DEB
-    const Standard_Integer aP = (Standard_Integer) anOS.tellp();
-    cout << "POS = " << aP <<endl;
-#endif
-//#endif
-*/
     if (theDevice->CanWrite()) {
 
 //  2. Write the Table of Contents of Sections
-      BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections);
-      for (; anIterS.More(); anIterS.Next())
-        anIterS.ChangeValue().WriteTOC (theDevice);
+    BinLDrivers_VectorOfDocumentSection::Iterator anIterS (mySections);
+    for (; anIterS.More(); anIterS.Next())
+      anIterS.ChangeValue().WriteTOC (theDevice);
 
       // Shapes Section is the last one, it indicates the end of the table.
       BinLDrivers_DocumentSection aShapesSection (SHAPESECTION_POS,
@@ -172,12 +158,14 @@ void BinLDrivers_DocumentStorageDriver::Write
       WriteMessage (anErrorStr + "BinLDrivers_DocumentStorageDriver, Problem with the file stream.";
 #else
       TCollection_ExtendedString aStr =
-        anErrorStr + aMethStr + "Problem writing the file ";
-      WriteMessage (aStr + theFileName);
+        anErrorStr + aMethStr + "Problem writing the file.";
+      WriteMessage (aStr);
 #endif
       SetIsError(Standard_True);
       SetStoreStatus(PCDM_SS_WriteFailure);
     }
+
+    theDevice->Close();
   }
 }
 
@@ -368,7 +356,6 @@ void BinLDrivers_DocumentStorageDriver::WriteInfoSection
   if (aFileDriver.Open( theDevice, Storage_VSWrite ) != Storage_VSOk) {
     WriteMessage (TCollection_ExtendedString("Error: Cannot open the device ") +
                   theDevice->Name());
-#endif
     SetIsError(Standard_True);
     return;
   }
index fba4784f037d80b48ef64fcd192ba7273cb9b8fa..c5e49cf34d3d6c706731c8dcd44bcf7c869dabce 100644 (file)
@@ -111,16 +111,25 @@ Standard_OStream& BinObjMgt_Persistent::Write (Standard_OStream& theOS)
 
 void BinObjMgt_Persistent::Write (const Handle(Storage_IODevice)& theDevice)
 {
-  if (!theDevice->CanWrite())
-  {
-    return;
-  }
-
-  Handle(Storage_OStream) aStream = Handle(Storage_OStream)::DownCast(theDevice);
-  if (!aStream.IsNull())
+  Standard_Integer nbWritten = 0;
+  Standard_Integer *aData = (Standard_Integer*) myData(1);
+  // update data length
+  aData[2] = mySize - BP_HEADSIZE;
+#if DO_INVERSE
+  aData[0] = InverseInt (aData[0]);
+  aData[1] = InverseInt (aData[1]);
+  aData[2] = InverseInt (aData[2]);
+#endif
+  for (Standard_Integer i=1; theDevice->CanWrite() && nbWritten < mySize && i <= myData.Length(); i++)
   {
-    Write (*aStream->Stream());
+    Standard_Integer nbToWrite = Min(mySize - nbWritten, BP_PIECESIZE);
+    theDevice->Write( (char*)myData(i), nbToWrite );
+    nbWritten += nbToWrite;
   }
+  myIndex = 1;
+  myOffset = BP_HEADSIZE;
+  mySize = BP_HEADSIZE;
+  myIsError = Standard_False;
 }
 
 //=======================================================================
index c4fe046cfde41414c1a68755c62cca8eddb764ad..7b276b7fdf47bc82bfe7505e9d98097a013b5416 100644 (file)
@@ -109,90 +109,24 @@ Standard_ExtString CDF_Store::Name() const {
 }
 
 Standard_Boolean CDF_Store::SetDevice(const Handle(Storage_IODevice)& aDevice) {
-  /*
-  TCollection_ExtendedString theFolder(aFolder);
-  Standard_Integer l = theFolder.Length();
-
-  // if the last character is the folder separator (which is always the first character)
-  // it is removed.
-       // This is correct for Unix systems but not for Windows! VMS and MAC? Thomas Haller, 23.11.01
-  if(l > 1) {
-#ifndef WNT
-    if(theFolder.Value(l) == theFolder.Value(1)) theFolder.Trunc(l-1);
-#else
-       if (theFolder.Value(l) == '/' || theFolder.Value(l) == '\\')
-               theFolder.Trunc(l-1);
-#endif
-  }
-
-  if(theMetaDataDriver->FindFolder(theFolder))  {
-  */
-    myCurrentDocument->SetRequestedDevice(aDevice);
-    return Standard_True;
-    /*
-  }
-  return Standard_False;
-    */
+  myCurrentDocument->SetRequestedDevice(aDevice);
+  return Standard_True;
 }
 
 CDF_StoreSetNameStatus CDF_Store::RecheckName () {
   //   return SetName(myCurrentDocument->RequestedName());
   return CDF_SSNS_OK;
 }
-/*
-CDF_StoreSetNameStatus CDF_Store::SetName(const TCollection_ExtendedString&  aName)
-{
-  TCollection_ExtendedString theName=theMetaDataDriver->SetName(myCurrentDocument,aName);
-
-  if(myCurrentDocument->IsStored ()) { 
-    Handle(CDM_MetaData)  E = myCurrentDocument->MetaData();
-    if(   E->Folder() == myCurrentDocument->RequestedFolder() 
-       && E->Name()   == theName) return CDF_SSNS_OK;
-  }
-  
-  if(myCurrentDocument->HasRequestedFolder()) {
-    if (theMetaDataDriver->Find(myCurrentDocument->RequestedFolder(),theName)) {
-      if(theMetaDataDriver->MetaData(myCurrentDocument->RequestedFolder(),theName)->IsRetrieved())
-       return CDF_SSNS_OpenDocument;
-      else {
-       myCurrentDocument->SetRequestedName(theName);
-       return CDF_SSNS_ReplacingAnExistentDocument;
-      }
-    }
-  }
-  myCurrentDocument->SetRequestedName(theName);
-  return  CDF_SSNS_OK;
-}
-
-CDF_StoreSetNameStatus CDF_Store::SetName(const Standard_ExtString aName)
-{
-  TCollection_ExtendedString theName(aName);
-  return SetName(theName);
-}
-*/
 
 void CDF_Store::Realize() {
   Standard_ProgramError_Raise_if(!myList->IsConsistent(),"information are missing");
   Handle(CDM_MetaData) m;
   myText = "";
 
-  myCurrentDocument->RequestedDevice()->Open (Storage_VSWrite);
   myStatus = myList->Store(m,myText);
-  myCurrentDocument->RequestedDevice()->Close();
-}
-/*
-Standard_ExtString CDF_Store::Path() const {
-  return myPath.ToExtString();
 }
-*/
 
 Handle(Storage_IODevice) CDF_Store::MetaDataDevice() const {
-  /*
-  static TCollection_ExtendedString retv;
-  retv="";
-  if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
-  return retv.ToExtString();
-  */
   return myCurrentDocument->MetaData()->Device();
 }
 
index e09500ebf8c838d8ab2a5cc62676512276f85752..997520686d83bf0605f34ce6612ad2f340ff847a 100644 (file)
@@ -86,12 +86,20 @@ is
        -- -   Storage_VSInternalError : an internal error  has been detected
        -- -   Storage_VSExtCharParityError : an error
        --   has occurred while reading 16 bit characte   
+
+    enumeration SeekMode
+    is
+        SMBegin,
+       SMCur,
+       SMEnd
+    end;
+
     enumeration OpenMode
     is
         VSNone,
        VSRead,
        VSWrite,
+       VSAppend,
        VSReadWrite
     end;
        ---Purpose:
index 567d241ba22b23424735c10c95a48209ee384bbe..b45a5fa7bd0207e61b78d471091fc20e87ad0e01 100644 (file)
@@ -19,6 +19,7 @@ class File from Storage inherits IODevice from Storage
 uses Position    from Storage,
      AsciiString from TCollection,
      OpenMode    from Storage,
+     SeekMode    from Storage,
      Error       from Storage,
      FStream     from Standard,
      ExtendedString from TCollection
@@ -45,7 +46,8 @@ is
     Tell (me: mutable) returns Position from Storage is redefined;
     ---Purpose: returns a position in the device. Return -1 upon error.
 
-    Seek (me: mutable; thePos: Position from Storage) returns Boolean from Standard is redefined;
+    Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+    returns Boolean from Standard is redefined;
    
     Close (me: mutable) returns Boolean from Standard;
 
index 17282b80bdd9cd6b7af699b4fe1b1c17fe325bf1..5e8cdcb31ec33f9a1296a163966cc7310406b0cf 100644 (file)
@@ -79,15 +79,19 @@ Storage_Error Storage_File::Open (const Storage_OpenMode theMode)
   {
     if (theMode == Storage_VSRead)
     {
-      myStream.open(aFilePath, ios::in | ios::binary );
+      myStream.open( aFilePath, ios::in | ios::binary );
     }
     else if (theMode == Storage_VSWrite)
     {
-      myStream.open(aFilePath, ios::out | ios::binary );
+      myStream.open( aFilePath, ios::out | ios::binary );
+    }
+    else if (theMode == Storage_VSAppend)
+    {
+      myStream.open( aFilePath, ios::in | ios::out | ios::binary | ios::ate );
     }
     else if (theMode == Storage_VSReadWrite)
     {
-      myStream.open(aFilePath, ios::in | ios::out);
+      myStream.open( aFilePath, ios::in | ios::out | ios::binary );
     }
     
     if (!myStream.rdbuf()->is_open()) {
@@ -128,12 +132,27 @@ Storage_Position Storage_File::Tell()
 //function : Seek
 //purpose  : 
 //=======================================================================
-Standard_Boolean Storage_File::Seek (const Storage_Position& thePos)
+Standard_Boolean Storage_File::Seek (const Storage_Position& thePos, const Storage_SeekMode aMode)
 {
+  ios::seekdir dir = ios::beg;
+  switch ( aMode )
+  {
+  case Storage_SMEnd:
+    dir = ios::end;
+    break;
+  case Storage_SMCur:
+    dir = ios::cur;
+    break;
+  case Storage_SMBegin:
+  default:
+    dir = ios::beg;
+    break;
+  }
+
   if ( OpenMode() == Storage_VSRead )
-    myStream.seekg( thePos );
+    myStream.seekg( thePos, dir );
   else
-    myStream.seekp( thePos );
+    myStream.seekp( thePos, dir );
 
   return !myStream.fail();
 }
@@ -166,7 +185,7 @@ Standard_Boolean Storage_File::CanRead() const
 //=======================================================================
 Standard_Boolean Storage_File::CanWrite() const
 {
-  return myStream.good() && ( OpenMode() == Storage_VSWrite || OpenMode() == Storage_VSReadWrite );
+  return myStream.good() && ( OpenMode() == Storage_VSWrite || OpenMode() == Storage_VSAppend || OpenMode() == Storage_VSReadWrite );
 }
 
 //=======================================================================
index de50507305b2fb0feb8c9c98ad11fe853598f498..52ad5a42d08acd21ed648ad9dbf3f35c2ef2936f 100644 (file)
@@ -21,6 +21,7 @@ uses Position    from Storage,
      AsciiString from TCollection,
      OpenMode    from Storage,
      Error       from Storage,
+     SeekMode    from Storage,
      ExtendedString from TCollection,
      SequenceOfAsciiString from TColStd,
      SequenceOfExtendedString from TColStd
@@ -48,7 +49,8 @@ is
     Tell( me : mutable ) returns Position from Storage is deferred;
     ---Purpose: return position in the device. Return -1 upon error.
 
-    Seek( me: mutable; aPos : Position from Storage ) returns Boolean from Standard is deferred;
+    Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+    returns Boolean from Standard is deferred;
     ---Purpose: Set new absolute position within the stream
    
     Close(me : mutable) returns Boolean from Standard is deferred;
index cadc7329a6516f801372f53fee641ee427e7769b..515f75a15efb699668154a59b97eeab0e129e48d 100644 (file)
@@ -38,7 +38,8 @@ void Storage_IODevice::ReadLine( Standard_CString& aBuffer, const Standard_Integ
   {
     Standard_Character c;
     Read( &c, sizeof( Standard_Character ) );
-    if ( aFin = ( c == anEndSymbol ) )
+    aFin = ( c == anEndSymbol );
+    if ( aFin )
       aBuf[i++] = '\0';
     else
       aBuf[i++] = c;
index 215d6d1a87e273ae6c6f0ae07808f1c1317f5970..8f1419a1cf5e17da685b91e53fbe7230d695578c 100644 (file)
@@ -19,6 +19,7 @@ class IStream from Storage inherits IODevice from Storage
 uses Position       from Storage,
      AsciiString    from TCollection,
      OpenMode       from Storage,
+     SeekMode       from Storage,
      Error          from Storage,
      IStream        from Standard,
      IStreamPtr     from Standard,
@@ -46,7 +47,8 @@ is
     Tell (me: mutable) returns Position from Storage is redefined;
     ---Purpose: returns a position in the device. Return -1 upon error.
 
-    Seek (me: mutable; thePos: Position from Storage) returns Boolean from Standard is redefined;
+    Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+    returns Boolean from Standard is redefined;
    
     Close (me: mutable) returns Boolean from Standard;
 
index 3e1293c9678e5e03fb330f83264e87ed20fba0c8..c91f1df2f0663956d4d1a5f54cb3c2a01547f38b 100644 (file)
@@ -102,9 +102,21 @@ Storage_Position Storage_IStream::Tell()
 //function : Seek
 //purpose  : 
 //=======================================================================
-Standard_Boolean Storage_IStream::Seek (const Storage_Position& thePos)
+Standard_Boolean Storage_IStream::Seek (const Storage_Position& thePos, const Storage_SeekMode aMode )
 {
-  myStream->seekg (thePos);
+  switch ( aMode )
+  {
+  case Storage_SMEnd:
+    myStream->seekg(thePos, ios::end);
+    break;
+  case Storage_SMCur:
+    myStream->seekg(thePos, ios::cur);
+    break;
+  case Storage_SMBegin:
+  default:
+    myStream->seekg(thePos, ios::beg);
+    break;
+  }
 
   return !myStream->fail();
 }
index 3ebf37794074464b88187d9ca0b0a9d0b1406144..a3a364ea7a14300a1b15c9d83d4e5c00d734e216 100644 (file)
@@ -19,6 +19,7 @@ class OStream from Storage inherits IODevice from Storage
 uses Position       from Storage,
      AsciiString    from TCollection,
      OpenMode       from Storage,
+     SeekMode       from Storage,
      Error          from Storage,
      OStream        from Standard,
      OStreamPtr     from Standard,
@@ -46,7 +47,8 @@ is
     Tell (me: mutable) returns Position from Storage is redefined;
     ---Purpose: returns a position in the device. Return -1 upon error.
 
-    Seek (me: mutable; thePos: Position from Storage) returns Boolean from Standard is redefined;
+    Seek( me: mutable; aPos : Position from Storage; aMode: SeekMode from Storage = Storage_SMBegin )
+    returns Boolean from Standard is redefined;
    
     Close (me: mutable) returns Boolean from Standard;
 
index 0616d0b7302dac8cd55fc0f3442d42f7fb5e20b0..930760fb9d08789c8bcf133a352da3b54583aba8 100644 (file)
@@ -50,7 +50,7 @@ TCollection_ExtendedString Storage_OStream::Name() const
 //=======================================================================
 Storage_Error Storage_OStream::Open (const Storage_OpenMode theMode)
 {
-  if (theMode != Storage_VSWrite)
+  if (theMode != Storage_VSWrite || theMode != Storage_VSAppend)
   {
     return Storage_VSOpenError;
   }
@@ -69,7 +69,10 @@ Storage_Error Storage_OStream::Open (const Storage_OpenMode theMode)
       
       // clear flags and set the position where the next character is to be inserted 
       myStream->clear();
-      myStream->seekp(0, ios::beg);
+      if ( theMode == Storage_VSWrite )
+        myStream->seekp(0, ios::beg);
+      else
+        myStream->seekp(0, ios::end);
     }
   }
   else
@@ -102,9 +105,21 @@ Storage_Position Storage_OStream::Tell()
 //function : Seek
 //purpose  : 
 //=======================================================================
-Standard_Boolean Storage_OStream::Seek (const Storage_Position& thePos)
+Standard_Boolean Storage_OStream::Seek (const Storage_Position& thePos, const Storage_SeekMode aMode )
 {
-  myStream->seekp (thePos);
+  switch ( aMode )
+  {
+  case Storage_SMEnd:
+    myStream->seekp(thePos, ios::end);
+    break;
+  case Storage_SMCur:
+    myStream->seekp(thePos, ios::cur);
+    break;
+  case Storage_SMBegin:
+  default:
+    myStream->seekp(thePos, ios::beg);
+    break;
+  }
 
   return !myStream->fail();
 }
index 30e9254a4b30c588e0d50a304306ea3a34fc2784..fdea2da6b48f9812f08c50a6ce8785eae72067d2 100644 (file)
@@ -115,16 +115,17 @@ void XmlLDrivers_DocumentStorageDriver::Write
 
   if (WriteToDomDocument (theDocument, anElement, theDevice) == Standard_False) {
     // Write DOM_Document into XML file,
-    //FILE * aFile = OSD_OpenFile(theFileName, "wt");
+    theDevice->Open( Storage_VSWrite );
 
     if (theDevice->CanWrite()) {
       LDOM_XmlWriter aWriter (theDevice);
       aWriter.SetIndentation(1);
       aWriter << aDOMDoc;
-      //fclose(aFile);
+      theDevice->Close();
       ::take_time (0, " +++++ Fin formatting to XML : ", aMessageDriver);
-
-    }else{
+    }
+    else
+    {
       SetIsError (Standard_True);
       TCollection_ExtendedString aMsg =
         TCollection_ExtendedString("Error: the device ") + theDevice->Name() +