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

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


SVN commit 1320470 by kuemmel:

make line ending private

 M  +15 -16    asciidatareader.cpp  
 M  +12 -17    asciidatareader.h  
 M  +1 -2      asciisource.cpp  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.cpp #1320469:1320470
@@ -55,7 +55,7 @@
 
 
 //-------------------------------------------------------------------------------------------
-LineEndingType AsciiDataReader::detectLineEndingType(QFile& file) const
+void AsciiDataReader::detectLineEndingType(QFile& file)
 {
   QByteArray line;
   int line_size = 0;
@@ -65,12 +65,11 @@
   }
   file.seek(0);
   if (line_size < 2) {
-    return LineEndingType();
+    _lineending = LineEndingType();
+  } else {
+    _lineending.is_crlf = line[line_size - 2] == '\r' && line[line_size - 1] == '\n' ;
+    _lineending.character =  _lineending.is_crlf ? line[line_size - 2] : line[line_size - 1];
   }
-  LineEndingType end;
-  end.is_crlf = line[line_size - 2] == '\r' && line[line_size - 1] == '\n' ;
-  end.character =  end.is_crlf ? line[line_size - 2] : line[line_size - 1];
-  return end;
 }
 
 
@@ -164,7 +163,7 @@
 
 bool AsciiDataReader::findDataRows(int& numFrames, bool read_completely, QFile& file, int _byteLength)
 {
-  LineEndingType lineending = detectLineEndingType(file);
+  detectLineEndingType(file);
 
   bool new_data = false;
 
@@ -180,24 +179,24 @@
 
     if (_config._delimiters.value().size() == 0) {
       const NoDelimiter comment_del;
-      if (lineending.isLF()) {
-        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakLF(lineending), comment_del);
+      if (_lineending.isLF()) {
+        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakLF(_lineending), comment_del);
       } else {
-        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakCR(lineending), comment_del);
+        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakCR(_lineending), comment_del);
       }
     } else if (_config._delimiters.value().size() == 1) {
       const IsCharacter comment_del(_config._delimiters.value()[0].toLatin1());
-      if (lineending.isLF()) {
-        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakLF(lineending), comment_del);
+      if (_lineending.isLF()) {
+        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakLF(_lineending), comment_del);
       } else {
-        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakCR(lineending), comment_del);
+        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakCR(_lineending), comment_del);
       }
     } else if (_config._delimiters.value().size() > 1) {
       const IsInString comment_del(_config._delimiters.value());
-      if (lineending.isLF()) {
-        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedS, IsLineBreakLF(lineending), comment_del);
+      if (_lineending.isLF()) {
+        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedS, IsLineBreakLF(_lineending), comment_del);
       } else {
-        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakCR(lineending), comment_del);
+        new_data = findDataRows(numFrames, buf.constData(), buf._bufferedS, buf._bufferedN, IsLineBreakCR(_lineending), comment_del);
       }
     }
   } while (buf._bufferedN == AsciiFileBuffer::Prealloc - 1  && read_completely);
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.h #1320469:1320470
@@ -26,26 +26,26 @@
     AsciiDataReader(AsciiSourceConfig& c);
     ~AsciiDataReader();
 
-    // TODO remove
-    AsciiSourceConfig& _config;
-    
     typedef QVarLengthArray<int, AsciiFileBuffer::Prealloc> RowIndex;
-    RowIndex _rowIndex;
-
     inline RowIndex& rowIndex() { return _rowIndex; }
 
-    void clearFileBuffer(bool forceDelete = false);
+    void detectLineEndingType(QFile& file);
 
-    template<class T>
-    bool resizeBuffer(T& buffer, int bytes);
+    bool findDataRows(int& _numFrames, bool read_completely, QFile& file, int _byteLength);
+    int readFromFile(QFile&, AsciiFileBuffer&, int start, int numberOfBytes, int maximalBytes = -1);  
+    int readField(AsciiFileBuffer* _fileBuffer, int col, int bufstart, int bufread,
+                  double *v, const QString& field, int s, int n);
 
-    AsciiCharacterTraits::LineEndingType detectLineEndingType(QFile& file) const;
+  private:
+    RowIndex _rowIndex;
+    AsciiSourceConfig& _config;
     AsciiCharacterTraits::LineEndingType _lineending;
     
-    int readFromFile(QFile&, AsciiFileBuffer&, int start, int numberOfBytes, int maximalBytes = -1); 
+    const AsciiCharacterTraits::IsDigit isDigit;
+    const AsciiCharacterTraits::IsWhiteSpace isWhiteSpace;
     
-    int readField(AsciiFileBuffer* _fileBuffer, int col, int bufstart, int bufread,
-                  double *v, const QString& field, int s, int n);
+    template<class T>
+    bool resizeBuffer(T& buffer, int bytes);
 
     template<class Buffer, typename ColumnDelimiter>
     int readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
@@ -59,15 +59,10 @@
     int readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
                     const IsLineBreak&, const ColumnDelimiter&, const CommentDelimiter&, const ColumnWidthsAreConst&);
 
-    bool findDataRows(int& _numFrames, bool read_completely, QFile& file, int _byteLength);
-
     template<class Buffer, typename IsLineBreak, typename CommentDelimiter>
     bool findDataRows(int& _numFrames, const Buffer& buffer, int bufstart, int bufread, const IsLineBreak&, const CommentDelimiter&);
 
     void toDouble(const LexicalCast& lexc, const char* buffer, int bufread, int ch, double* v, int row);
-
-    const AsciiCharacterTraits::IsDigit isDigit;
-    const AsciiCharacterTraits::IsWhiteSpace isWhiteSpace;
 };
 
 #endif
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320469:1320470
@@ -327,9 +327,8 @@
       return 0;
     }
 
-    r._lineending = r.detectLineEndingType(file);
+    r.detectLineEndingType(file);
 
-
     bufread = r.readFromFile(file, *_fileBuffer, bufstart, bufread);
     if (bufread == 0) {
       success = false;


More information about the Kst mailing list