51 CSVReader::CSVReader() : _header(false), _skip(0),
52 _delimiter(
','), _keepParts(true), _lines(),
53 _ignoreComments(true) { }
82 const char &delimiter,
const bool keepEmptyParts,
83 const bool ignoreComments) :
84 _header(header), _skip(skip), _delimiter(delimiter),
85 _keepParts(keepEmptyParts), _lines(),
86 _ignoreComments(ignoreComments) {
135 return ((summary.
size() > 0) ? summary.
key(0) : 0);
157 ifstream ifile(csvfile.toLatin1().data(), ios::in);
159 QString mess =
"Unable to open file [" + csvfile +
"]";
206 if((index < 0) || (index >=
rows())) {
244 for(
int i = 0 ; i < nrows ; i++) {
246 if(parser.
size() <= index) {
251 column[i] = parser(index);
256 return ((nbad == nrows) ?
CSVAxis(0) : column);
282 QString head = hname.trimmed();
283 for(
int i = 0 ; i < header.dim() ; i++) {
284 if(head.toLower() == header[i].trimmed().toLower()) {
322 for(
int row = 0 ; row < nrows ; row++) {
324 table[row] = parser.
result();
363 for(
int row = 0 ; row < table.dim() ; row++) {
364 int n(table[row].dim());
366 int &count = summary.
get(n);
390 return (summary.
size() <= 1);
422 while(getline(ifile, iline)) {
425 _lines.push_back(iline.c_str());
433 mess <<
"Error reading line [" << (nlines + 1) <<
"]" << ends;
464 return (csv.
load(is));
std::istream & load(std::istream &ifile)
Reads all lines from the input stream until an EOF is encoutered.
CSVList _lines
List of lines from file.
CSVTable getTable() const
Parse and return all rows and columns in a table array.
CSV Parser seperates fields (tokens) from a string with a delimeter.
T & get(const K &key)
Returns the value associated with the name provided.
CSVColumnSummary getColumnSummary(const CSVTable &table) const
Computes a row summary of the number of distinct columns in table.
void read(const QString &fname)
Reads the entire contents of a file for subsequent parsing.
TokenList result() const
Returns the list of tokens.
int firstRowIndex() const
Computes the index of the first data.
int _skip
Number of lines to skip.
int parse(const QString &str, const char &delimiter=',', bool keepEmptyParts=true)
Parser method accepting string, delimiter and multiple token handling.
CSVParser< QString > Parser
Defines single line parser.
Namespace for the standard library.
int size() const
Returns the size of the collection.
bool _keepParts
Keep empty parts between delimiter.
bool _header
Indicates presences of header.
char _delimiter
Separator of values.
const K & key(int nth) const
Returns the nth key in the collection.
int rows() const
Reports the number of rows in the table.
bool exists(const K &key) const
Checks the existance of a particular key in the list.
#define _FILEINFO_
Macro for the filename and line number.
void add(const K &key, const T &value)
Adds the element to the list.
std::istream & operator>>(std::istream &is, CSVReader &csv)
Input read operator for input stream sources.
int size() const
Returns the number of tokens in the parsed string.
A type of error that could only have occurred due to a mistake on the user's part (e...
CSVAxis getRow(int index) const
Parse and return the requested row by index.
CSVAxis getColumn(int index) const
Parse and return a column specified by index order.
Parser::TokenList CSVAxis
Row/Column token list.
Reads strings and parses them into tokens separated by a delimiter character.
int columns() const
Determine the number of columns in the input source.
Collector/container for arbitrary items.
bool isTableValid(const CSVTable &table) const
Indicates if all rows have the same number of columns.
CSVReader()
Default constructor for CSV reader.
Namespace for ISIS/Bullet specific routines.
TNT::Array1D< CSVAxis > CSVTable
Table of all rows/columns.
CSVAxis getHeader() const
Retrieve the header from the input source if it exists.
bool _ignoreComments
Ignore comments on read.