QseInputFile Class Reference

#include <qseinputfile.h>

Inheritance diagram for QseInputFile:

Inheritance graph
[legend]
Collaboration diagram for QseInputFile:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 QseInputFile (const QString &name, QObject *parent=0)
 ~QseInputFile ()
void nextDataFile (QString fileName)
bool atEnd ()
void nextInputLine ()
QString filePath ()
void emitDataChanged ()

Private Member Functions

void updateProgress ()

Private Attributes

char * m_Buffer
int m_Length
int m_BufferSize
QString m_PathName
QFile m_File
int m_NLines
int m_MaxLength
QseScanm_Scan
int m_NPoints


Detailed Description

Definition at line 6 of file qseinputfile.h.


Constructor & Destructor Documentation

QseInputFile::QseInputFile ( const QString &  name,
QObject parent = 0 
)

Definition at line 3 of file qseinputfile.cpp.

References m_Buffer, m_BufferSize, and m_Length.

00004   : QseDataSet(name, parent),
00005     m_Buffer(NULL),
00006     m_Length(0),
00007     m_BufferSize(0),    
00008     m_PathName(""),
00009     m_File(),
00010 
00011     m_NLines(0),
00012     m_MaxLength(0),
00013     m_Scan(NULL),
00014     m_NPoints(0)
00015 {
00016   m_Buffer = (char*) malloc(250001);
00017   m_Length = 0;
00018   m_BufferSize = 250000;
00019 }

QseInputFile::~QseInputFile (  ) 

Definition at line 21 of file qseinputfile.cpp.

References m_Buffer, and QseDataSet::m_Mutex.

00022 {
00023   QMutexLocker lock(&m_Mutex);
00024 
00025   if (m_Buffer) {
00026     free(m_Buffer);
00027   }
00028 }


Member Function Documentation

void QseInputFile::nextDataFile ( QString  fileName  ) 

Definition at line 58 of file qseinputfile.cpp.

References m_File, m_Length, m_MaxLength, QseDataSet::m_Mutex, m_NLines, m_NPoints, m_PathName, m_Scan, and QseDataSet::setFileName().

00059 {
00060   QMutexLocker lock(&m_Mutex);
00061 
00062   if (m_File.isOpen()) {
00063     m_File.close();
00064   }
00065   
00066   m_PathName = nm;
00067   m_File.setFileName(m_PathName);
00068   m_File.open(QIODevice::ReadOnly);
00069   m_NLines = 0;
00070   m_MaxLength = 0;
00071   m_Length = 0;
00072   m_Scan = NULL;
00073   m_NPoints = 0;
00074 
00075   setFileName(nm);
00076 }

Here is the call graph for this function:

bool QseInputFile::atEnd (  ) 

Definition at line 78 of file qseinputfile.cpp.

References m_File, and QseDataSet::m_Mutex.

Referenced by nextInputLine().

00079 {
00080   QMutexLocker lock(&m_Mutex);
00081 
00082   if (m_File.isOpen()) {
00083     qint64 sz = m_File.size();
00084     qint64 pz = m_File.pos();
00085     
00086     return pz>=sz;
00087   } else{
00088 //     printf("atEnd on closed file\n");
00089     return true;
00090   }
00091 }

void QseInputFile::nextInputLine (  ) 

Definition at line 93 of file qseinputfile.cpp.

References QseDataSet::appendHeader(), QseDataSet::appendScan(), atEnd(), QseDataSet::loadCompleted(), m_Buffer, m_BufferSize, m_File, m_Length, m_MaxLength, QseDataSet::m_Mutex, m_NLines, m_NPoints, m_PathName, m_Scan, QseDataSet::madeProgress(), QseDataSet::message(), QseDataSet::scanAdded(), QseDataSet::scanCount(), and updateProgress().

