15#include "auto_apms_behavior_tree_core/convert.hpp"
19#include "auto_apms_util/string.hpp"
26std::vector<uint8_t> convertFromString<std::vector<uint8_t>>(StringView str)
28 auto parts = BT::splitString(str,
';');
29 std::vector<uint8_t> output;
30 output.reserve(parts.size());
31 for (
const StringView & part : parts) {
32 output.push_back(convertFromString<uint8_t>(part));
38std::vector<bool> convertFromString<std::vector<bool>>(StringView str)
40 auto parts = BT::splitString(str,
';');
41 std::vector<bool> output;
42 output.reserve(parts.size());
43 for (
const StringView & part : parts) {
44 output.push_back(convertFromString<bool>(part));
50std::vector<int64_t> convertFromString<std::vector<int64_t>>(StringView str)
52 auto parts = BT::splitString(str,
';');
53 std::vector<int64_t, std::allocator<int64_t>> output;
54 output.reserve(parts.size());
55 for (
const StringView & part : parts) {
56 output.push_back(convertFromString<int64_t>(part));
62Eigen::MatrixXd convertFromString<Eigen::MatrixXd>(StringView str)
64 const std::string input_str(str);
65 std::vector<std::vector<double>> values;
66 std::stringstream matrix_stream(input_str);
70 while (std::getline(matrix_stream, row_str,
',')) {
71 std::stringstream row_stream(row_str);
72 std::string value_str;
73 std::vector<double> row_values;
76 while (std::getline(row_stream, value_str,
';')) {
77 row_values.push_back(convertFromString<double>(value_str));
80 if (!row_values.empty()) {
81 values.push_back(row_values);
87 return Eigen::MatrixXd();
89 size_t rows = values.size();
90 size_t cols = values[0].size();
91 Eigen::MatrixXd matrix(rows, cols);
93 for (
size_t i = 0; i < rows; ++i) {
94 for (
size_t j = 0; j < std::min(cols, values[i].size()); ++j) {
95 matrix(i, j) = values[i][j];
102std::string
toStr(
const std::vector<uint8_t> & value)
104 return auto_apms_util::join(value,
";");
108std::string toStr<std::vector<bool>>(
const std::vector<bool> & value)
110 return auto_apms_util::join(value,
";");
114std::string toStr<std::vector<int64_t>>(
const std::vector<int64_t> & value)
116 return auto_apms_util::join(value,
";");
120std::string toStr<std::vector<double>>(
const std::vector<double> & value)
122 return auto_apms_util::join(value,
";");
126std::string toStr<Eigen::MatrixXd>(
const Eigen::MatrixXd & value)
128 Eigen::IOFormat fmt(Eigen::StreamPrecision, Eigen::DontAlignCols,
";",
",",
"",
"",
"",
"");
129 std::stringstream ss;
130 ss << value.format(fmt);
135std::string toStr<std::vector<std::string>>(
const std::vector<std::string> & value)
137 return auto_apms_util::join(value,
";");
const char * toStr(const ActionNodeErrorCode &err)
Convert the action error code to string.