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));
62std::vector<float> convertFromString<std::vector<float>>(StringView str)
65 std::vector<float> output;
66 output.reserve(parts.size());
67 for (
const StringView & part : parts) {
68 output.push_back(convertFromString<float>(part));
74Eigen::MatrixXd convertFromString<Eigen::MatrixXd>(StringView str)
76 const std::string input_str(str);
77 std::vector<std::vector<double>> values;
78 std::stringstream matrix_stream(input_str);
82 while (std::getline(matrix_stream, row_str,
',')) {
83 std::stringstream row_stream(row_str);
84 std::string value_str;
85 std::vector<double> row_values;
88 while (std::getline(row_stream, value_str,
';')) {
89 row_values.push_back(convertFromString<double>(value_str));
92 if (!row_values.empty()) {
93 values.push_back(row_values);
99 return Eigen::MatrixXd();
101 size_t rows = values.size();
102 size_t cols = values[0].size();
103 Eigen::MatrixXd matrix(rows, cols);
105 for (
size_t i = 0; i < rows; ++i) {
106 for (
size_t j = 0; j < std::min(cols, values[i].size()); ++j) {
107 matrix(i, j) = values[i][j];
114std::string
toStr(
const std::vector<uint8_t> & value)
116 return auto_apms_util::join(value,
";");
120std::string toStr<std::vector<bool>>(
const std::vector<bool> & value)
122 return auto_apms_util::join(value,
";");
126std::string toStr<std::vector<int64_t>>(
const std::vector<int64_t> & value)
128 return auto_apms_util::join(value,
";");
132std::string toStr<std::vector<double>>(
const std::vector<double> & value)
134 return auto_apms_util::join(value,
";");
138std::string toStr<Eigen::MatrixXd>(
const Eigen::MatrixXd & value)
140 Eigen::IOFormat fmt(Eigen::StreamPrecision, Eigen::DontAlignCols,
";",
",",
"",
"",
"",
"");
141 std::stringstream ss;
142 ss << value.format(fmt);
147std::string toStr<std::vector<std::string>>(
const std::vector<std::string> & value)
149 return auto_apms_util::join(value,
";");
std::vector< std::string > splitString(const std::string &str, const std::string &delimiter, bool remove_empty=true)
Split a string into multiple tokens using a specific delimiter string (Delimiter may consist of multi...
const char * toStr(const ActionNodeErrorCode &err)
Convert the action error code to string.