36 {
38 {
39 std::cout << "ReadCsv(): [Warning] File " << file_path << " does not exist." << std::endl;
40 exit(EXIT_FAILURE);
41 }
42
43 file_.open(file_path);
44
45
47
48
50
51 if (first_value_row < 1)
52 {
53 std::cout << "ReadCsv():Error: No header in CSV file" << std::endl;
54 exit(EXIT_FAILURE);
55 }
56
58
59
60 if (first_value_row > 0)
61 {
63 }
64
67 {
68 csv_data_int[it->second].resize(rows - 1, 0.0);
69 }
70
71
72 std::string line;
73 int line_counter = 0;
74 int parsed_row_counter = first_value_row;
75
76 while (std::getline(
file_, line))
77 {
78 std::stringstream row_stream(line);
79 std::string token;
80 int column_counter = 0;
81
82 double item;
83 while (std::getline(row_stream, token,
delim))
84 {
86 {
87 std::cout << "ReadCsv(): Warning: too many entries in row!" << std::endl;
88 ++column_counter;
89 break;
90 }
91
92 std::istringstream is(token);
93 is >> item;
94 csv_data_int[
header_map[column_counter]][line_counter] = (item);
95 ++column_counter;
96 }
97
98
100 {
101 std::cout << "ReadCsv(): Warning: corrupted row=" << parsed_row_counter << " will be skipped!" << std::endl;
102 }
103 else
104 {
105 line_counter++;
106 }
107
108
109 parsed_row_counter++;
110 }
111
112
114 {
115 csv_data_int[it->second].resize(line_counter);
116 }
117
119
120 *csv_data = csv_data_int;
121 }
HeaderMapType get_header(const int &row=0)
Definition read_csv.h:126
char delim
Definition read_csv.h:31
int check_for_header()
Definition read_csv.h:151
void set_line_couter_of_file(const int &line_number)
Definition read_csv.h:170
std::ifstream file_
Definition read_csv.h:124
int get_rows()
Definition read_csv.h:182
HeaderMapType header_map
Definition read_csv.h:32
static bool IsFile(const std::string &name)
filesystem::IsFile Check if the given path results in a file
std::map< std::string, std::vector< double > > CsvDataType
Definition read_csv.h:26