26 using CsvDataType = std::map<std::string, std::vector<double>>;
39 std::cout <<
"ReadCsv(): [Warning] File " << file_path <<
" does not exist." << std::endl;
43 file_.open(file_path);
51 if (first_value_row < 1)
53 std::cout <<
"ReadCsv():Error: No header in CSV file" << std::endl;
60 if (first_value_row > 0)
68 csv_data_int[it->second].resize(rows - 1, 0.0);
74 int parsed_row_counter = first_value_row;
76 while (std::getline(
file_, line))
78 std::stringstream row_stream(line);
80 int column_counter = 0;
83 while (std::getline(row_stream, token,
delim))
87 std::cout <<
"ReadCsv(): Warning: too many entries in row!" << std::endl;
92 std::istringstream is(token);
94 csv_data_int[
header_map[column_counter]][line_counter] = (item);
101 std::cout <<
"ReadCsv(): Warning: corrupted row=" << parsed_row_counter <<
" will be skipped!" << std::endl;
109 parsed_row_counter++;
115 csv_data_int[it->second].resize(line_counter);
120 *csv_data = csv_data_int;
134 std::getline(
file_, line);
135 std::stringstream row_stream(line);
138 while (std::getline(row_stream, token,
delim))
140 token.erase(remove_if(token.begin(), token.end(), isspace), token.end());
142 header_data[count] = token;
147 file_.seekg(0, std::ios::beg);
155 while (std::getline(
file_, line))
157 if (std::isdigit(line[line.find_first_not_of(
" \t")]))
166 file_.seekg(0, std::ios::beg);
173 file_.seekg(0, std::ios::beg);
176 for (
int k = 0; k < line_number; k++)
178 std::getline(
file_, line);
186 while (std::getline(
file_, line))
191 file_.seekg(0, std::ios::beg);
Definition: read_csv.h:30
HeaderMapType get_header(const int &row=0)
Definition: read_csv.h:126
ReadCsv(CsvDataType *csv_data, const std::string &file_path, char delim_=',')
Definition: read_csv.h:35
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
std::map< int, std::string > HeaderMapType
Definition: read_csv.h:27