Skip to content

Parameter tree inline parsing

Summary

The normal use of a ParameterTree is with a file. However, sometimes is nice to use the parameter tree with strings constructed at run-time. The code is an unnecessary boilerplate that may be saved with inline parsing of the parameter tree.

#include <dune/common/parametertree.hh>
#include <dune/common/parametertreeparser.hh>

std::stringstream ss;
ss << "[section]                \n"
   << "subsection.key = value   \n";
Dune::ParameterTree config;
ParameterTreeParser::readINITree(ss, config);

Proposal

Allow to construct ParameterTrees with strings that follow the INI format:

#include <dune/common/parametertree.hh>

auto config = Dune::ParameterTree{
  "[section]                \n"
  "subsection.key = value   \n"
};

Notice that the header dune/common/parametertreeparser.hh is not required in the latter case because the operation is compiled in the libdunecommon library.

This is nothing else than a syntactic sugar. But it is indeed useful to make minimal examples that require trees much more readable.

Merge request reports

Loading