|
1 | | -#include "../src/yaml_c_wrapper.h" |
2 | 1 | #include <iostream> |
| 2 | +#include "../src/yaml_c_wrapper.h" |
| 3 | + |
| 4 | +// If file name is provided as a command line argument, this will print out the |
| 5 | +// expanded contents of the file to the terminal, as well as to expand.pals.yaml. |
| 6 | +// Otherwise, it will use the example file ex.pals.yaml |
3 | 7 |
|
4 | | -// See ex.pals.yaml for the example lattice file and expand.pals.yaml for the output of this file. |
| 8 | +int main(int argc, char* argv[]) { |
| 9 | + if (argc != 1) { |
| 10 | + char* filename = argv[1]; |
| 11 | + std::string path = "../lattice_files/"; |
| 12 | + path += filename; |
| 13 | + YAMLNodeHandle handle = parse_file(path.c_str()); |
5 | 14 |
|
6 | | -int main() { |
| 15 | + lattice_expand(handle); |
| 16 | + std::cout << "Printing out contents of file: " << filename << std::endl; |
| 17 | + std::cout << yaml_to_string(handle) << std::endl; |
| 18 | + write_file(handle, "../lattice_files/expand.pals.yaml"); |
| 19 | + return 0; |
| 20 | + } |
7 | 21 | // reading a lattice from a yaml file |
8 | | - // allow files to be read in through command line, print back out |
9 | | - YAMLNodeHandle handle = yaml_parse_file("../lattice_files/ex.pals.yaml"); |
10 | | - // print out file name that was read in |
| 22 | + YAMLNodeHandle handle = parse_file("../lattice_files/ex.pals.yaml"); |
| 23 | + std::cout << "Printing out contents of file: " << "ex.pals.yaml" << std::endl; |
11 | 24 | // printing to terminal |
12 | 25 | std::cout << yaml_to_string(handle) << std::endl << std::endl; |
13 | 26 |
|
14 | 27 | // type checking |
15 | 28 | // prints "handle is of type sequence: 1", 1 meaning true |
16 | | - std::cout << "handle is of type sequence: " << (yaml_is_sequence(handle)) << "\n"; |
| 29 | + std::cout << "handle is of type sequence: " << (is_sequence(handle)) |
| 30 | + << "\n"; |
17 | 31 |
|
18 | 32 | // accessing sequence |
19 | | - YAMLNodeHandle node = yaml_get_index(handle, 0); |
| 33 | + YAMLNodeHandle node = get_index(handle, 0); |
20 | 34 | /* prints |
21 | | - the first element is: |
| 35 | + the first element is: |
22 | 36 | thingB: |
23 | 37 | kind: Sextupole |
24 | 38 | */ |
25 | 39 | std::cout << "the first element is: \n" << yaml_to_string(node) << "\n"; |
26 | 40 |
|
27 | 41 | // accessing map |
28 | 42 | // prints "the value at key 'thingB' is: kind: Sextupole" |
29 | | - std::cout << "\nthe value at key 'thingB' is: " << yaml_to_string(yaml_get_key(node, "thingB")) << "\n"; |
| 43 | + std::cout << "\nthe value at key 'thingB' is: " |
| 44 | + << yaml_to_string(get_key(node, "thingB")) << "\n"; |
30 | 45 |
|
31 | | - // creating a new node that's a map |
32 | | - YAMLNodeHandle map = yaml_create_map(); |
33 | | - yaml_set_int(map, "first", 1); |
| 46 | + // creating a new node that's a map |
| 47 | + YAMLNodeHandle map = create_map(); |
| 48 | + set_value_int(map, "apples", 5); |
34 | 49 |
|
35 | 50 | // creating a new node that's a sequence |
36 | | - YAMLNodeHandle sequence = yaml_create_sequence(); |
37 | | - yaml_push_string(sequence, "magnet1"); |
38 | | - yaml_push_string(sequence, ""); |
39 | | - YAMLNodeHandle scalar = yaml_create_scalar(); |
40 | | - yaml_set_scalar_string(scalar, "magnet2"); |
41 | | - yaml_set_at_index(sequence, 1, scalar); |
| 51 | + YAMLNodeHandle sequence = create_sequence(); |
| 52 | + push_string(sequence, "magnet1"); |
| 53 | + push_string(sequence, ""); |
| 54 | + YAMLNodeHandle scalar = create_scalar(); |
| 55 | + set_scalar_string(scalar, "magnet2"); |
| 56 | + set_at_index(sequence, 1, scalar); |
42 | 57 | // give sequence a name by putting it in a map: |
43 | | - YAMLNodeHandle magnets = yaml_create_map(); |
44 | | - yaml_set_node(magnets, "magnets", sequence); |
| 58 | + YAMLNodeHandle magnets = create_map(); |
| 59 | + set_value_node(magnets, "magnets", sequence); |
45 | 60 |
|
46 | 61 | // adding new nodes to lattice |
47 | | - yaml_push_node(handle, map); |
48 | | - yaml_push_node(handle, magnets); |
| 62 | + push_node(handle, map); |
| 63 | + push_node(handle, magnets); |
49 | 64 |
|
50 | | - yaml_expand(handle); |
| 65 | + // performing lattice expansion |
| 66 | + lattice_expand(handle); |
51 | 67 |
|
52 | 68 | // writing modified lattice file to expand.pals.yaml |
53 | | - yaml_write_file(handle, "../lattice_files/expand.pals.yaml"); |
| 69 | + write_file(handle, "../lattice_files/expand.pals.yaml"); |
| 70 | + return 0; |
54 | 71 | } |
0 commit comments