[Kst] branches/work/kst/portto4/kst/src/datasources/ascii
Peter Kümmel
syntheticpp at gmx.net
Sat Oct 13 17:40:57 UTC 2012
SVN commit 1320347 by kuemmel:
split out AsciiDataReader step by step
M +8 -7 asciisource.cpp
M +4 -39 asciisource.h
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.cpp #1320346:1320347
@@ -194,7 +194,7 @@
//-------------------------------------------------------------------------------------------
AsciiSource::AsciiSource(Kst::ObjectStore *store, QSettings *cfg, const QString& filename, const QString& type, const QDomElement& e) :
Kst::DataSource(store, cfg, filename, type),
- _fileBuffer(new FileBuffer),
+ _fileBuffer(new AsciiDataReader::FileBuffer),
_rowIndex(),
is(new DataInterfaceAsciiString(*this)),
iv(new DataInterfaceAsciiVector(*this))
@@ -385,7 +385,7 @@
}
_byteLength = file.size();
- FileBuffer buf;
+ AsciiDataReader::FileBuffer buf;
buf._bufferedS = _rowIndex[_numFrames];
buf._bufferedN = 0;
do {
@@ -395,7 +395,7 @@
//bufstart += bufread;
buf._bufferedS = _rowIndex[_numFrames]; // always read from the start of a line
- buf._bufferedN = readFromFile(file, buf, buf._bufferedS, _byteLength - buf._bufferedS, FileBuffer::Prealloc - 1);
+ buf._bufferedN = readFromFile(file, buf, buf._bufferedS, _byteLength - buf._bufferedS, AsciiDataReader::FileBuffer::Prealloc - 1);
if (_config._delimiters.value().size() == 0) {
const NoDelimiter comment_del;
@@ -420,7 +420,7 @@
}
}
- } while (buf._bufferedN == FileBuffer::Prealloc - 1 && read_completely);
+ } while (buf._bufferedN == AsciiDataReader::FileBuffer::Prealloc - 1 && read_completely);
_rowIndex.resize(_numFrames+1);
@@ -446,7 +446,7 @@
_rowIndex[_numFrames] = row_start;
++_numFrames;
if (_numFrames >= _rowIndex.size()) {
- _rowIndex.resize(_rowIndex.size() + FileBuffer::Prealloc - 1);
+ _rowIndex.resize(_rowIndex.size() + AsciiDataReader::FileBuffer::Prealloc - 1);
}
new_data = true;
row_start = row_offset+i;
@@ -487,9 +487,9 @@
void AsciiSource::clearFileBuffer(bool forceDelete)
{
// force deletion of heap allocated memory if any
- if (forceDelete || _fileBuffer->capacity() > FileBuffer::Prealloc) {
+ if (forceDelete || _fileBuffer->capacity() > AsciiDataReader::FileBuffer::Prealloc) {
delete _fileBuffer;
- _fileBuffer = new FileBuffer;
+ _fileBuffer = new AsciiDataReader::FileBuffer;
}
}
@@ -1003,4 +1003,5 @@
}
+
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/datasources/ascii/asciisource.h #1320346:1320347
@@ -22,6 +22,7 @@
#include "datasource.h"
#include "dataplugin.h"
#include "asciisourceconfig.h"
+#include "asciidatareader.h"
#include <QVarLengthArray>
#include <QFile>
@@ -78,50 +79,14 @@
Kst::ObjectList<Kst::Object> autoCurves(Kst::ObjectStore& objectStore);
private:
+ AsciiDataReader r;
- class FileBuffer
- {
- public:
+ AsciiDataReader::FileBuffer* _fileBuffer;
- enum SizeOnStack
- {
- Prealloc =
-#if defined(__ANDROID__) || defined(__QNX__) // Some mobile systems really do not like you allocating 1MB on the stack.
- 1 * 1024
-#else
- 1 * 1024 * 1024
-#endif
- };
+ QVarLengthArray<int, AsciiDataReader::FileBuffer::Prealloc> _rowIndex;
- typedef QVarLengthArray<char, Prealloc> Array;
-
- inline FileBuffer() : _bufferedS(-10), _bufferedN(-10), _array(new Array) {}
- inline ~FileBuffer() { delete _array; }
-
- int _bufferedS;
- int _bufferedN;
-
- inline void clear() { _array->clear(); }
- inline int size() const { return _array->size(); }
- inline void resize(int size) { _array->resize(size); }
- inline int capacity() const { return _array->capacity(); }
- inline char* data() { return _array->data(); }
-
- inline const char* const constPointer() const { return _array->data(); }
- inline const Array& constArray() const{ return *_array; }
-
void clearFileBuffer(bool forceDelete = false);
- private:
- Array* _array;
- };
-
- FileBuffer* _fileBuffer;
-
- QVarLengthArray<int, FileBuffer::Prealloc> _rowIndex;
-
- void clearFileBuffer(bool forceDelete = false);
-
template<class T>
bool resizeBuffer(T& buffer, int bytes);
More information about the Kst
mailing list