Allolib
1.0
C++ Components For Interactive Multimedia
|
The CSVReader class reads simple CSV files. More...
Public Types | |
enum | DataType { STRING , REAL , INT64 , BOOLEAN , IGNORE_COLUMN } |
Public Member Functions | |
bool | readFile (std::string fileName, bool hasColumnNames=true) |
readFile reads the CSV file into internal memory More... | |
void | addType (DataType type) |
addType More... | |
void | clearTypes () |
template<class DataStruct > | |
std::vector< DataStruct > | copyToStruct () |
getColumn returns a column from the csv file More... | |
std::vector< double > | getColumn (int index) |
getColumn returns a column from the csv file More... | |
std::vector< std::string > | getColumnNames () |
get names of the columns in CSV file More... | |
void | setBasePath (std::string basePath) |
Protected Member Functions | |
size_t | calculateRowLength () |
Protected Attributes | |
const size_t | maxStringSize = 32 |
std::vector< std::string > | mColumnNames |
std::vector< DataType > | mDataTypes |
std::vector< char * > | mData |
std::string | mBasePath |
The CSVReader class reads simple CSV files.
To use, first create a CSVReader object and call addType() to add the type of a column. Then call readFile().
Once the file is in memory it can be read as columns of floats using getColumn(). Or the whole CSV data can be copied to memory by defining a struct that will hold the values from each row from the csv file and calling copyToStruct() to create a vector with the data from the CSV file.
This reader is currently very naive (but efficient) and might choke with complex or malformed CSV files.
Definition at line 111 of file al_CSVReader.hpp.
|
inline |
|
inline |
getColumn returns a column from the csv file
index | column index |
Definition at line 143 of file al_CSVReader.hpp.
std::vector<double> al::CSVReader::getColumn | ( | int | index | ) |
getColumn returns a column from the csv file
index | column index |
|
inline |
get names of the columns in CSV file
Must be called after readFile(), otherwise an empty vector is returned.
Definition at line 173 of file al_CSVReader.hpp.
bool al::CSVReader::readFile | ( | std::string | fileName, |
bool | hasColumnNames = true |
||
) |
readFile reads the CSV file into internal memory
fileName | the csv file name |
hasColumnNames | if true, the first line in the file is interpreted as column names |