structures.cpp
Go to the documentation of this file.
00001 #include <fstream>
00002 #include <yaml-cpp/yaml.h>
00003 
00004 #include <segbot_common/structures.h>
00005 
00006 namespace bwi_common {
00007   
00008   void readLocationFile(const std::string& filename, 
00009       std::vector<std::string>& locations, std::vector<int32_t>& location_map) {
00010     std::ifstream fin(filename.c_str());
00011     YAML::Parser parser(fin);
00012 
00013     YAML::Node doc;
00014     parser.GetNextDocument(doc);
00015 
00016     locations.clear();
00017     const YAML::Node &loc_node = doc["locations"];
00018     for (size_t i = 0; i < loc_node.size(); i++) {
00019       std::string location;
00020       loc_node[i] >> location;
00021       locations.push_back(location);
00022     }
00023     const YAML::Node &data_node = doc["data"];
00024     location_map.resize(data_node.size());
00025     for (size_t i = 0; i < data_node.size(); i++) {
00026       data_node[i] >> location_map[i];
00027 
00028     }
00029   }
00030 
00031   void readDoorFile(const std::string& filename, std::vector<Door>& doors) {
00032     std::ifstream fin(filename.c_str());
00033     YAML::Parser parser(fin);
00034 
00035     YAML::Node doc;
00036     parser.GetNextDocument(doc);
00037 
00038     doors.clear();
00039     for (size_t i = 0; i < doc.size(); i++) {
00040       Door door;
00041       const YAML::Node &approach_node = doc[i]["approach"];
00042       for (size_t j = 0; j < 2; ++j) {
00043         approach_node[j]["from"] >> door.approach_names[j];
00044         approach_node[j]["point"][0] >> door.approach_points[j].x; 
00045         approach_node[j]["point"][1] >> door.approach_points[j].y; 
00046         approach_node[j]["point"][2] >> door.approach_yaw[j]; 
00047       }
00048       doc[i]["name"] >> door.name;
00049       try {
00050         doc[i]["width"] >> door.width;
00051       } catch(YAML::TypedKeyNotFound<std::string>& e) {
00052         door.width = 0.5;
00053       }
00054       doors.push_back(door);
00055     }
00056   }
00057 
00058 } /* bwi_common */


segbot_common
Author(s): Piyush Khandelwal
autogenerated on Sat Dec 7 2013 11:54:24