Ksetiwatch API Documentation


CSVDataBase Class Reference

A class that allows reading of csv files. More...

#include <csvdatabase.h>

Inherits QFile.

Inheritance diagram for CSVDataBase:

Inheritance graph
[legend]
Collaboration diagram for CSVDataBase:

Collaboration graph
[legend]
List of all members.

Public Methods

 CSVDataBase (const char *file=0)
 ~CSVDataBase ()
QString readItem (int column, int line)
QString readItem (const char *identifier, int line)
int columnCount ()

Protected Methods

int readItems (const char *linestr, QStrList *strlist)
int readDefinitionLine ()
int readCurrentLine (int line)
QString readLine (int line)
QString readNextLine ()
QString readItem (int column, const char *linestr)
QString readItem (const char *identifier)

Detailed Description

A class that allows reading of csv files.

This class allows access to the elements of a comma-separated-value (csv) file. It doesn't store the entire array in memory, but reads and processes the elements line-by-line. The first line of the csv file must be a header line which consists of ID strings defining the contents of the columns.

Definition at line 30 of file csvdatabase.h.


Constructor & Destructor Documentation

CSVDataBase::CSVDataBase const char *    file = 0
 

The constructor.

Initializes the access to a csv file.

Parameters:
file  The file name. If the pointer is 0, an uninitialized object is created, and the file name must be set with setName().

Definition at line 19 of file csvdatabase.cpp.

References QFile::setName().

CSVDataBase::~CSVDataBase  
 

The destructor.

Definition at line 30 of file csvdatabase.cpp.


Member Function Documentation

QString CSVDataBase::readItem int    column,
int    line
 

Reads an element from the csv file.

The element is read from column column and line line.

Parameters:
column  The column number of the element.
line  The line number of the element.
Returns:
The element at the given position, or an empty string if the element could not be read.

Definition at line 71 of file csvdatabase.cpp.

References readCurrentLine().

Referenced by CompletedWUList::addLoggedWU(), CompletedWUList::fillTotalList(), CompletedWUList::fillWUList(), and readItem().

QString CSVDataBase::readItem const char *    identifier,
int    line
 

Reads an element from the csv file.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The element is read from the column specified by identifier and line line.

Parameters:
identifier  The identifier string of the column.
line  The line number.
Returns:
The element at the given position, or an empty string if the element could not be read.

Definition at line 82 of file csvdatabase.cpp.

References QString::isEmpty(), readCurrentLine(), readDefinitionLine(), and readItem().

int CSVDataBase::columnCount  
 

Returns the number of columns in the csv file.

Definition at line 183 of file csvdatabase.cpp.

References QString::isEmpty(), and readDefinitionLine().

Referenced by SetiLoc::logWorkUnit().

int CSVDataBase::readItems const char *    linestr,
QStrList   strlist
[protected]
 

Reads all elements of a line.

Reads all elements of the line linestr and stores them in the string list strlist.

Parameters:
linestr  A string containing a line of a csv file.
strlist  A pointer to a QStrList where the elements are stored.
Returns:
The number of elements in the line.

Definition at line 35 of file csvdatabase.cpp.

Referenced by readCurrentLine(), and readDefinitionLine().

int CSVDataBase::readDefinitionLine   [protected]
 

Reads the definition line.

The definition (or header) line must always be the first line of a csv file.

Returns:
The number of columns in the definition line.

Definition at line 154 of file csvdatabase.cpp.

References readItems(), and QIODevice::readLine().

Referenced by columnCount(), and readItem().

int CSVDataBase::readCurrentLine int    line [protected]
 

Reads the current line.

line becomes the current line.

Parameters:
line  The line to be read.
Returns:
The number of columns in the line.

Definition at line 165 of file csvdatabase.cpp.

References readItems(), QIODevice::readLine(), and readNextLine().

Referenced by readItem().

QString CSVDataBase::readLine int    line [protected]
 

Reads a line and returns it in a string.

Parameters:
line  The line to be read.
Returns:
A string containing the line, or an empty string if the line number is too high.

Definition at line 118 of file csvdatabase.cpp.

References QFile::at(), QTextStream::atEnd(), QIODevice::isOpen(), QIODevice::isReadable(), and QTextStream::readLine().

QString CSVDataBase::readNextLine   [protected]
 

Reads a line at the current file index and returns it in a string.

Returns:
A string containing the line, or an empty string if the file index is at the end of the file.

Definition at line 140 of file csvdatabase.cpp.

References QTextStream::atEnd(), QIODevice::isOpen(), QIODevice::isReadable(), and QTextStream::readLine().

Referenced by readCurrentLine().

QString CSVDataBase::readItem int    column,
const char *    linestr
[protected]
 

Extracts an element from a string.

The element at column column is read from the string linestr.

Parameters:
column  The column number of the element.
linestr  A string containing a line of a csv file.
Returns:
A string containing the line, or an empty string if the column number is too high.

QString CSVDataBase::readItem const char *    identifier [protected]
 

Extracts an element from a string.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The element is read from the column specified by identifier in the current line.

Parameters:
identifier  The identifier string of the column.
Returns:
A string containing the line, or an empty string if the column number is too high.

Definition at line 92 of file csvdatabase.cpp.

References QString::isEmpty().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for Ksetiwatch API Version 2.6.1.
Documentation copyright © 2000-2003 Gordon Machel.
Generated on Fri Jun 6 00:28:41 2003 by doxygen 1.2.18, written by Dimitri van Heesch, © 1997-2002