21#ifndef CSVDATALOADER_H_
22#define CSVDATALOADER_H_
24#include <tulip/tulipconf.h>
25#include <tulip/CSVContentHandler.h>
41class TLP_QT_SCOPE CSVParser {
43 virtual ~CSVParser() {}
45 virtual char decimalMark()
const {
53 virtual bool parse(CSVContentHandler *handler, tlp::PluginProgress *progress =
nullptr,
54 bool firstLineOnly =
false) = 0;
70class TLP_QT_SCOPE CSVSimpleParser :
public CSVParser {
81 CSVSimpleParser(
const std::string &fileName,
const QString &separator =
";",
82 bool mergesep =
false,
char textDelimiter =
'"',
char delimiterMark =
'.',
83 bool considerAsString =
false,
84 const std::string &fileEncoding = std::string(
"UTF-8"),
85 unsigned int firstLine = 0,
unsigned int lastLine = UINT_MAX);
87 ~CSVSimpleParser()
override;
89 inline std::string fileName()
const {
92 inline void setFileName(
const std::string &fileName) {
96 inline char textDelimiter()
const {
97 return _textDelimiter;
100 char decimalMark()
const override {
104 inline void setTextDelimiter(
char delimiter) {
105 _textDelimiter = delimiter;
108 inline std::string fileEncoding()
const {
109 return _fileEncoding;
112 inline void setFileEncoding(
const std::string &fileEncoding) {
113 _fileEncoding = fileEncoding;
116 bool parse(CSVContentHandler *handler, tlp::PluginProgress *progress =
nullptr,
117 bool firstLineOnly =
false)
override;
120 virtual std::string treatToken(
const std::string &token,
int row,
int column);
123 void tokenize(
const std::string &str, std::vector<CSVToken> &tokens,
const QString &delimiters,
124 const bool mergedelim,
char _textDelimiter,
unsigned int numberOfCol);
125 std::string convertStringEncoding(
const std::string &toConvert,
const std::string& encoder);
131 bool multiplatformgetline(std::istream &is, std::string &str);
133 bool checkForContiguousTdlm(std::istream &is, std::string &str,
char sep,
bool tdlm);
134 std::string removeQuotesIfAny(std::string &s);
135 std::string _fileName;
139 std::string _fileEncoding;
140 unsigned int _firstLine;
141 unsigned int _lastLine;
142 bool _mergesep, _considerAsString;
148class 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();
157 bool parse(CSVContentHandler *handler, tlp::PluginProgress *progress =
nullptr,
158 bool firstLineOnly =
false)
override;
160 bool begin()
override;
161 bool line(
unsigned int row,
const std::vector<CSVToken> &lineTokens)
override;
162 bool end(
unsigned int rowNumber,
unsigned int columnNumber)
override;
166 CSVContentHandler *handler;
167 std::vector<std::vector<CSVToken>> columns;
168 unsigned int maxLineSize;
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...