[Kst] branches/work/kst/portto4/kst/src/datasources/ascii

Peter Kümmel syntheticpp at gmx.net
Sun Oct 14 12:32:38 UTC 2012


SVN commit 1320498 by kuemmel:

one way to get the read bytes is enough

 M  +3 -0      asciidatareader.cpp  
 M  +7 -10     asciifilebuffer.cpp  
 M  +1 -1      asciifilebuffer.h  
 M  +4 -6      asciisource.cpp  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.cpp #1320497:1320498
@@ -121,6 +121,9 @@
 
     // always read from the start of a line
     buf.read(file, _rowIndex[_numFrames], _byteLength - buf.begin(), AsciiFileBuffer::Prealloc - 1);
+    if (buf.bytesRead() == 0) {
+      return false;
+    }
     
     if (_config._delimiters.value().size() == 0) {
       const NoDelimiter comment_del;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.cpp #1320497:1320498
@@ -41,32 +41,29 @@
 }
 
 //-------------------------------------------------------------------------------------------
-int AsciiFileBuffer::read(QFile& file, int start, int bytesToRead, int maximalBytes)
+void AsciiFileBuffer::read(QFile& file, int start, int bytesToRead, int maximalBytes)
 {
   _begin = -1;
-  _bytesRead = -1;
+  _bytesRead = 0;
 
-  if (bytesToRead <= 0) {
-    return 0;
-  }
+  if (bytesToRead <= 0)
+    return;
 
   if (maximalBytes == -1) {
     if (!resize(bytesToRead + 1))
-      return 0;
+      return;
   } else {
     bytesToRead = qMin(bytesToRead, maximalBytes);
     if (!resize(bytesToRead + 1))
-      return 0;
+      return;
   }
   file.seek(start); // expensive?
   int bytesRead = file.read(data(), bytesToRead);
   if (!resize(bytesRead + 1))
-    return 0;
+    return;
 
   data()[bytesRead] = '\0';
   _begin = start;
   _bytesRead = bytesRead;
-
-  return bytesRead;
 }
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.h #1320497:1320498
@@ -39,7 +39,7 @@
   inline int begin() const { return _begin; }
   inline int bytesRead() const { return _bytesRead; }
 
-  int read(QFile&, int start, int numberOfBytes, int maximalBytes = -1);
+  void read(QFile&, int start, int numberOfBytes, int maximalBytes = -1);
 
   inline char* data() { return _array->data(); }
 
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320497:1320498
@@ -303,22 +303,20 @@
     return 0;
   }
   
+  // check if the already in buffer
   int begin = reader.beginOfRow(s);
   int bytesToRead = reader.beginOfRow(s + n) - begin;
-  // check if the already in buffer
   if ((begin != _fileBuffer->begin()) || (bytesToRead != _fileBuffer->bytesRead())) {
     QFile file(_filename);
     if (!openValidFile(file)) {
       return 0;
     }
-    
-    reader.detectLineEndingType(file);
-    
-    bytesToRead = _fileBuffer->read(file, begin, bytesToRead);
-    if (bytesToRead == 0) {
+    _fileBuffer->read(file, begin, bytesToRead);
+    if (_fileBuffer->bytesRead() == 0) {
       success = false;
       return 0;
     }
+    reader.detectLineEndingType(file);
   }
   
   return reader.readField(_fileBuffer, col, v, field, s, n);


More information about the Kst mailing list