示例#1
0
文件: Save.cpp 项目: annaborn/mars
    void Save::writeConfigMap(const configmaps::ConfigMap &cfg, QTextStream * out,
                              std::string tag, bool handleSensor, int depth) {

      configmaps::ConfigMap::const_iterator it;
      configmaps::ConfigVector::const_iterator it2;
      bool close = false;
      char text[255];

      if(handleSensor && depth == 0) {
        it = cfg.find("name");
        std::string name = it->second.toString();
        it = cfg.find("type");
        std::string type = it->second.toString();
        // FIXME: potential Buffer Overflow!!!!
        sprintf(text, "    <sensor name=\"%s\" type=\"%s\">", name.c_str(),
                type.c_str());

        //LOG_DEBUG("%s", text);

        *out <<text<<"\n";

        close = true;
        depth+=3;
      }
      else if(depth==0) {
        //LOG_DEBUG("  <%s>", tag.c_str());
        *out << "    <" << QString(tag.c_str()) << ">\n";
        depth+=3;
        close = true;
      }

      for(int i=0; i<depth*2; i++) text[i] = ' ';

      for(it=cfg.begin(); it!=cfg.end(); ++it) {
        if(handleSensor && (depth < 3 && (it->first == "name" || it->first == "type"))) continue;
        for(it2=it->second.begin(); it2!=it->second.end(); ++it2) {
          if(it2->size() == 0) {
            sprintf(text+depth*2, "<%s>%s</%s>", it->first.c_str(),
                    it2->toString().c_str(), it->first.c_str());
            *out << text << "\n";
            //LOG_DEBUG("%s", text);
          }
          else {
            sprintf(text+depth*2, "<%s>", it->first.c_str());
            *out << text << "\n";
            //LOG_DEBUG("%s", text);
            writeConfigMap((configmaps::ConfigMap&)(*it2), out, tag, handleSensor, depth+1);
            sprintf(text+depth*2, "</%s>", it->first.c_str());
            *out << text << "\n";
            //LOG_DEBUG("%s", text);
          }
        }
      }

      if(close) {
        *out << "    </"<< QString(tag.c_str()) <<">\n";
        //LOG_DEBUG("  </%s>", tag.c_str());
      }
    }
示例#2
0
文件: Smurf.cpp 项目: Rauldg/smurf
std::string checkGet(configmaps::ConfigMap &map, const std::string &key)
{
    auto it = map.find(key);
    if(it == map.end())
    {
        throw std::runtime_error("Smurf:: Error, could not find key " + key + " in config map");
    }
    
    return it->second;
}