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

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


SVN commit 1320468 by kuemmel:

template code only used in cource file

 M  +101 -0    asciidatareader.cpp  
 M  +2 -112    asciidatareader.h  


--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.cpp #1320467:1320468
@@ -12,6 +12,7 @@
 
 #include "asciidatareader.h"
 
+#include "asciisourceconfig.h"
 #include "math_kst.h"
 #include "kst_inf.h"
 #include "kst_i18n.h"
@@ -238,4 +239,104 @@
 }
 
 
+//-------------------------------------------------------------------------------------------
+template<class Buffer, typename ColumnDelimiter>
+int AsciiDataReader::readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
+                              const LineEndingType& lineending, const ColumnDelimiter& column_del)
+{
+  if (_config._delimiters.value().size() == 0) {
+    const NoDelimiter comment_del;
+    return readColumns(v, buffer, bufstart, bufread, col, s, n, lineending, column_del, comment_del);
+  } else if (_config._delimiters.value().size() == 1) {
+    const IsCharacter comment_del(_config._delimiters.value()[0].toLatin1());
+    return readColumns(v, buffer, bufstart, bufread, col, s, n, lineending, column_del, comment_del);
+  } else if (_config._delimiters.value().size() > 1) {
+    const IsInString comment_del(_config._delimiters.value());
+    return readColumns(v, buffer, bufstart, bufread, col, s, n, lineending, column_del, comment_del);
+  }
+
+  return 0;
+}
+
+template<class Buffer, typename ColumnDelimiter, typename CommentDelimiter>
+int AsciiDataReader::readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
+                              const LineEndingType& lineending, const ColumnDelimiter& column_del, const CommentDelimiter& comment_del)
+{
+  if (_config._columnWidthIsConst) {
+    const AlwaysTrue column_withs_const;
+    if (lineending.isLF()) {
+      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakLF(lineending), column_del, comment_del, column_withs_const);
+    } else {
+      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakCR(lineending), column_del, comment_del, column_withs_const);
+    }
+  } else {
+    const AlwaysFalse column_withs_const;
+    if (lineending.isLF()) {
+      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakLF(lineending), column_del, comment_del, column_withs_const);
+    } else {
+      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakCR(lineending), column_del, comment_del, column_withs_const);
+    }
+  }
+}
+
+
+template<class Buffer, typename IsLineBreak, typename ColumnDelimiter, typename CommentDelimiter, typename ColumnWidthsAreConst>
+int AsciiDataReader::readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
+                              const IsLineBreak& isLineBreak,
+                              const ColumnDelimiter& column_del, const CommentDelimiter& comment_del,
+                              const ColumnWidthsAreConst& are_column_widths_const)
+{
+  LexicalCast lexc;
+  lexc.setDecimalSeparator(_config._useDot);
+  const QString delimiters = _config._delimiters.value();
+
+  bool is_custom = (_config._columnType.value() == AsciiSourceConfig::Custom);
+
+  int col_start = -1;
+  for (int i = 0; i < n; i++, s++) {
+    bool incol = false;
+    int i_col = 0;
+
+    if (are_column_widths_const()) {
+      if (col_start != -1) {
+        v[i] = lexc.toDouble(&buffer[0] + _rowIndex[s] + col_start);
+        continue;
+      }
+    }
+
+    v[i] = Kst::NOPOINT;
+    for (int ch = _rowIndex[s] - bufstart; ch < bufread; ++ch) {
+      if (isLineBreak(buffer[ch])) {
+        break;
+      } else if (column_del(buffer[ch])) { //<- check for column start
+        if ((!incol) && is_custom) {
+          ++i_col;
+          if (i_col == col) {
+            v[i] = NAN;
+          }
+        }
+        incol = false;
+      } else if (comment_del(buffer[ch])) {
+        break;
+      } else {
+        if (!incol) {
+          incol = true;
+          ++i_col;
+          if (i_col == col) {
+            toDouble(lexc, &buffer[0], bufread, ch, &v[i], i);
+            if (are_column_widths_const()) {
+              if (col_start == -1) {
+                col_start = ch - _rowIndex[s];
+              }
+            }
+            break;
+          }
+        }
+      }
+    }
+  }
+  return n;
+}
+
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.h #1320467:1320468
@@ -13,16 +13,12 @@
 #ifndef ASCII_DATA_READER_H
 #define ASCII_DATA_READER_H
 
