[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sun Oct 14 12:03:27 UTC 2012
SVN commit 1320483 by kuemmel:
FileBuffer: should read from the file
M +11 -10 asciidatareader.cpp
M +0 -1 asciidatareader.h
M +2 -0 asciifilebuffer.cpp
M +3 -3 asciifilebuffer.h
M +1 -1 asciisource.cpp
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.cpp #1320482:1320483
@@ -91,26 +91,27 @@
}
//-------------------------------------------------------------------------------------------
-int AsciiDataReader::readFromFile(QFile& file, AsciiFileBuffer& buffer, int start, int bytesToRead, int maximalBytes)
+int AsciiFileBuffer::read(QFile& file, int start, int bytesToRead, int maximalBytes)
{
- buffer.setRead(0);
+ _start = -10;
+ _read = -10;
if (maximalBytes == -1) {
- if (!buffer.resize(bytesToRead + 1))
+ if (!resize(bytesToRead + 1))
return 0;
} else {
bytesToRead = qMin(bytesToRead, maximalBytes);
- if (!buffer.resize(bytesToRead + 1))
+ if (!resize(bytesToRead + 1))
return 0;
}
file.seek(start); // expensive?
- int bytesRead = file.read(buffer.data(), bytesToRead);
- if (!buffer.resize(bytesRead + 1))
+ int bytesRead = file.read(data(), bytesToRead);
+ if (!resize(bytesRead + 1))
return 0;
- buffer.data()[bytesRead] = '\0';
- buffer.setStart(start);
- buffer.setRead(bytesRead);
+ data()[bytesRead] = '\0';
+ _start = start;
+ _read =bytesRead;
return bytesRead;
}
@@ -127,7 +128,7 @@
buf.clear();
// always read from the start of a line
- readFromFile(file, buf, _rowIndex[numFrames], _byteLength - buf.start(), AsciiFileBuffer::Prealloc - 1);
+ buf.read(file, _rowIndex[numFrames], _byteLength - buf.start(), AsciiFileBuffer::Prealloc - 1);
if (_config._delimiters.value().size() == 0) {
const NoDelimiter comment_del;
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciidatareader.h #1320482:1320483
@@ -33,7 +33,6 @@
void detectLineEndingType(QFile& file);
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);
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.cpp #1320482:1320483
@@ -12,7 +12,9 @@
#include "asciifilebuffer.h"
+#include <QFile>
+
//-------------------------------------------------------------------------------------------
bool AsciiFileBuffer::resize(int bytes)
{
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciifilebuffer.h #1320482:1320483
@@ -13,9 +13,9 @@
#ifndef ASCII_FILE_BUFFER_H
#define ASCII_FILE_BUFFER_H
-
#include <QVarLengthArray>
+class QFile;
class AsciiFileBuffer
{
@@ -38,9 +38,9 @@
inline int start() const { return _start; }
inline int read() const { return _read; }
- inline void setStart(int value) { _start = value; }
- inline void setRead(int value) { _read = value; }
+ int read(QFile&, int start, int numberOfBytes, int maximalBytes = -1);
+
inline char* data() { return _array->data(); }
inline const char* const constPointer() const { return _array->data(); }
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320482:1320483
@@ -323,7 +323,7 @@
reader.detectLineEndingType(file);
- bufread = reader.readFromFile(file, *_fileBuffer, bufstart, bufread);
+ bufread = _fileBuffer->read(file, bufstart, bufread);
if (bufread == 0) {
success = false;
return 0;
More information about the Kst
mailing list