Exemple #1
0
std::string
YAMLFormatter::printParams(const std::string & prefix,
                           const std::string & /*fully_qualified_name*/,
                           InputParameters & params,
                           short depth,
                           const std::string & search_string,
                           bool & found)
{
  std::ostringstream oss;
  std::string indent(depth * 2, ' ');

  for (auto & iter : params)
  {
    std::string name = iter.first;
    // First make sure we want to see this parameter, also block active and type
    if (params.isPrivate(iter.first) || name == "active" ||
        (search_string != "" && search_string != iter.first) || haveSeenIt(prefix, iter.first))
      continue;

    found = true;

    // Mark it as "seen"
    seenIt(prefix, iter.first);

    // Block params may be required and will have a doc string
    std::string required = params.isParamRequired(iter.first) ? "Yes" : "No";

    oss << indent << "  - name: " << name << "\n";
    oss << indent << "    required: " << required << "\n";
    oss << indent << "    default: !!str ";

    // Only output default if it has one
    if (params.isParamValid(iter.first))
    {
      // prints the value, which is the default value when dumping the tree
      // because it hasn't been changed

      // Output stream, performing special operations for writing objects such as Points and
      // RealVectorValues
      std::ostringstream toss;
      buildOutputString(toss, iter);

      // remove additional '\n' possibly generated in output (breaks YAML parsing)
      std::string tmp_str = toss.str();
      for (auto & ch : tmp_str)
        if (ch == '\n')
          ch = ' ';
      if (tmp_str == ",")
        oss << "\"" << tmp_str << "\"";
      else
        oss << tmp_str;
    }
    else if (params.hasDefaultCoupledValue(iter.first))
      oss << params.defaultCoupledValue(iter.first);

    std::string doc = params.getDocString(iter.first);
    MooseUtils::escape(doc);
    // Print the type
    oss << "\n"
        << indent << "    cpp_type: " << params.type(iter.first) << "\n"
        << indent << "    group_name: ";
    std::string group_name = params.getGroupName(iter.first);
    if (!group_name.empty())
      oss << "'" << group_name << "'";

    {
      InputParameters::Parameter<MooseEnum> * enum_type =
          dynamic_cast<InputParameters::Parameter<MooseEnum> *>(iter.second);
      if (enum_type)
        oss << "\n" << indent << "    options: " << enum_type->get().getRawNames();
    }
    {
      InputParameters::Parameter<MultiMooseEnum> * enum_type =
          dynamic_cast<InputParameters::Parameter<MultiMooseEnum> *>(iter.second);
      if (enum_type)
        oss << "\n" << indent << "    options: " << enum_type->get().getRawNames();
    }
    {
      InputParameters::Parameter<std::vector<MooseEnum>> * enum_type =
          dynamic_cast<InputParameters::Parameter<std::vector<MooseEnum>> *>(iter.second);
      if (enum_type)
        oss << "\n" << indent << "    options: " << (enum_type->get())[0].getRawNames();
    }

    oss << "\n" << indent << "    description: |\n      " << indent << doc << "\n";
  }

  return oss.str();
}