Teuchos - Trilinos Tools Package
Version of the Day
|
Functions to convert between ParameterList and YAML. More...
#include "Teuchos_ParameterList.hpp"
#include "Teuchos_ParameterEntry.hpp"
#include "Teuchos_RCP.hpp"
#include "Teuchos_PtrDecl.hpp"
#include "Teuchos_FileInputSource.hpp"
#include <iostream>
#include <string>
Go to the source code of this file.
Namespaces | |
Teuchos | |
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines. | |
Functions to convert between ParameterList and YAML.
YAML is a human-readable data serialization format. Teuchos provides a YAML parameter list interpreter. It produces Teuchos::ParameterList objects equivalent to those produced by the Teuchos XML helper functions.
Here is a simple example XML parameter list:
Here is an equivalent YAML parameter list:
The nested structure and key-value pairs of these two lists are identical. To a program querying them for settings, they are indistinguishable.
These are the general rules for creating a YAML parameter list:
%YAML 1.1
, second must be —
, and last must be ...
ANONYMOUS:
must be explicit 5
is an int, 5.0
is a double, and '5.0'
is a string :{}[],&*#?|<>=!%\
. '3'
is a string true
and false
are supported by the parameter list reader. exampleArray: [hello, world, goodbye]
[3, 4, 5]
is an int array, [3, 4, 5.0]
is a double array, and [3, '4', 5.0]
is a string array |
after the key:
and then indent the string one level deeper than the key |2
after the key:
and then indent your string's content by 2 spaces relative to the key. Note that the |-
and empty line after myfunc:
in this example remove the trailing newline from the myfunc
content and add a newline to the start of it, respectively. This is only done to mimic the fact that the XML value has a newline at the beginning and not the end due to the way it was placed for readability in the XML file. However, a more idiomatic way to include a multi-line string in YAML is:
This will create a string with a newline at the end and not the beginning, which is more natural, will print better to other file formats, looks more like the contents of its own file from the perspective of the parser handling it (e.g. the RTCompiler) and looks better in YAML itself.
Definition in file Teuchos_YamlParser_decl.hpp.