Skip to content

setGlobalSMData not working with "non-streamable" objects #117

@dave992

Description

@dave992

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:

void ISmaccStateMachine::setGlobalSMData(std::string name, T value)
{
{
std::lock_guard<std::recursive_mutex> lock(m_mutex_);
// ROS_WARN("set SM Data lock acquire");
globalData_[name] = {[this, name]() {
std::stringstream ss;
auto val = any_cast<T>(globalData_[name].second);
ss << val;
return ss.str();
},
value};
}
this->updateStatusMessage();
}

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.

┆Issue is synchronized with this Jira Task by Unito

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions