[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sun Oct 14 12:32:40 UTC 2012
SVN commit 1320499 by kuemmel:
_fileBuffer doesn't need to be a pointer
M +5 -5 asciidatareader.cpp
M +1 -1 asciidatareader.h
M +12 -13 asciisource.cpp
M +1 -1 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.cpp #1320498:1320499
@@ -191,7 +191,7 @@
}
//-------------------------------------------------------------------------------------------
-int AsciiDataReader::readField(AsciiFileBuffer* buf, int col, double *v, const QString& field, int s, int n)
+int AsciiDataReader::readField(const AsciiFileBuffer& buf, int col, double *v, const QString& field, int s, int n)
{
if (_config._columnType == AsciiSourceConfig::Fixed) {
MeasureTime t("AsciiSource::readField: same width for all columns");
@@ -199,7 +199,7 @@
lexc.setDecimalSeparator(_config._useDot);
// &buffer[0] points to first row at _rowIndex[0] , so if we wanna find
// the column in row i by adding _rowIndex[i] we have to start at:
- const char* col_start = &buf->constData()[0] - _rowIndex[0] + _config._columnWidth * (col - 1);
+ const char* col_start = &buf.constData()[0] - _rowIndex[0] + _config._columnWidth * (col - 1);
for (int i = 0; i < n; ++i) {
v[i] = lexc.toDouble(_rowIndex[i] + col_start);
}
@@ -208,16 +208,16 @@
if (_config._columnDelimiter.value().size() == 1) {
MeasureTime t("AsciiSource::readField: 1 custom column delimiter");
const IsCharacter column_del(_config._columnDelimiter.value()[0].toLatin1());
- return readColumns(v, buf->constData(), buf->begin(), buf->bytesRead(), col, s, n, _lineending, column_del);
+ return readColumns(v, buf.constData(), buf.begin(), buf.bytesRead(), col, s, n, _lineending, column_del);
} if (_config._columnDelimiter.value().size() > 1) {
MeasureTime t(QString("AsciiSource::readField: %1 custom column delimiters").arg(_config._columnDelimiter.value().size()));
const IsInString column_del(_config._columnDelimiter.value());
- return readColumns(v, buf->constData(), buf->begin(), buf->bytesRead(), col, s, n, _lineending, column_del);
+ return readColumns(v, buf.constData(), buf.begin(), buf.bytesRead(), col, s, n, _lineending, column_del);
}
} else if (_config._columnType == AsciiSourceConfig::Whitespace) {
MeasureTime t("AsciiSource::readField: whitespace separated columns");
const IsWhiteSpace column_del;
- return readColumns(v, buf->constData(), buf->begin(), buf->bytesRead(), col, s, n, _lineending, column_del);
+ return readColumns(v, buf.constData(), buf.begin(), buf.bytesRead(), col, s, n, _lineending, column_del);
}
return 0;
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.h #1320498:1320499
@@ -37,7 +37,7 @@
void detectLineEndingType(QFile& file);
bool findDataRows(bool read_completely, QFile& file, int _byteLength);
- int readField(AsciiFileBuffer* buf, int col, double *v, const QString& field, int s, int n);
+ int readField(const AsciiFileBuffer &buf, int col, double *v, const QString& field, int s, int n);
private:
int _numFrames;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320498:1320499
@@ -50,7 +50,7 @@
AsciiSource::AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e) :
Kst::DataSource(store, cfg, filename, type),
reader(_config),
- _fileBuffer(new AsciiFileBuffer),
+ _fileBuffer(),
is(new DataInterfaceAsciiString(*this)),
iv(new DataInterfaceAsciiVector(*this))
{
@@ -86,7 +86,6 @@
//-------------------------------------------------------------------------------------------
AsciiSource::~AsciiSource()
{
- delete _fileBuffer;
}
@@ -94,7 +93,7 @@
void AsciiSource::reset()
{
// forget about cached data
- _fileBuffer->clear();
+ _fileBuffer.clear();
reader.clear();
_valid = false;
@@ -175,7 +174,7 @@
MeasureTime t("AsciiSource::internalDataSourceUpdate: " + _filename);
// forget about cached data
- _fileBuffer->clear();
+ _fileBuffer.clear();
if (!_haveHeader) {
_haveHeader = initRowIndex();
@@ -252,12 +251,12 @@
// reading whole file into memory failed
// find a smaller allocatable size
- _fileBuffer->clear();
+ _fileBuffer.clear();
int realloc_size = n / 4;
- while (!_fileBuffer->resize(realloc_size) && realloc_size > 0) {
+ while (!_fileBuffer.resize(realloc_size) && realloc_size > 0) {
realloc_size /= 2;
}
- _fileBuffer->clear();
+ _fileBuffer.clear();
if (realloc_size == 0) {
QMessageBox::warning(0, "Error while reading ascii file", "File could not be read because not enough memory is available.");
return 0;
@@ -267,18 +266,18 @@
int start = s;
n_read = 0;
while (n_read < n) {
- _fileBuffer->clear();
+ _fileBuffer.clear();
int to_read = n_read + realloc_size < n ? realloc_size : n - n_read;
n_read += readField(v + start, field, n_read, to_read, succcess);
if (!succcess) {
- _fileBuffer->clear();
+ _fileBuffer.clear();
QMessageBox::warning(0, "Error while reading ascii file", "The file was only read partially not enough memory is available.");
return n_read;
}
start += to_read;
}
// don't buffer partial files
- _fileBuffer->clear();
+ _fileBuffer.clear();
return n_read;
}
@@ -306,13 +305,13 @@
// check if the already in buffer
int begin = reader.beginOfRow(s);
int bytesToRead = reader.beginOfRow(s + n) - begin;
- if ((begin != _fileBuffer->begin()) || (bytesToRead != _fileBuffer->bytesRead())) {
+ if ((begin != _fileBuffer.begin()) || (bytesToRead != _fileBuffer.bytesRead())) {
QFile file(_filename);
if (!openValidFile(file)) {
return 0;
}
- _fileBuffer->read(file, begin, bytesToRead);
- if (_fileBuffer->bytesRead() == 0) {
+ _fileBuffer.read(file, begin, bytesToRead);
+ if (_fileBuffer.bytesRead() == 0) {
success = false;
return 0;
}
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1320498:1320499
@@ -69,7 +69,7 @@
private:
AsciiDataReader reader;
- AsciiFileBuffer* _fileBuffer;
+ AsciiFileBuffer _fileBuffer;
friend class ConfigWidgetAscii;
More information about the Kst
mailing list