Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// CSVReader.h
#pragma once
#include <fstream>
#include <vector>
#include <string>
#include <memory>
namespace math1d_cl
{
/**
* @brief CSVReader reads CSV files.
* @details Reads CSV files. Parses first line as header. Returns empty lines as empty row.
*
* @param decimal decimal point char
* @param separator column separator char
*
*/
class CSVReader
{
public:
CSVReader(char decimal, char separator);
void open(std::string file);
void close();
std::shared_ptr<std::vector<std::string>> getRow();
std::shared_ptr<std::vector<std::string>> getHeader();
bool eof();
private:
void explode(std::string input, std::shared_ptr<std::vector<std::string>> output, const char delimiter);
std::ifstream m_fileStream; // Input file stream
std::shared_ptr<std::vector<std::string>> m_header; // CSV Header
const char m_decimal;
const char m_separator;
};
}