#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) |
|
§ csvToModel()
Wt::WStandardItemModel* csvToModel |
( |
const std::string & |
csvFile, |
|
|
Wt::WObject * |
parent, |
|
|
bool |
firstLineIsHeader = true |
|
) |
| |
Definition at line 41 of file CsvUtil.C.
45 std::ifstream f(csvFile.c_str());
48 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.
§ readFromCsv()
void readFromCsv |
( |
std::istream & |
f, |
|
|
Wt::WAbstractItemModel * |
model, |
|
|
int |
numRows = -1 , |
|
|
bool |
firstLineIsHeaders = true |
|
) |
| |
Definition at line 56 of file CsvUtil.C.
66 typedef boost::tokenizer<boost::escaped_list_separator<char> >
68 CsvTokenizer tok(line);
71 for (CsvTokenizer::iterator i = tok.begin();
72 i != tok.end(); ++i, ++col) {
74 if (col >= model->columnCount())
75 model->insertColumns(model->columnCount(),
76 col + 1 - model->columnCount());
78 if (firstLineIsHeaders && csvRow == 0)
79 model->setHeaderData(col, boost::any(Wt::WString::fromUTF8(*i)));
81 int dataRow = firstLineIsHeaders ? csvRow - 1 : csvRow;
83 if (numRows != -1 && dataRow >= numRows)
86 if (dataRow >= model->rowCount())
87 model->insertRows(model->rowCount(),
88 dataRow + 1 - model->rowCount());
90 boost::any data(Wt::WString::fromUTF8(*i));
91 model->setData(dataRow, col, data);