ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I've modified my question to match the real problem and answer to it. Reading a yamlis quite heavy in C++, here's a way to read a map of arrays for instance:

                XmlRpc::XmlRpcValue symbols;

                if(!ros::param::get("/thr/symbols", symbols))
                    ROS_ERROR("Failed to read symbols on param server");

                ROS_ASSERT(symbols.getType()==XmlRpc::XmlRpcValue::TypeStruct);
                for(int i=0; i<symbols.size(); ++i) {
                    for (XmlRpc::XmlRpcValue::iterator i=symbols.begin(); i!=symbols.end(); ++i) {
                        ROS_ASSERT(i->second.getType()==XmlRpc::XmlRpcValue::TypeArray);
                        for(int j=0; j<i->second.size(); ++j) {
                            ROS_ASSERT(i->second[j].getType()==XmlRpc::XmlRpcValue::TypeDouble);
                        }
                    }
                }

With YAML being:

object0: [0.1280805148444952, -0.2574350304851667]
table: [-0.019239830108468144]
object1: [-0.12373553201812965, -0.2581443366277866, 0.12297468008504482, 0.0405834453536516, 0.9474896873206372, -0.026972527372781926]
arm: [0.9303491449393159]
eye: [0.12397546355498722 -0.37202872219628474]

I've modified my question to match the real problem and answer to it. Reading a yamlis quite heavy in C++, here's a way to read a map of arrays for instance:

                XmlRpc::XmlRpcValue symbols;

                if(!ros::param::get("/thr/symbols", symbols))
                    ROS_ERROR("Failed to read symbols on param server");

                ROS_ASSERT(symbols.getType()==XmlRpc::XmlRpcValue::TypeStruct);
                for(int i=0; i<symbols.size(); ++i) {
                    for (XmlRpc::XmlRpcValue::iterator i=symbols.begin(); i!=symbols.end(); ++i) {
                     ROS_ASSERT(i->second.getType()==XmlRpc::XmlRpcValue::TypeArray);
                     for(int j=0; j<i->second.size(); ++j) {
                         ROS_ASSERT(i->second[j].getType()==XmlRpc::XmlRpcValue::TypeDouble);
                        }
                    }
                }

With YAML being:

object0: [0.1280805148444952, -0.2574350304851667]
table: [-0.019239830108468144]
object1: [-0.12373553201812965, -0.2581443366277866, 0.12297468008504482, 0.0405834453536516, 0.9474896873206372, -0.026972527372781926]
arm: [0.9303491449393159]
eye: [0.12397546355498722 -0.37202872219628474]

Sorry for editing 1000 times :)