]> OCCT Git - occt-copy.git/commitdiff
Fixing regressions (CmpFile only): CR26229-OCCT690
authorabv <abv@opencascade.com>
Fri, 18 Sep 2015 06:25:55 +0000 (09:25 +0300)
committerabv <abv@opencascade.com>
Fri, 18 Sep 2015 06:25:55 +0000 (09:25 +0300)
- Returned lost setting of precision and locale in file stream
- Disable FSD_CmpFile::FlushEndOfLine() to avoid eating lines
- Reimplement writing reals to keep precision (and simplified other types)

src/FSD/FSD_CmpFile.cxx
src/FSD/FSD_File.cxx
src/Storage/Storage_File.cxx

index 3e669590cf5a4cb6ba4353882bcf18969612be9c..a5303f5158882b7097c261a1d14a6e2b34d1cc54 100644 (file)
@@ -176,8 +176,8 @@ const Standard_CString FSD_CmpFile::MagicNumber()
 
 void FSD_CmpFile::FlushEndOfLine()
 {
-  TCollection_AsciiString aDummy;
-  ReadLine (aDummy); // flush is nothing more than to read till the line-break
+//  TCollection_AsciiString aDummy;
+//  ReadLine (aDummy); // flush is nothing more than to read till the line-break
   /*
   static char Buffer[8192];
   char c;
@@ -235,9 +235,9 @@ void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
     {
       buffer += '\0';
       IsEnd = Standard_True;
+    }
   }
 }
-}
 
 //=======================================================================
 //function : WriteExtendedLine
@@ -422,10 +422,7 @@ void FSD_CmpFile::SkipObject()
 
 Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
 {
-  TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
-    Storage_StreamWriteError::Raise();
-  return *this;
+  return PutInteger (aValue);
 }
 
 //=======================================================================
@@ -435,12 +432,7 @@ Storage_BaseDriver& FSD_CmpFile::PutReference(const Standard_Integer aValue)
 
 Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
 {
-  Standard_Integer i = aValue;
-  TCollection_AsciiString aStr = TCollection_AsciiString( i ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
-    Storage_StreamWriteError::Raise();
-
-  return *this;
+  return PutInteger (aValue);
 }
 
 //=======================================================================
@@ -450,12 +442,7 @@ Storage_BaseDriver& FSD_CmpFile::PutCharacter(const Standard_Character aValue)
 
 Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aValue)
 {
-  Standard_Integer i = aValue;
-  TCollection_AsciiString aStr = TCollection_AsciiString( i ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
-    Storage_StreamWriteError::Raise();
-
-  return *this;
+  return PutInteger (aValue);
 }
 
 //=======================================================================
@@ -465,8 +452,9 @@ Storage_BaseDriver& FSD_CmpFile::PutExtCharacter(const Standard_ExtCharacter aVa
 
 Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
 {
-  TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
+  char buffer[256];
+  Standard_Size aLen = sprintf (buffer, "%d ", aValue);
+  if ( Device()->Write (buffer, aLen ) != aLen )
     Storage_StreamWriteError::Raise();
 
   return *this;
@@ -479,8 +467,11 @@ Storage_BaseDriver& FSD_CmpFile::PutInteger(const Standard_Integer aValue)
 
 Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
 {
-  TCollection_AsciiString aStr = TCollection_AsciiString( (Standard_Integer)aValue ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
+  char buffer[3];
+  buffer[0] = (aValue ? '1' : '0');
+  buffer[1] = ' ';
+  buffer[2] = '\0';
+  if ( Device()->Write (buffer, 2) != 2 )
     Storage_StreamWriteError::Raise();
 
   return *this;
@@ -493,8 +484,9 @@ Storage_BaseDriver& FSD_CmpFile::PutBoolean(const Standard_Boolean aValue)
 
 Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
 {
-  TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
+  char buffer[256];
+  Standard_Size aLen = sprintf (buffer, "%.17g ", aValue);
+  if ( Device()->Write (buffer, aLen ) != aLen )
     Storage_StreamWriteError::Raise();
 
   return *this;
@@ -507,8 +499,9 @@ Storage_BaseDriver& FSD_CmpFile::PutReal(const Standard_Real aValue)
 
 Storage_BaseDriver& FSD_CmpFile::PutShortReal(const Standard_ShortReal aValue)
 {
-  TCollection_AsciiString aStr = TCollection_AsciiString( aValue ) + " ";
-  if ( Device()->Write( (Standard_Address)aStr.ToCString(), aStr.Length() ) != (Standard_Size)aStr.Length() )
+  char buffer[256];
+  Standard_Size aLen = sprintf (buffer, "%.8g ", (double)aValue);
+  if ( Device()->Write (buffer, aLen ) != aLen )
     Storage_StreamWriteError::Raise();
 
   return *this;
@@ -1241,29 +1234,10 @@ Storage_Error FSD_CmpFile::BeginReadDataSection()
 void FSD_CmpFile::ReadPersistentObjectHeader(Standard_Integer& aRef,
                                          Standard_Integer& aType) 
 {
-  char c;
-
-  Device()->Read( (Standard_Address)&c, sizeof( char ) );
-
-  while (c != '#') {
-    if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
-      Storage_StreamFormatError::Raise();
-    }
-    Device()->Read( (Standard_Address)&c, sizeof( char ) );
-  }
-
-  GetInteger (aRef);
-
-  Device()->Read( (Standard_Address)&c, sizeof( char ) );
-
-  while (c != '%') {
-    if (IsEnd() || (c != ' ') || (c == '\r')|| (c == '\n')) {
-      Storage_StreamFormatError::Raise();
-    }
-    Device()->Read( (Standard_Address)&c, sizeof( char ) );
-  }
-
-  GetInteger (aType);
+  TCollection_AsciiString buffer;
+  ReadWord (buffer);
+  if (sscanf (buffer.ToCString(), "#%d%%%d", &aRef, &aType) !=2)
+    Storage_StreamFormatError::Raise();
 }
 
 //=======================================================================
index d120154996e386781118240f13ce4c5c32511079..c99b5a778f26f66e89d14001ef192e1f5dfc479e 100644 (file)
@@ -73,48 +73,6 @@ Storage_Error FSD_File::Open(const Handle(Storage_IODevice)& aDevice, const Stor
     return Storage_VSOpenError;
 
   return Device()->Open(aMode);
-  /*
-  Storage_Error result = Storage_VSOk;
-
-  if (OpenMode() == Storage_VSNone) {
-
-#ifdef _WIN32
-    TCollection_ExtendedString aWName(aName);
-    if (aMode == Storage_VSRead) {
-      myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in); // ios::nocreate is not portable
-    }
-    else if (aMode == Storage_VSWrite) {
-      myStream.open( (const wchar_t*) aWName.ToExtString(),ios::out);
-    }
-    else if (aMode == Storage_VSReadWrite) {
-      myStream.open( (const wchar_t*) aWName.ToExtString(),ios::in|ios::out);
-#else
-    if (aMode == Storage_VSRead) {
-      myStream.open(aName.ToCString(),ios::in); // ios::nocreate is not portable
-    }
-    else if (aMode == Storage_VSWrite) {
-      myStream.open(aName.ToCString(),ios::out);
-    }
-    else if (aMode == Storage_VSReadWrite) {
-      myStream.open(aName.ToCString(),ios::in|ios::out);
-#endif
-    }
-    
-    if (myStream.fail()) {
-      result = Storage_VSOpenError;
-    }
-    else {
-      myStream.precision(17);
-      myStream.imbue (std::locale::classic()); // use always C locale
-      SetOpenMode(aMode);
-    }
-  }
-  else {
-    result = Storage_VSAlreadyOpen;
-  }
-
-  return result;
-  */
 }
 
 //=======================================================================
index 5e8cdcb31ec33f9a1296a163966cc7310406b0cf..66c10dbfd62597b14edf07df916cd9422bbe7e19 100644 (file)
@@ -99,6 +99,8 @@ Storage_Error Storage_File::Open (const Storage_OpenMode theMode)
     }
     else
     {
+      myStream.precision(17);
+      myStream.imbue (std::locale::classic()); // use always C locale
       SetOpenMode (theMode);
     }
   }