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() {}
47 virtual char decimalMark()
const {
56 bool firstLineOnly =
false) = 0;
72 class TLP_QT_SCOPE CSVSimpleParser :
public CSVParser {
83 CSVSimpleParser(
const std::string &fileName,
const QString &separator =
";",
84 const bool mergesep =
false,
char textDelimiter =
'"',
char delimiterMark =
'.',
85 const std::string &fileEncoding = std::string(
"UTF-8"),
86 unsigned int firstLine = 0,
unsigned int lastLine = UINT_MAX);
88 ~CSVSimpleParser()
override;
90 inline std::string fileName()
const {
93 inline void setFileName(
const std::string &fileName) {
97 inline char textDelimiter()
const {
98 return _textDelimiter;
101 char decimalMark()
const override {
105 inline void setTextDelimiter(
char delimiter) {
106 _textDelimiter = delimiter;
109 inline std::string fileEncoding()
const {
110 return _fileEncoding;
113 inline void setFileEncoding(
const std::string &fileEncoding) {
114 _fileEncoding = fileEncoding;
118 bool firstLineOnly =
false)
override;
121 virtual std::string treatToken(
const std::string &token,
int row,
int column);
124 void tokenize(
const std::string &str, std::vector<std::string> &tokens,
const QString &delimiters,
125 const bool mergedelim,
char _textDelimiter,
unsigned int numberOfCol);
126 std::string convertStringEncoding(
const std::string &toConvert, QTextCodec *encoder);
132 bool multiplatformgetline(std::istream &is, std::string &str);
134 std::string removeQuotesIfAny(std::string &s);
135 std::string _fileName;
139 std::string _fileEncoding;
140 unsigned int _firstLine;
141 unsigned int _lastLine;
148 class TLP_QT_SCOPE CSVInvertMatrixParser :
public tlp::CSVParser,
public tlp::CSVContentHandler {
150 CSVInvertMatrixParser(CSVParser *parser);
151 ~CSVInvertMatrixParser()
override;
153 char decimalMark()
const override {
154 return parser->decimalMark();
158 bool firstLineOnly =
false)
override;
160 bool begin()
override;
161 bool line(
unsigned int row,
const std::vector<std::string> &lineTokens)
override;
162 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
166 CSVContentHandler *handler;
167 std::vector<std::vector<std::string>> columns;
168 unsigned int maxLineSize;
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...