11#include " ../src/yaml_c_wrapper.h"
22#include < iostream>
33
4+ // See ex.pals.yaml for the example lattice file and expand.pals.yaml for the output of this file.
5+
46int main () {
57 // reading a lattice from a yaml file
68 YAMLNodeHandle handle = yaml_parse_file (" ../lattice_files/ex.pals.yaml" );
79 // printing to terminal
810 std::cout << yaml_to_string (handle) << std::endl << std::endl;
911
1012 // type checking
11- std::cout << (yaml_is_sequence (handle)) << " \n " ;
13+ // prints "handle is of type sequence: 1", 1 meaning true
14+ std::cout << " handle is of type sequence: " << (yaml_is_sequence (handle)) << " \n " ;
1215
1316 // accessing sequence
1417 YAMLNodeHandle node = yaml_get_index (handle, 0 );
18+ /* prints
19+ the first element is:
20+ thingB:
21+ kind: Sextupole
22+ */
1523 std::cout << " the first element is: \n " << yaml_to_string (node) << " \n " ;
1624
1725 // accessing map
26+ // prints "the value at key 'thingB' is: kind: Sextupole"
1827 std::cout << " \n the value at key 'thingB' is: " << yaml_to_string (yaml_get_key (node, " thingB" )) << " \n " ;
1928
2029 // creating a new node that's a map
@@ -28,10 +37,15 @@ int main() {
2837 YAMLNodeHandle scalar = yaml_create_scalar ();
2938 yaml_set_scalar_string (scalar, " magnet2" );
3039 yaml_set_at_index (sequence, 1 , scalar);
40+ // give sequence a name by putting it in a map:
41+ YAMLNodeHandle magnets = yaml_create_map ();
42+ yaml_set_node (magnets, " magnets" , sequence);
3143
3244 // adding new nodes to lattice
3345 yaml_push_node (handle, map);
34- yaml_push_node (handle, sequence);
46+ yaml_push_node (handle, magnets);
47+
48+ yaml_expand (handle);
3549
3650 // writing modified lattice file to expand.pals.yaml
3751 yaml_write_file (handle, " ../lattice_files/expand.pals.yaml" );
0 commit comments