30#include <spdlog/fmt/fmt.h>
35#include <SettingReader.h>
36#include <cRIO/DataTypes.h>
43std::string rowToStr(std::vector<std::string> row);
48 static void loadTable(
size_t columnsToSkip,
size_t columnsToKeep, std::vector<t> *data,
49 const std::string &filename);
50 static void loadLimitTable(
size_t columnsToSkip, std::vector<Limit> *data,
const std::string &filename);
51 static void loadForceLimitTable(
size_t columnsToSkip,
float zLow[FA_Z_COUNT],
float zHigh[FA_Z_COUNT],
52 float yLow[FA_Y_COUNT],
float yHigh[FA_Y_COUNT],
float xLow[FA_X_COUNT],
53 float xHigh[FA_X_COUNT],
const std::string &filename);
57void TableLoader::loadTable(
size_t columnsToSkip,
size_t columnsToKeep, std::vector<t> *data,
58 const std::string &filename) {
59 std::string fullPath = SettingReader::instance().getTablePath(filename);
61 rapidcsv::Document table(fullPath, rapidcsv::LabelParams(), rapidcsv::SeparatorParams(),
62 rapidcsv::ConverterParams(), rapidcsv::LineReaderParams(
true,
'#'));
64 if (columnsToSkip + columnsToKeep != table.GetColumnCount()) {
65 throw std::runtime_error(fmt::format(
"CSV {} has {} columns, expected {}", fullPath,
66 table.GetColumnCount(), columnsToSkip + columnsToKeep));
68 for (
size_t row = 0; row < table.GetRowCount(); row++) {
69 for (
size_t column = columnsToSkip; column < columnsToSkip + columnsToKeep; column++) {
71 data->push_back(table.GetCell<t>(column, row));
72 }
catch (std::logic_error &er) {
73 throw std::runtime_error(fmt::format(
"{}:{}:{}: cannot parse {}: {}", fullPath, row,
74 column, table.GetCell<std::string>(column, row),
79 }
catch (std::ios_base::failure &er) {
80 throw std::runtime_error(fmt::format(
"Cannot read CSV {}: {}", fullPath, er.what()));
Definition TableLoader.h:45