00094 {
00095   QMutexLocker lock(&m_Mutex);
00096 
00097   int lnth = m_File.readLine(m_Buffer+m_Length, m_BufferSize-m_Length);
00098   bool lineended = false;
00099 
00100   while (lnth > 0 && (m_Buffer[lnth-1]=='\n' || m_Buffer[lnth-1]=='\r')) {
00101     m_Buffer[lnth-1]=0;
00102     lnth--;
00103     lineended = true;
00104   }
00105 
00106   m_Length += lnth;
00107 
00108   if (lineended) {
00109     m_NLines++;
00110 
00111     if (m_Length > m_MaxLength) {
00112       m_MaxLength = m_Length;
00113     }
00114 
00115     if (strncasecmp(m_Buffer, "#S", 2) == 0) {
00116       int ns = scanCount();
00117       // printf("Scan Added %d\n", ns);
00118       
00119       m_Scan = appendScan();
00120       m_Scan -> setName(m_Buffer);
00121       
00122       int sn;
00123       if (sscanf(m_Buffer, "#S%d", &sn)==1) {
00124   m_Scan -> setScanNumber(sn);
00125       }
00126 
00127       m_NPoints = 0;
00128       updateProgress();
00129       
00130 //       printf("Scan Added %d\n", ns);
00131 
00132       emit scanAdded(ns);
00133       emit message(QString("Loading scan %1 of file %2").arg(scanCount()).arg(m_PathName));
00134     } else if (strncasecmp(m_Buffer, "#N", 2) == 0) {
00135       int nc;
00136     
00137       if (m_Scan && (sscanf(m_Buffer, "#N%d", &nc) == 1)) {
00138   m_Scan -> setColumnCount(nc);
00139       }
00140     } else if (strncasecmp(m_Buffer, "#L", 2) == 0) {
00141       if (m_Scan) {
00142   m_Scan -> setColumnNames(m_Buffer);
00143 //  emit scanAdded(scanCount()-1);
00144       }
00145     } else if (strncasecmp(m_Buffer, "#D", 2) == 0) {
00146       QDateTime dt = QDateTime::fromString(m_Buffer+2);
00147 
00148       if (dt.isValid()) {
00149 //  printf("Valid date %s\n", m_Buffer+2);
00150 //  printf(" == %s\n", qPrintable(dt.toString("yyyyMMdd_hhmmss")));
00151 
00152   if (m_Scan) {
00153     m_Scan -> setScanDateTime(dt);
00154   }
00155       }
00156     }
00157   
00158     if (strncasecmp(m_Buffer, "#", 1) == 0) {
00159       if (m_Scan) {
00160   m_Scan -> appendHeader(m_Buffer);
00161       } else {
00162   appendHeader(m_Buffer);
00163       }
00164     } else {
00165       if (m_Scan) {
00166   //      printf("Append: <%s>\n", l);
00167   m_Scan -> appendData(m_Buffer);
00168   m_NPoints++;
00169       } else {
00170   appendHeader(m_Buffer);
00171       }
00172     }
00173     
00174     if (atEnd()) {
00175       emit madeProgress(110);
00176       emit message(QString("File %1 scanned, %2 lines, longest %3")
00177        .arg(m_PathName).arg(m_NLines).arg(m_MaxLength));
00178       emit message(QString("%1 scans found\n").arg(scanCount()));
00179       
00180       emit loadCompleted();
00181     }
00182 
00183     m_Length = 0;
00184   }
00185 }

Here is the call graph for this function:

QString QseInputFile::filePath (  ) 

Definition at line 30 of file qseinputfile.cpp.

References QseDataSet::m_Mutex, and m_PathName.

Referenced by QseController::readSettings(), and QseController::writeSettings().

00031 {
00032   QMutexLocker lock(&m_Mutex);
00033 
00034   return m_PathName;
00035 }

void QseInputFile::emitDataChanged (  ) 

Definition at line 37 of file qseinputfile.cpp.

References QseDataSet::dataChanged().

00038 {
00039   printf("emitDataChanged()\n");
00040 
00041   emit dataChanged();
00042 }

void QseInputFile::updateProgress (  )  [private]

Definition at line 44 of file qseinputfile.cpp.

References m_File, QseDataSet::m_Mutex, and QseDataSet::madeProgress().

Referenced by nextInputLine().

00045 {
00046   QMutexLocker lock(&m_Mutex);
00047 
00048   qint64 sz = m_File.size();
00049   qint64 pz = m_File.pos();
00050 
00051   double pct = ((double) pz)/((double) sz)*100.0;
00052 
00053   emit madeProgress((int) pct);
00054 
00055   //  QApplication::processEvents();
00056 }


Member Data Documentation

char* QseInputFile::m_Buffer [private]

Definition at line 24 of file qseinputfile.h.

Referenced by nextInputLine(), QseInputFile(), and ~QseInputFile().

int QseInputFile::m_Length [private]

Definition at line 25 of file qseinputfile.h.

Referenced by nextDataFile(), nextInputLine(), and QseInputFile().

Definition at line 26 of file qseinputfile.h.

Referenced by nextInputLine(), and QseInputFile().

QString QseInputFile::m_PathName [private]

Definition at line 27 of file qseinputfile.h.

Referenced by filePath(), nextDataFile(), and nextInputLine().

QFile QseInputFile::m_File [private]

Definition at line 28 of file qseinputfile.h.

Referenced by atEnd(), nextDataFile(), nextInputLine(), and updateProgress().

int QseInputFile::m_NLines [private]

Definition at line 30 of file qseinputfile.h.

Referenced by nextDataFile(), and nextInputLine().

Definition at line 31 of file qseinputfile.h.

Referenced by nextDataFile(), and nextInputLine().

Definition at line 32 of file qseinputfile.h.

Referenced by nextDataFile(), and nextInputLine().

int QseInputFile::m_NPoints [private]

Definition at line 33 of file qseinputfile.h.

Referenced by nextDataFile(), and nextInputLine().


The documentation for this class was generated from the following files:

Generated on Fri May 2 16:26:42 2008 for QSE by  doxygen 1.5.5