Пример #1
0
int main()
{
    Param * p = NULL;
    bool result = false;

    // show structure size
    std::cout << "size of Param: " << sizeof(Param) << std::endl;

    // param1
    result = Param::getDict().get("param1", p);
    assert(result);
    assert(p->getType() == Param::FLOAT);
    assert(fabs(p->getFloat() - 1.0f) < 1e-20);
    assert(p->getInt() == 1);

    // param2
    result = Param::getDict().get("param2", p);
    assert(result);
    assert(p->getType() == Param::INT);
    assert(fabs(p->getFloat() - 2.0f) < 1e-20);
    assert(p->getInt() == 2);

    // param3
    result = Param::getDict().get("param3", p);
    assert(result);
    assert(p->getType() == Param::FLOAT);
    assert(fabs(p->getFloat() - 1.3f) < 1e-20);
    assert(p->getInt() == 1);
};
Пример #2
0
bool ParamManager::load_from_file(std::string filename)
{
  try
  {
    YAML::Node root = YAML::LoadFile(filename);
    assert(root.IsSequence());

    for (int i = 0; i < root.size(); i++)
    {
      if (root[i].IsMap() && root[i]["name"] && root[i]["type"] && root[i]["value"])
      {
        if (is_param_id(root[i]["name"].as<std::string>()))
        {
          Param param = params_.find(root[i]["name"].as<std::string>())->second;
          if ((MAV_PARAM_TYPE) root[i]["type"].as<int>() == param.getType())
          {
            set_param_value(root[i]["name"].as<std::string>(), root[i]["value"].as<double>());
          }
        }
      }
    }

    return true;
  }
  catch (...)
  {
    return false;
  }
}