ADTF  3.18.2
CSVReader

Read, store and retrieve data from a comma separated value file (csv) More...

Public Member Functions

void readFile (const std::string &filename, char delimiter)
 Read data from a csv file and internally store it in a vector of string vectors. More...
 
std::vector< std::vector< std::string > > getData ()
 Get data from csv file as a vector of string vectors. More...
 
std::vector< std::string > getColumn (size_t column_number)
 Get the contents of the column identified by column_number. More...
 
std::vector< std::string > getRow (size_t row_number)
 Get the contents of the row identified by row_number. More...
 
std::string getElement (size_t column_number, size_t row_number)
 Get the content of a cell, identified by column_number and row_number. More...
 

Private Member Functions

void splitIntoSubstring (const std::string &data_string, const std::vector< char > &vector_split_point, std::vector< std::string > &vector_with_substrings)
 Split data from one line into vector elements according to the separator. More...
 

Private Attributes

std::vector< std::vector< std::string > > _data_matrix
 

Detailed Description

Read, store and retrieve data from a comma separated value file (csv)

Definition at line 26 of file csv_reader.h.

Member Function Documentation

◆ getColumn()

std::vector<std::string> getColumn ( size_t  column_number)

Get the contents of the column identified by column_number.

Parameters
[in]column_numberNumber of the column, first column being 0
Returns
Data of the entire column.

◆ getData()

std::vector<std::vector<std::string> > getData ( )

Get data from csv file as a vector of string vectors.

Returns
The data, organized in a 2 dimensional vector (first index is the row, second index the column)

◆ getElement()

std::string getElement ( size_t  column_number,
size_t  row_number 
)

Get the content of a cell, identified by column_number and row_number.

Parameters
[in]column_numberNumber of the column, first column being 0
[in]row_numberNumber of the row, first row being 0
Returns
Content of the specified cell

◆ getRow()

std::vector<std::string> getRow ( size_t  row_number)

Get the contents of the row identified by row_number.

Parameters
[in]row_numberNumber of the row, first row being 0
Returns
Data of the entire row

◆ readFile()

void readFile ( const std::string &  filename,
char  delimiter 
)

Read data from a csv file and internally store it in a vector of string vectors.

Parameters
[in]filenameFull path to the file
[in]delimiterThe delimiter separating the data cells (';' or ',' and '
')

◆ splitIntoSubstring()

void splitIntoSubstring ( const std::string &  data_string,
const std::vector< char > &  vector_split_point,
std::vector< std::string > &  vector_with_substrings 
)
private

Split data from one line into vector elements according to the separator.

Parameters
[in]data_stringReference to the string to be separated
[in]vector_split_pointReference to a vector of strings with the separators of data, (';' or ',') and line separator '
'
[in]vector_with_substringsReference to a vector of strings with the data separated as vector elements