[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Mon Jul 26 17:09:10 CEST 2010
SVN commit 1154926 by kuemmel:
AsciiPlugin: configuration could be on stack
M +4 -4 asciiplugin.cpp
M +21 -26 asciisource.cpp
M +2 -2 asciisource.h
M +1 -0 asciisourceconfig.cpp
M +3 -1 asciisourceconfig.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciiplugin.cpp #1154925:1154926
@@ -131,9 +131,9 @@
if (hasInstance()) {
Kst::SharedPtr<AsciiSource> src = Kst::kst_cast<AsciiSource>(instance());
_ac->_indexVector->addItems(src->vector().list());
- _ac->_indexVector->setCurrentIndex(src->_config->_indexInterpretation - 1);
- if (src->vector().list().contains(src->_config->_indexVector)) {
- _ac->_indexVector->setEditText(src->_config->_indexVector);
+ _ac->_indexVector->setCurrentIndex(src->_config._indexInterpretation - 1);
+ if (src->vector().list().contains(src->_config._indexVector)) {
+ _ac->_indexVector->setEditText(src->_config._indexVector);
}
} else {
_ac->_indexVector->addItem("INDEX");
@@ -158,7 +158,7 @@
// Update the instance from our new settings
if (src->reusable()) {
- src->_config->readGroup(settings(), src->fileName());
+ src->_config.readGroup(settings(), src->fileName());
src->reset();
src->internalDataSourceUpdate();
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1154925:1154926
@@ -120,7 +120,6 @@
AsciiSource::AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e) :
Kst::DataSource(store, cfg, filename, type),
_rowIndex(0L),
- _config(0L),
_tmpBuf(0L),
_tmpBufSize(0),
iv(new DataInterfaceAsciiVector(*this))
@@ -138,10 +137,9 @@
if (!type.isEmpty() && type != asciiTypeString) {
return;
}
- _config = new AsciiSourceConfig;
- _config->readGroup(*cfg, filename);
+ _config.readGroup(*cfg, filename);
if (!e.isNull()) {
- _config->load(e);
+ _config.load(e);
}
_valid = true;
@@ -162,9 +160,6 @@
_rowIndex = 0L;
_numLinesAlloc = 0;
}
-
- delete _config;
- _config = 0L;
}
@@ -219,12 +214,12 @@
_byteLength = 0;
_numFrames = 0;
- if (_config->_dataLine > 0) {
+ if (_config._dataLine > 0) {
QFile file(_filename);
if (!file.open(QIODevice::ReadOnly)) {
return false;
}
- int left = _config->_dataLine;
+ int left = _config._dataLine;
int didRead = 0;
QByteArray ignore;
while (left > 0) {
@@ -250,12 +245,12 @@
return NoChange;
}
// Re-update the field list since we have one now
- _fieldList = fieldListFor(_filename, _config);
+ _fieldList = fieldListFor(_filename, &_config);
_fieldListComplete = _fieldList.count() > 1;
// Re-update the scalar list since we have one now
- _scalarList = scalarListFor(_filename, _config);
- _stringList = stringListFor(_filename, _config);
+ _scalarList = scalarListFor(_filename, &_config);
+ _stringList = stringListFor(_filename, &_config);
}
bool forceUpdate = false;
@@ -281,7 +276,7 @@
int bufstart, bufread;
bool new_data = false;
char tmpbuf[MAXBUFREADLEN+1];
- QByteArray delbytes = _config->_delimiters.value().toLatin1();
+ QByteArray delbytes = _config._delimiters.value().toLatin1();
const char *del = delbytes.constData();
bool first_read = (_numFrames==0);
@@ -370,9 +365,9 @@
int AsciiSource::readField(double *v, const QString& field, int s, int n) {
NumberLocale dot;
- char sep = _config->_localSeparator;
+ char sep = _config._localSeparator;
- if (_config->_useDot) {
+ if (_config._useDot) {
#ifdef USE_KST_ATOF
sep = '.';
#else
@@ -435,22 +430,22 @@
file.seek(bufstart);
file.read(_tmpBuf, bufread);
- if (_config->_columnType == AsciiSourceConfig::Fixed) {
+ if (_config._columnType == AsciiSourceConfig::Fixed) {
for (int i = 0; i < n; ++i, ++s) {
// Read appropriate column and convert to double
- v[i] = atof(_tmpBuf + _rowIndex[i] - _rowIndex[0] + _config->_columnWidth * (col - 1), sep);
+ v[i] = atof(_tmpBuf + _rowIndex[i] - _rowIndex[0] + _config._columnWidth * (col - 1), sep);
}
- } else if (_config->_columnType == AsciiSourceConfig::Custom) {
+ } else if (_config._columnType == AsciiSourceConfig::Custom) {
for (int i = 0; i < n; ++i, ++s) {
bool incol = false;
int i_col = 0;
v[i] = Kst::NOPOINT;
for (int ch = _rowIndex[s] - bufstart; ch < bufread; ++ch) {
- if (_config->_columnDelimiter.value().contains(_tmpBuf[ch])) {
+ if (_config._columnDelimiter.value().contains(_tmpBuf[ch])) {
incol = false;
} else if (_tmpBuf[ch] == '\n' || _tmpBuf[ch] == '\r') {
break;
- } else if (_config->_delimiters.value().contains(_tmpBuf[ch])) {
+ } else if (_config._delimiters.value().contains(_tmpBuf[ch])) {
break;
} else {
if (!incol) {
@@ -482,7 +477,7 @@
} else {
incol = false;
}
- } else if (_config->_delimiters.value().contains(_tmpBuf[ch])) {
+ } else if (_config._delimiters.value().contains(_tmpBuf[ch])) {
break;
} else {
if (!incol) {
@@ -665,23 +660,23 @@
void AsciiSource::save(QXmlStreamWriter &s) {
Kst::DataSource::save(s);
- _config->save(s);
+ _config.save(s);
}
void AsciiSource::parseProperties(QXmlStreamAttributes &properties) {
- _config->parseProperties(properties);
+ _config.parseProperties(properties);
reset();
}
bool AsciiSource::supportsTimeConversions() const {
- return false; //fieldList().contains(_config->_indexVector) && _config->_indexInterpretation != AsciiSourceConfig::Unknown && _config->_indexInterpretation != AsciiSourceConfig::INDEX;
+ return false; //fieldList().contains(_config._indexVector) && _config._indexInterpretation != AsciiSourceConfig::Unknown && _config._indexInterpretation != AsciiSourceConfig::INDEX;
}
int AsciiSource::sampleForTime(double ms, bool *ok) {
- switch (_config->_indexInterpretation) {
+ switch (_config._indexInterpretation) {
case AsciiSourceConfig::Seconds:
// FIXME: make sure "seconds" exists in _indexVector
if (ok) {
@@ -706,7 +701,7 @@
int AsciiSource::sampleForTime(const QDateTime& time, bool *ok) {
- switch (_config->_indexInterpretation) {
+ switch (_config._indexInterpretation) {
case AsciiSourceConfig::Seconds:
// FIXME: make sure "time" exists in _indexVector
if (ok) {
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1154925:1154926
@@ -20,9 +20,9 @@
#include "datasource.h"
#include "dataplugin.h"
+#include "asciisourceconfig.h"
-class AsciiSourceConfig;
class QFile;
class DataInterfaceAsciiVector;
@@ -73,7 +73,7 @@
int _numFrames;
int _byteLength;
friend class ConfigWidgetAscii;
- mutable AsciiSourceConfig *_config;
+ mutable AsciiSourceConfig _config;
char *_tmpBuf;
uint _tmpBufSize;
bool _haveHeader;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.cpp #1154925:1154926
@@ -18,6 +18,7 @@
#include "asciisourceconfig.h"
+#include "asciisource.h"
//
// AsciiSourceConfig
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisourceconfig.h #1154925:1154926
@@ -17,9 +17,11 @@
#ifndef KST_ASCII_SOURCE_CONFIG_H
#define KST_ASCII_SOURCE_CONFIG_H
-#include "asciisource.h"
#include "namedparameter.h"
+#include <QDomElement>
+
+
class AsciiSourceConfig {
// TODO translate keys?
More information about the Kst
mailing list