[Kst] kdeextragear-2/kst/kst/datasources/ascii

George Staikos staikos at kde.org
Wed Apr 13 18:35:39 CEST 2005


CVS commit by staikos: 

implement header skip - causes some minor regressions that I'm fixing now


  A            notes.txt   1.1
  M +31 -16    ascii.cpp   1.50
  M +14 -14    ascii.h   1.18


--- kdeextragear-2/kst/kst/datasources/ascii/ascii.cpp  #1.49:1.50
@@ -93,4 +93,5 @@ class AsciiSource::Config {
 AsciiSource::AsciiSource(KConfig *cfg, const QString& filename, const QString& type)
 : KstDataSource(cfg, filename, type), _rowIndex(0L), _config(0L), _tmpBuf(0L), _tmpBufSize(0) {
+  _valid = false;
   if (!type.isEmpty() && type != "ASCII") {
     return;
@@ -100,7 +101,5 @@ AsciiSource::AsciiSource(KConfig *cfg, c
   _config->read(cfg, filename);
 
-  if (initFile()) {
-    _valid = true;
-  }
+  update();
 }
 
@@ -124,15 +123,34 @@ AsciiSource::~AsciiSource() {
 
 
-bool AsciiSource::initFile() {
+bool AsciiSource::initRowIndex() {
   if (!_rowIndex) {
     _rowIndex = (int *)malloc(32768 * sizeof(int));
-    _rowIndex[0] = 0;
     _numLinesAlloc = 32768;
+  }
+  _rowIndex[0] = 0;
     _byteLength = 0;
+  _numFrames = 0;
+
+  if (_config->_dataLine > 0) {
+    QFile file(_filename);
+    if (!file.open(IO_ReadOnly)) {
+      return false;
+    }
+    int left = _config->_dataLine;
+    int didRead = 0;
+    QString ignore;
+    ignore.reserve(1001);
+    while (left > 0) {
+      int thisRead = file.readLine(ignore, 1000);
+      if (thisRead <= 0 || file.atEnd()) {
+        return false;
+      }
+      didRead += thisRead;
+      --left;
+    }
+    _rowIndex[0] = didRead;
+    kdDebug() << "rowindex[0] == " << didRead << endl;
   }
 
-  // Allow files to start out empty (stdin, for instance)
-  //return update() == KstObject::UPDATE;
-  update();
   return true;
 }
@@ -145,14 +163,10 @@ KstObject::UpdateType AsciiSource::updat
   }
 
-  bool forceUpdate = false;
-  char tmpbuf[MAXBUFREADLEN];
-  QFile file(_filename);
-
   if (!_valid) {
-    _numFrames = 0;
-    _byteLength = 0;
-    _rowIndex[0] = 0;
+    _valid = initRowIndex();
   }
 
+  bool forceUpdate = false;
+  QFile file(_filename);
   if (file.exists()) {
     if (uint(_byteLength) != file.size() || !_valid) {
@@ -175,4 +189,5 @@ KstObject::UpdateType AsciiSource::updat
   int bufstart, bufread;
   bool new_data = false;
+  char tmpbuf[MAXBUFREADLEN];
   do {
     /* Read the tmpbuffer, starting at row_index[_numFrames] */

--- kdeextragear-2/kst/kst/datasources/ascii/ascii.h  #1.17:1.18
@@ -26,31 +26,31 @@ class AsciiSource : public KstDataSource
     AsciiSource(KConfig *cfg, const QString& filename, const QString& type);
 
-    virtual ~AsciiSource();
+    ~AsciiSource();
 
-    virtual bool initFile();
+    bool initRowIndex();
 
-    virtual KstObject::UpdateType update(int = -1);
+    KstObject::UpdateType update(int = -1);
 
-    virtual int readField(double *v, const QString &field, int s, int n);
+    int readField(double *v, const QString &field, int s, int n);
 
-    virtual bool isValidField(const QString &field) const;
+    bool isValidField(const QString &field) const;
 
-    virtual int samplesPerFrame(const QString &field);
+    int samplesPerFrame(const QString &field);
 
-    virtual int frameCount(const QString& field = QString::null) const;
+    int frameCount(const QString& field = QString::null) const;
 
-    virtual QString fileType() const;
+    QString fileType() const;
 
-    virtual QStringList fieldList() const;
+    QStringList fieldList() const;
 
-    virtual void save(QTextStream &ts, const QString& indent = QString::null);
+    void save(QTextStream &ts, const QString& indent = QString::null);
 
-    virtual bool isEmpty() const;
+    bool isEmpty() const;
 
-    virtual bool supportsTimeConversions() const;
+    bool supportsTimeConversions() const;
 
-    virtual int sampleForTime(int seconds, bool *ok);
+    int sampleForTime(int seconds, bool *ok);
 
-    virtual int sampleForTime(const QDateTime& time, bool *ok);
+    int sampleForTime(const QDateTime& time, bool *ok);
 
     class Config;




More information about the Kst mailing list