ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
First of all, ROS itself uses yaml-cpp, so that's not a bad way to go about it.
Second, I'd like to propose an alternative way to solve your problem (since I've just done the same thing myself). roslaunch
supports all forms of XmlRpc values, including lists. Therefore, you can use the following code:
XmlRpc::XmlRpcValue topicList;
std::vector<std::string> topics;
if (private_nh.getParam("topics", topicList))
{
std::map<std::string, XmlRpc::XmlRpcValue>::iterator i;
for (i = topicList.begin(); i != topicList.end(); i++)
{
std::string topic_name;
std::string topic_type;
topic_name = i->first;
topic_type.assign(i->second["topic_type"]);
topics.push_back(topic_name);
}
}
Essentially, this code will read all parameters that are under the "topics" namespace into a single list. You then iterate through that list to grab all topic names. Each new topic can have as many sub-fields (topic_type) as you desire. Here's an example launchfile statement for the above code.
<launch>
<node pkg="my_package" type="my_node" name="my_node" output="screen">
<param name="topics/topic1/topic_type" type="string" value="sensor_msgs/LaserScan" />
<param name="topics/topic2/topic_type" type="string" value="sensor_msgs/PointCloud2" />
</node>
</launch