-#include "asciisourceconfig.h"
 #include "asciifilebuffer.h"
 
-#include "math_kst.h"
-#include "kst_inf.h"
-#include "kst_atof.h"
-
 class QFile;
+class LexicalCast;
+class AsciiSourceConfig;
 
-
 class AsciiDataReader
 {
   public:
@@ -175,111 +171,5 @@
     const IsWhiteSpace isWhiteSpace;
 };
 
-
-
-//-------------------------------------------------------------------------------------------
-template<class Buffer, typename ColumnDelimiter>
-int AsciiDataReader::readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
-                              const LineEndingType& lineending, const ColumnDelimiter& column_del)
-{
-  if (_config._delimiters.value().size() == 0) {
-    const NoDelimiter comment_del;
-    return readColumns(v, buffer, bufstart, bufread, col, s, n, lineending, column_del, comment_del);
-  } else if (_config._delimiters.value().size() == 1) {
-    const IsCharacter comment_del(_config._delimiters.value()[0].toLatin1());
-    return readColumns(v, buffer, bufstart, bufread, col, s, n, lineending, column_del, comment_del);
-  } else if (_config._delimiters.value().size() > 1) {
-    const IsInString comment_del(_config._delimiters.value());
-    return readColumns(v, buffer, bufstart, bufread, col, s, n, lineending, column_del, comment_del);
-  }
-
-  return 0;
-}
-
-template<class Buffer, typename ColumnDelimiter, typename CommentDelimiter>
-int AsciiDataReader::readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
-                              const LineEndingType& lineending, const ColumnDelimiter& column_del, const CommentDelimiter& comment_del)
-{
-  if (_config._columnWidthIsConst) {
-    const AlwaysTrue column_withs_const;
-    if (lineending.isLF()) {
-      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakLF(lineending), column_del, comment_del, column_withs_const);
-    } else {
-      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakCR(lineending), column_del, comment_del, column_withs_const);
-    }
-  } else {
-    const AlwaysFalse column_withs_const;
-    if (lineending.isLF()) {
-      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakLF(lineending), column_del, comment_del, column_withs_const);
-    } else {
-      return readColumns(v, buffer, bufstart, bufread, col, s, n, IsLineBreakCR(lineending), column_del, comment_del, column_withs_const);
-    }
-  }
-}
-
-
-template<class Buffer, typename IsLineBreak, typename ColumnDelimiter, typename CommentDelimiter, typename ColumnWidthsAreConst>
-int AsciiDataReader::readColumns(double* v, const Buffer& buffer, int bufstart, int bufread, int col, int s, int n,
-                              const IsLineBreak& isLineBreak,
-                              const ColumnDelimiter& column_del, const CommentDelimiter& comment_del,
-                              const ColumnWidthsAreConst& are_column_widths_const)
-{
-  LexicalCast lexc;
-  lexc.setDecimalSeparator(_config._useDot);
-  const QString delimiters = _config._delimiters.value();
-
-  bool is_custom = (_config._columnType.value() == AsciiSourceConfig::Custom);
-
-  int col_start = -1;
-  for (int i = 0; i < n; i++, s++) {
-    bool incol = false;
-    int i_col = 0;
-
-    if (are_column_widths_const()) {
-      if (col_start != -1) {
-        v[i] = lexc.toDouble(&buffer[0] + _rowIndex[s] + col_start);
-        continue;
-      }
-    }
-
-    v[i] = Kst::NOPOINT;
-    for (int ch = _rowIndex[s] - bufstart; ch < bufread; ++ch) {
-      if (isLineBreak(buffer[ch])) {
-        break;
-      } else if (column_del(buffer[ch])) { //<- check for column start
-        if ((!incol) && is_custom) {
-          ++i_col;
-          if (i_col == col) {
-            v[i] = NAN;
-          }
-        }
-        incol = false;
-      } else if (comment_del(buffer[ch])) {
-        break;
-      } else {
-        if (!incol) {
-          incol = true;
-          ++i_col;
-          if (i_col == col) {
-            toDouble(lexc, &buffer[0], bufread, ch, &v[i], i);
-            if (are_column_widths_const()) {
-              if (col_start == -1) {
-                col_start = ch - _rowIndex[s];
-              }
-            }
-            break;
-          }
-        }
-      }
-    }
-  }
-  return n;
-}
-
-
-
-
-
-
 #endif
 // vim: ts=2 sw=2 et


More information about the Kst mailing list