[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Fri Jan 21 17:25:15 CET 2011
SVN commit 1216158 by kuemmel:
- there could be multiple instances of AsciiSource
- also support multiple delimiters
- optimize when only one delimiter is used
M +9 -20 asciisource.cpp
M +15 -1 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1216157:1216158
@@ -386,20 +386,6 @@
//-------------------------------------------------------------------------------------------
-namespace
-{
- bool isWhiteSpace(char c) {
- return isspace((unsigned char)c);
- }
-
- char columnDelimiter;
- bool isColumnDelimiter(char c) {
- return columnDelimiter == c;
- }
-}
-
-
-//-------------------------------------------------------------------------------------------
int AsciiSource::readField(double *v, const QString& field, int s, int n)
{
if (n < 0) {
@@ -445,12 +431,15 @@
}
return n;
} else if (_config._columnType == AsciiSourceConfig::Custom) {
- if (!_config._columnDelimiter.value().isEmpty()) {
- columnDelimiter = _config._columnDelimiter.value().toAscii().constData()[0];
- return readColumns(v, buffer, bufstart, bufread, col, s, n, &isColumnDelimiter);
+ if (_config._columnDelimiter.value().size() == 1) {
+ _columnDelimiterCharacter = _config._columnDelimiter.value()[0].toAscii();
+ return readColumns(v, buffer, bufstart, bufread, col, s, n, &AsciiSource::isColumnDelimiter);
+ } if (_config._columnDelimiter.value().size() > 1) {
+ _columnDelimiterString = _config._columnDelimiter.value();
+ return readColumns(v, buffer, bufstart, bufread, col, s, n, &AsciiSource::isInColumnDelimiterString);
}
} else if (_config._columnType == AsciiSourceConfig::Whitespace) {
- return readColumns(v, buffer, bufstart, bufread, col, s, n, &isWhiteSpace);
+ return readColumns(v, buffer, bufstart, bufread, col, s, n, &AsciiSource::isWhiteSpace);
}
return 0;
@@ -458,7 +447,7 @@
//-------------------------------------------------------------------------------------------
-int AsciiSource::readColumns(double* v, const char* buffer, int bufstart, int bufread, int col, int s, int n, bool (*isColumnDelemiterFunction)(char))
+int AsciiSource::readColumns(double* v, const char* buffer, int bufstart, int bufread, int col, int s, int n, bool (AsciiSource::*isColumnDelemiterFunction)(char))
{
LexicalCast lexc;
lexc.setDecimalSeparator(_config._useDot, _config._localSeparator);
@@ -472,7 +461,7 @@
for (ch = _rowIndex[s] - bufstart; ch < bufread; ++ch) {
if (buffer[ch] == '\n' || buffer[ch] == '\r') {
break;
- } else if (isColumnDelemiterFunction(buffer[ch])) { //<- check for column start
+ } else if ((this->*isColumnDelemiterFunction)(buffer[ch])) { //<- check for column start
incol = false;
} else if (delimiters.contains(buffer[ch])) {
break;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1216157:1216158
@@ -102,7 +102,21 @@
template<class T>
int readFromFile(QFile&, T& buffer, int start, int numberOfBytes, int maximalBytes = -1);
- int readColumns(double* v, const char* buffer, int bufstart, int bufread, int col, int s, int n, bool (*isColumnDelemiterFunction)(char));
+ inline bool isWhiteSpace(char c) {
+ return isspace((unsigned char)c);
+ }
+
+ char _columnDelimiterCharacter;
+ inline bool isColumnDelimiter(char c) {
+ return _columnDelimiterCharacter == c;
+ }
+
+ QString _columnDelimiterString;
+ inline bool isInColumnDelimiterString(char c) {
+ return _columnDelimiterString.contains(c);
+ }
+
+ int readColumns(double* v, const char* buffer, int bufstart, int bufread, int col, int s, int n, bool (AsciiSource::*isColumnDelemiterFunction)(char));
void toDouble(const LexicalCast& lexc, const char* buffer, int bufread, int ch, double* v, int row);
// TODO remove
More information about the Kst
mailing list