qse  0.5.0
Public Member Functions | Private Member Functions | Private Attributes
QseInputFile Class Reference

#include <qseinputfile.h>

Inheritance diagram for QseInputFile:
Inheritance graph

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 ()
- Public Member Functions inherited from QseDataSet
 QseDataSet (const QString &name, QObject *parent=0)
 ~QseDataSet ()
void writeScan (int i, const QString &name)
void writeScans (const QString &name)
void removeScan (int i)
int scanCount () const
void clear ()
int maxColumnCount () const
QseScanscan (int n) const
QStringList header () const
void setHeader (const QStringList &hdr)
void appendHeader (const QString &hline)
QseScanappendScan ()
QString fileName () const
void setFileName (const QString &name)
void emitOperationCompleted ()

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

Additional Inherited Members

- Signals inherited from QseDataSet
void operationCompleted ()
void message (const QString &msg)
void madeProgress (int level)
void dataCleared ()
void scanAdded (int n)
void dataChanged ()
- Protected Attributes inherited from QseDataSet
QMutex m_Mutex

Detailed Description

Definition at line 6 of file qseinputfile.h.


Constructor & Destructor Documentation

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

Definition at line 9 of file qseinputfile.cpp.

References m_Buffer, m_BufferSize, and m_Length.

: QseDataSet(name, parent),
m_Buffer(NULL),
m_File(),
m_Scan(NULL),
{
m_Buffer = (char*) malloc(2500001);
m_Length = 0;
m_BufferSize = 2500000;
}
QseInputFile::~QseInputFile ( )

Definition at line 27 of file qseinputfile.cpp.

References m_Buffer, and QseDataSet::m_Mutex.

{
QMutexLocker lock(&m_Mutex);
if (m_Buffer) {
free(m_Buffer);
}
}

Member Function Documentation

bool QseInputFile::atEnd ( )

Definition at line 84 of file qseinputfile.cpp.

References m_File, and QseDataSet::m_Mutex.

Referenced by nextInputLine().

{
QMutexLocker lock(&m_Mutex);
if (m_File.isOpen()) {
qint64 sz = m_File.size();
qint64 pz = m_File.pos();
return pz>=sz;
} else{
// printf("atEnd on closed file\n");
return true;
}
}
void QseInputFile::emitDataChanged ( )

Reimplemented from QseDataSet.

Definition at line 43 of file qseinputfile.cpp.

{
// printf("QseInputFile::emitDataChanged()\n");
// emit dataChanged();
}
QString QseInputFile::filePath ( )

Definition at line 36 of file qseinputfile.cpp.

References QseDataSet::m_Mutex, and m_PathName.

{
QMutexLocker lock(&m_Mutex);
return m_PathName;
}
void QseInputFile::nextDataFile ( QString  fileName)

Definition at line 64 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().

{
QMutexLocker lock(&m_Mutex);
if (m_File.isOpen()) {
m_File.close();
}
m_PathName = nm;
m_File.setFileName(m_PathName);
m_File.open(QIODevice::ReadOnly);
m_NLines = 0;
m_Length = 0;
m_Scan = NULL;
m_NPoints = 0;
}
void QseInputFile::nextInputLine ( )

Definition at line 99 of file qseinputfile.cpp.

References QseDataSet::appendHeader(), QseDataSet::appendScan(), atEnd(), 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::operationCompleted(), QseDataSet::scanCount(), and updateProgress().

{
QMutexLocker lock(&m_Mutex);
int lnth = m_File.readLine(m_Buffer+m_Length, m_BufferSize-m_Length);
bool lineended = false;
while (lnth > 0 && (m_Buffer[lnth-1]=='\n' || m_Buffer[lnth-1]=='\r')) {
m_Buffer[lnth-1]=0;
lnth--;
lineended = true;
}
m_Length += lnth;
if (lineended) {
}
if (strncasecmp(m_Buffer, "#S", 2) == 0) {
int ns = scanCount();
// printf("QseInputFile:: Scan Added %d\n", ns);
m_Scan -> setName(m_Buffer);
m_Scan -> setScanCommand(m_Buffer);
int sn;
if (sscanf(m_Buffer, "#S%d", &sn)==1) {
m_Scan -> setScanNumber(sn);
}
m_NPoints = 0;
// emit scanAdded(ns);
emit message(QString("Loading scan %1 of file %2").arg(scanCount()).arg(m_PathName));
} else if (strncasecmp(m_Buffer, "#N", 2) == 0) {
int nc;
if (m_Scan && (sscanf(m_Buffer, "#N%d", &nc) == 1)) {
m_Scan -> setColumnCount(nc);
}
} else if (strncasecmp(m_Buffer, "#L", 2) == 0) {
if (m_Scan) {
m_Scan -> setColumnNames(m_Buffer);
// emit scanAdded(scanCount()-1);
}
} else if (strncasecmp(m_Buffer, "#D", 2) == 0) {
QDateTime dt = QDateTime::fromString(m_Buffer+2);
if (dt.isValid()) {
// printf("Valid date %s\n", m_Buffer+2);
// printf(" == %s\n", qPrintable(dt.toString("yyyyMMdd_hhmmss")));
if (m_Scan) {
m_Scan -> setScanDateTime(dt);
}
}
} else if (strncasecmp(m_Buffer, "#", 1) == 0) {
if (m_Scan) {
} else {
}
} else {
if (m_Scan) {
// printf("Append: <%s>\n", l);
m_Scan -> appendData(m_Buffer);
} else {
}
}
if (atEnd()) {
emit madeProgress(110);
// emit message(QString("File %1 scanned, %2 lines, longest %3")
// .arg(m_PathName).arg(m_NLines).arg(m_MaxLength));
// emit message(QString("%1 scans found\n").arg(scanCount()));
// printf("QseInputFile:: load completed\n");
// emitDataChanged();
}
m_Length = 0;
}
}
void QseInputFile::updateProgress ( )
private

Definition at line 50 of file qseinputfile.cpp.

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

Referenced by nextInputLine().

{
QMutexLocker lock(&m_Mutex);
qint64 sz = m_File.size();
qint64 pz = m_File.pos();
double pct = ((double) pz)/((double) sz)*100.0;
emit madeProgress((int) pct);
// QApplication::processEvents();
}

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_BufferSize
private

Definition at line 26 of file qseinputfile.h.

Referenced by nextInputLine(), and QseInputFile().

QFile QseInputFile::m_File
private

Definition at line 28 of file qseinputfile.h.

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

int QseInputFile::m_Length
private

Definition at line 25 of file qseinputfile.h.

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

int QseInputFile::m_MaxLength
private

Definition at line 31 of file qseinputfile.h.

Referenced by nextDataFile(), and nextInputLine().

int QseInputFile::m_NLines
private

Definition at line 30 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().

QString QseInputFile::m_PathName
private

Definition at line 27 of file qseinputfile.h.

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

QseScan* QseInputFile::m_Scan
private

Definition at line 32 of file qseinputfile.h.

Referenced by nextDataFile(), and nextInputLine().


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