Esempio n. 1
0
T safe_varmap_get(const variant_map_type& kv, std::string key) {
  if (kv.count(key) == 0) {
    log_and_throw("Required Key " + key + " not found");
  } else {
    return variant_get_value<T>(kv.at(key));
  }
  __builtin_unreachable();
}
Esempio n. 2
0
variant_type toolkit_class_base::get_value(std::string key, variant_map_type& arg) {
  perform_registration();
  if (key == "list_functions") {
    return to_variant(list_functions());
  } else if (key == "list_get_properties") {
    return to_variant(list_get_properties());
  } else if (key == "list_set_properties") {
    return to_variant(list_set_properties());
  } else if (key == "call_function") {
    // dispatches to a user defined function
    if (!arg.count("__function_name__")) {
      throw("Invalid function call format");
    }
    std::string function_name = variant_get_value<std::string>(arg["__function_name__"]);
    return to_variant(call_function(function_name, arg));
  } else if (key == "set_property") {
    // dispatches to a user defined set property
    if (!arg.count("__property_name__")) {
      throw("Invalid function call format");
    }
    std::string property_name = variant_get_value<std::string>(arg["__property_name__"]);
    return to_variant(set_property(property_name, arg));
  } else if (key == "get_property") {
    // dispatches to a user defined get property
    if (!arg.count("__property_name__")) {
      throw("Invalid function call format");
    }
    std::string property_name = variant_get_value<std::string>(arg["__property_name__"]);
    return to_variant(get_property(property_name, arg));
  } else if (key == "get_docstring") {
    // dispatches to a user defined get property
    if (!arg.count("__symbol__")) {
      throw("Invalid function call format");
    }
    std::string symbol = variant_get_value<std::string>(arg["__symbol__"]);
    return to_variant(get_docstring(symbol));
  } else if (key == "__name__") {
    return name();
  } else if (key == "__uid__") {
    return uid();
  } else {
    return variant_type();
  }
}