#include <iostream>
Go to the source code of this file.
|
void | readFromCsv (std::istream &f, Wt::WAbstractItemModel *model, int numRows=-1, bool firstLineIsHeaders=true) |
|
Wt::WStandardItemModel * | csvToModel (const std::string &csvFile, Wt::WObject *parent, bool firstLineIsHeader=true) |
|
Wt::WStandardItemModel* csvToModel |
( |
const std::string & |
csvFile, |
|
|
Wt::WObject * |
parent, |
|
|
bool |
firstLineIsHeader = true |
|
) |
| |
Definition at line 40 of file CsvUtil.C.
44 std::ifstream f(csvFile.c_str());
47 Wt::WStandardItemModel *result =
new Wt::WStandardItemModel(0, 0, parent);
void readFromCsv(std::istream &f, Wt::WAbstractItemModel *model, int numRows, bool firstLineIsHeaders)
Utility function that reads a model from a CSV file.
void readFromCsv |
( |
std::istream & |
f, |
|
|
Wt::WAbstractItemModel * |
model, |
|
|
int |
numRows = -1 , |
|
|
bool |
firstLineIsHeaders = true |
|
) |
| |
Definition at line 55 of file CsvUtil.C.
65 typedef boost::tokenizer<boost::escaped_list_separator<char> >
67 CsvTokenizer tok(line);
70 for (CsvTokenizer::iterator i = tok.begin();
71 i != tok.end(); ++i, ++col) {
73 if (col >= model->columnCount())
74 model->insertColumns(model->columnCount(),
75 col + 1 - model->columnCount());
77 if (firstLineIsHeaders && csvRow == 0)
78 model->setHeaderData(col, boost::any(Wt::WString::fromUTF8(*i)));
80 int dataRow = firstLineIsHeaders ? csvRow - 1 : csvRow;
82 if (numRows != -1 && dataRow >= numRows)
85 if (dataRow >= model->rowCount())
86 model->insertRows(model->rowCount(),
87 dataRow + 1 - model->rowCount());
89 boost::any data(Wt::WString::fromUTF8(*i));
90 model->setData(dataRow, col, data);