SMACC
SMACC copied to clipboard
setGlobalSMData not working with "non-streamable" objects
I was looking for a way to transfer data between states. In particular a std::filesystem::path
and a Eigen::Isometry3d
object.
For this purpose, I came across the setGlobalSMData
and getGlobalSMData
functions that the state machine support. As the functions are templated, it looked like they would support any type.
However, when I try to store an Eigen::Isometry3d
object using setGlobalSMData
, I get the following error:
error: no match for ‘operator<<’ (operand types are ‘std::stringstream’ {aka ‘std::__cxx11::basic_stringstream<char>’} and ‘Eigen::Transform<double, 3, 1>’)
The source code for setGlobalSMData
:
https://github.com/robosoft-ai/SMACC/blob/e5abc09c51b16a8911b2516892afc953a00020ea/smacc/include/smacc/impl/smacc_state_machine_impl.h#L208-L224
The build error is due to the val
object (casted to Eigen::Isometry3d
) being inserted into the stream. As the object does not define a <<
operator, this results in the abovementioned error.
Why is globalData_
of type std::map<std::string, std::pair<std::function<std::string()>, boost::any>>
and not just std::map<std::string, boost::any>>
? The first element of the std::pair
is not used in getGlobalSMData
so I am not sure why we need the function object.