1 #ifndef INCLUDE_AL_CSVREADER_HPP
2 #define INCLUDE_AL_CSVREADER_HPP
113 typedef enum { STRING, REAL, INT64, BOOLEAN, IGNORE_COLUMN } DataType;
127 bool readFile(std::string fileName,
bool hasColumnNames =
true);
133 void addType(DataType type) { mDataTypes.push_back(type); }
135 void clearTypes() { mDataTypes.clear(); }
142 template <
class DataStruct>
144 std::vector<DataStruct> output;
145 if (
sizeof(DataStruct) < calculateRowLength()) {
146 std::cout <<
"WARNING: DataStruct size is too small for CSV file!"
150 for (
auto row : mData) {
151 DataStruct newValues;
152 memset(&newValues, 0,
sizeof(DataStruct));
153 memcpy(&newValues, row,
sizeof(newValues));
154 output.push_back(newValues);
175 void setBasePath(std::string basePath) { mBasePath = basePath; }
178 size_t calculateRowLength();
180 const size_t maxStringSize = 32;
182 std::vector<std::string> mColumnNames;
183 std::vector<DataType> mDataTypes;
184 std::vector<char *> mData;
186 std::string mBasePath;
The CSVReader class reads simple CSV files.
std::vector< DataStruct > copyToStruct()
getColumn returns a column from the csv file
bool readFile(std::string fileName, bool hasColumnNames=true)
readFile reads the CSV file into internal memory
void addType(DataType type)
addType
std::vector< std::string > getColumnNames()
get names of the columns in CSV file
std::vector< double > getColumn(int index)
getColumn returns a column from the csv file