]> OCCT Git - occt-copy.git/commitdiff
0031173: Point Cloud Rendering - Enable remote file systems as input and output for...
authoragv <agv@opencascade.com>
Fri, 22 Nov 2019 09:21:55 +0000 (12:21 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 18 Sep 2020 14:46:51 +0000 (17:46 +0300)
Make RWStl_Reader::IsAscii() accepting optional argument pointing how to rewind the input stream, using unget() or seekg(). This allows writing a reader that uses a stream supporting seekg but not supporting unget.

src/RWStl/RWStl_Reader.cxx
src/RWStl/RWStl_Reader.hxx

index e8514712db4431fa8bc3d37702229eff5e87b39c..b29bd3e01086c2da4b3bf93bf54e282a4ed7dde5 100644 (file)
@@ -149,7 +149,7 @@ Standard_Boolean RWStl_Reader::Read (const char* theFile,
   // (80 bytes header + 4 bytes facet count + 50 bytes for one facet);
   // thus assume files shorter than 134 as Ascii without probing
   // (probing may bring stream to fail state if EOF is reached)
-  bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (aStream));
+  bool isAscii = ((size_t)theEnd < THE_STL_MIN_FILE_SIZE || IsAscii (aStream, true));
 
   Standard_ReadLineBuffer aBuffer (THE_BUFFER_SIZE);
 
@@ -185,7 +185,8 @@ Standard_Boolean RWStl_Reader::Read (const char* theFile,
 //purpose  :
 //==============================================================================
 
-Standard_Boolean RWStl_Reader::IsAscii (Standard_IStream& theStream)
+Standard_Boolean RWStl_Reader::IsAscii (Standard_IStream& theStream,
+                                        const bool        isSeekgAvailable)
 {
   // read first 134 bytes to detect file format
   char aBuffer[THE_STL_MIN_FILE_SIZE];
@@ -196,10 +197,18 @@ Standard_Boolean RWStl_Reader::IsAscii (Standard_IStream& theStream)
     return true;
   }
 
-  // put back the read symbols
-  for (std::streamsize aByteIter = aNbRead; aByteIter > 0; --aByteIter)
+  if (isSeekgAvailable)
   {
-    theStream.unget();
+    // get back to the beginning
+    theStream.seekg(0, theStream.beg);
+  }
+  else
+  {
+    // put back the read symbols
+    for (std::streamsize aByteIter = aNbRead; aByteIter > 0; --aByteIter)
+    {
+      theStream.unget();
+    }
   }
 
   // if file is shorter than size of binary file with 1 facet, it must be ascii
index f1b2f2309b85b31918208ecb0af4b3680e5e534d..671f79d66f616c71a34a3594f32010eb75098d04 100644 (file)
@@ -45,9 +45,12 @@ public:
                                          const Message_ProgressRange& theProgress);
 
   //! Guess whether the stream is an Ascii STL file, by analysis of the first bytes (~200).
-  //! The function attempts to put back the read symbols to the stream which thus must support ungetc().
+  //! If the stream does not support seekg() then the parameter isSeekgAvailable should
+  //! be passed as 'false', in this case the function attempts to put back the read symbols
+  //! to the stream which thus must support ungetc().
   //! Returns true if the stream seems to contain Ascii STL.
-  Standard_EXPORT Standard_Boolean IsAscii (Standard_IStream& theStream);
+  Standard_EXPORT Standard_Boolean IsAscii (Standard_IStream& theStream,
+                                            const bool isSeekgAvailable);
 
   //! Reads STL data from binary stream.
   //! The stream must be opened in binary mode.