Skip to content

Commit f8e0052

Browse files
authored
Devel3 (#11)
1 parent 367f26e commit f8e0052

File tree

6 files changed

+84
-49
lines changed

6 files changed

+84
-49
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ build/
4242
# debug information files
4343
*.dwo
4444

45-
lattice_files/expand.yaml
45+
lattice_files/expand.pals.yaml

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 3.16)
22
project(YAMLWrapper)
33

4+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
5+
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
6+
47
set(CMAKE_CXX_STANDARD 17)
58
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
69
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -85,7 +88,7 @@ file(COPY ${CMAKE_SOURCE_DIR}/lattice_files/
8588
# endif()
8689

8790
add_library(yaml_c_wrapper SHARED src/yaml_c_wrapper.cpp)
88-
target_link_libraries(yaml_c_wrapper yaml-cpp)
91+
target_link_libraries(yaml_c_wrapper PUBLIC yaml-cpp)
8992

9093
add_executable(yaml_reader examples/yaml_reader.cpp)
9194
target_link_libraries(yaml_reader yaml_c_wrapper)

examples/yaml_reader.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
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+
46
int 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 << "\nthe 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");

lattice_files/ex.pals.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
length: 1.03
1515
direction: -1
1616
- a_subline: # Item a_subline is repeated three times
17-
repeat: 3
17+
repeat: 3
18+
- include: "include.pals.yaml"

lattice_files/include.pals.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- line:
2+
first: 1
3+
second: 2
4+
thrid: 3

0 commit comments

Comments
 (0)