#include <stdlib.h>
#include <boost/tokenizer.hpp>
#include <Wt/WAbstractItemModel.h>
#include <Wt/WString.h>
#include "CsvUtil.h"
Go to the source code of this file.
|
void | readFromCsv (std::istream &f, Wt::WAbstractItemModel *model, int numRows, bool firstLineIsHeaders) |
| Utility function that reads a model from a CSV file. More...
|
|
◆ readFromCsv()
void readFromCsv |
( |
std::istream & |
f, |
|
|
Wt::WAbstractItemModel * |
model, |
|
|
int |
numRows, |
|
|
bool |
firstLineIsHeaders |
|
) |
| |
Utility function that reads a model from a CSV file.
Definition at line 15 of file CsvUtil.C.
25 typedef boost::tokenizer<boost::escaped_list_separator<char> >
27 CsvTokenizer tok(line);
30 for (CsvTokenizer::iterator i = tok.begin();
31 i != tok.end(); ++i, ++col) {
33 if (col >= model->columnCount())
34 model->insertColumns(model->columnCount(),
35 col + 1 - model->columnCount());
37 if (firstLineIsHeaders && csvRow == 0)
38 model->setHeaderData(col, Wt::cpp17::any(Wt::WString(*i)));
40 int dataRow = firstLineIsHeaders ? csvRow - 1 : csvRow;
42 if (numRows != -1 && dataRow >= numRows)
45 if (dataRow >= model->rowCount())
46 model->insertRows(model->rowCount(),
47 dataRow + 1 - model->rowCount());
55 data = Wt::cpp17::any();
57 double d = strtod(s.c_str(), &endptr);
59 data = Wt::cpp17::any(d);
61 data = Wt::cpp17::any(Wt::WString(s));
64 model->setData(dataRow, col, data);