]> OCCT Git - occt-copy.git/commitdiff
Fixing regressions (CmpFile only):
authorabv <abv@opencascade.com>
Fri, 18 Sep 2015 06:25:55 +0000 (09:25 +0300)
committerpdn <pdn@opencascade.com>
Fri, 18 Sep 2015 07:33:37 +0000 (10:33 +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 1cfa233335144e608d4e05f76d9bba9a3168b60f..c7c7e4f67aa4924ab3ce2155ce14f2fcf62fe376 100644 (file)
@@ -183,8 +183,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;
@@ -242,9 +242,9 @@ void FSD_CmpFile::ReadLine(TCollection_AsciiString& buffer)
     {
       buffer += '\0';
       IsEnd = Standard_True;
+    }
   }
 }
-}
 
 //=======================================================================
 //function : WriteExtendedLine
@@ -429,10 +429,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);
 }
 
 //=======================================================================
@@ -442,12 +439,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);
 }
 
 //=======================================================================
@@ -457,12 +449,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);
 }
 
 //=======================================================================
@@ -472,8 +459,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;
@@ -486,8 +474,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;
@@ -500,8 +491,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;
@@ -514,8 +506,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;
@@ -1248,29 +1241,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 bfe1ce34f79e9aa7f50fb26515fc4a8a9220b307..0ffbef9620f15b4a6a652827f304dae91a2572b5 100644 (file)
@@ -81,48 +81,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 cf9da11ce0628b9c82889e29f3975ab06f8ae6f4..675ed4b663d107d0a00bc41b8816ad48a21922f6 100644 (file)
@@ -97,6 +97,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);
     }
   }