|
Enables reading of .csv files into MercuryDPM. More...
#include <csvReader.h>
Public Member Functions | |
csvReader () | |
Constructor. More... | |
void | read (const std::string &filename) |
Reads .csv files into Mercury. More... | |
std::vector< std::string > | getHeaderVector () |
Get the Header string vector of a .csv file. More... | |
void | setHeader (bool headings) |
Set the boolean hasHeader_. More... | |
std::vector< std::vector< std::string > > | getNumArray () |
Get the 2D array with the .csv file values. More... | |
std::vector< Mdouble > | getFirstColumn (Mdouble scalingFactor) |
Get first column of a .csv file and return it as a double. More... | |
std::vector< Mdouble > | getSecondColumn (Mdouble scalingFactor) |
Get second column of a .csv file and return it as a double. More... | |
Private Attributes | |
std::vector< std::vector< std::string > > | numArray_ |
std::vector< std::string > | headerVector_ |
std::vector< Mdouble > | CSVFirstColumn_ |
std::vector< Mdouble > | CSVSecondColumn_ |
bool | hasHeader_ = false |
Enables reading of .csv files into MercuryDPM.
the csvReader stores a 2D array of strings from a comma-separated value (.csv) file. In this way any data type from a .csv file can be read into Mercury and converted into other formats.
|
default |
Constructor.
Default constructor; sets every data member to 0 or default.
Get first column of a .csv file and return it as a double.
Gets the first column of the .csv file as a vector of doubles. It extracts the first column from the 2D array and converts the vector of strings into a vector of doubles.
References CSVFirstColumn_, constants::i, and numArray_.
Referenced by PSD::setPSDFromCSV().
std::vector< std::string > csvReader::getHeaderVector | ( | ) |
Get the Header string vector of a .csv file.
Gets the headerVector_ containing the values of the .csv file's first row.
References headerVector_.
std::vector< std::vector< std::string > > csvReader::getNumArray | ( | ) |
Get second column of a .csv file and return it as a double.
Gets the second column of the .csv file as a vector of doubles. It extracts the second column from the 2D array and converts the vector of strings into a vector of doubles.
References CSVSecondColumn_, constants::i, and numArray_.
Referenced by PSD::setPSDFromCSV().
void csvReader::read | ( | const std::string & | filename | ) |
Reads .csv files into Mercury.
Read function that divides each line of the .csv file into comma delimited fields which get stored in the numArray_. Further it checks for a byte order mark (BOM) and skips them if existent to avoid errors. If the hasHeader_ is set to TRUE the first row of the .csv file will be skipped.
[in] | filename | Name of the .csv file. |
References ERROR, hasHeader_, headerVector_, INFO, logger, and numArray_.
Referenced by PSD::setPSDFromCSV().
void csvReader::setHeader | ( | bool | hasHeader | ) |
Set the boolean hasHeader_.
Sets the boolean hasHeader_ which determines if the .csv file has headings.
References hasHeader_.
Referenced by PSD::setPSDFromCSV().
|
private |
vector of doubles containing all values of the .csv file's first column.
Referenced by getFirstColumn().
|
private |
vector of doubles containing all values of the .csv file's first column.
Referenced by getSecondColumn().
|
private |
if FALSE the file has no headers and if TRUE the file has headers and the first row will be skipped.
Referenced by read(), and setHeader().
|
private |
vector of strings containing possible header values of the .csv file's first row. This vector is only filled when headerFlag is set to TRUE.
Referenced by getHeaderVector(), and read().
|
private |
2D array containing all .csv file values
Referenced by getFirstColumn(), getNumArray(), getSecondColumn(), and read().