21 #ifndef CSVDATALOADER_H_
22 #define CSVDATALOADER_H_
24 #include <tulip/tulipconf.h>
25 #include <tulip/CSVContentHandler.h>
43 class TLP_QT_SCOPE CSVParser {
45 virtual ~CSVParser() {}
67 class TLP_QT_SCOPE CSVSimpleParser :
public CSVParser {
77 CSVSimpleParser(
const std::string& fileName,
const QString &separator=
";",
const bool mergesep=
false,
char textDelimiter=
'"',
const std::string& fileEncoding=std::string(
"UTF-8"),
unsigned int firstLine = 0,
unsigned int lastLine = UINT_MAX);
79 virtual ~CSVSimpleParser();
81 inline std::string fileName()
const {
84 inline void setFileName(
const std::string& fileName) {
88 inline char textDelimiter()
const {
89 return _textDelimiter;
92 inline void setTextDelimiter(
char delimiter) {
93 _textDelimiter = delimiter;
96 inline std::string fileEncoding()
const {
100 inline void setFileEncoding(
const std::string& fileEncoding) {
101 _fileEncoding = fileEncoding;
107 virtual std::string treatToken(
const std::string& token,
int row,
int column);
110 void tokenize(
const std::string& str, std::vector<std::string>& tokens,
111 const QString &delimiters,
const bool mergedelim,
char _textDelimiter,
unsigned int numberOfCol);
112 std::string convertStringEncoding(
const std::string& toConvert,QTextCodec* encoder);
117 bool multiplatformgetline ( std::istream& is, std::string& str );
119 std::string removeQuotesIfAny(
const std::string &s,
const std::string& rejectedChars);
120 std::string _fileName;
123 std::string _fileEncoding;
124 unsigned int _firstLine;
125 unsigned int _lastLine;
133 class TLP_QT_SCOPE CSVInvertMatrixParser :
public tlp::CSVParser ,
public tlp::CSVContentHandler {
135 CSVInvertMatrixParser(CSVParser* parser);
136 virtual ~CSVInvertMatrixParser();
141 void line(
unsigned int row,
const std::vector<std::string>& lineTokens);
142 void end(
unsigned int rowNumber,
unsigned int columnNumber);
145 CSVContentHandler *handler;
146 std::vector<std::vector<std::string> > columns;
147 unsigned int maxLineSize;