JayBeams  0.1
Another project to have fun coding.
merge_yaml.hpp
Go to the documentation of this file.
1 #ifndef jb_merge_yaml_hpp
2 #define jb_merge_yaml_hpp
3 
4 #include <yaml-cpp/yaml.h>
5 #include <map>
6 
7 namespace jb {
8 
9 /**
10  * Store the overrides for each class.
11  *
12  * Jaybeams configuration objects can be overriden "by-class",
13  * meaning, all configs of the same class receive the same overrides.
14  * This type is used to (temporarily) store the by-class overrides in
15  * a given context.
16  */
17 typedef std::map<std::string, YAML::Node> class_overrides;
18 
19 namespace yaml {
20 
21 /**
22  * Merge two YAML nodes.
23  *
24  * Unlike a simple assignment, if @a source does not have a value
25  * for a given key, we keep the value from @a target.
26  */
27 void merge_node(YAML::Node target, YAML::Node const& source);
28 
29 /**
30  * Merge all the values from @a source into @a target
31  *
32  * Unlike a simple assignment, if @a source does not have a value
33  * for a given key, we keep the value from @a target.
34  */
35 void merge_map(YAML::Node target, YAML::Node const& source);
36 
37 /**
38  * Memberwise merge two sequences, from @a source into @a target.
39  *
40  * If @a source has more elements than @a target the additional values
41  * are appended. If @a source has less elements than @a target, the
42  * extra values in @a target are unmodified.
43  */
44 void merge_sequences(YAML::Node target, YAML::Node const& source);
45 
46 /**
47  * Merge the class-overrides from @a source into @a by_class.
48  *
49  * Given a set of by-class overrides apply any additional by-class
50  * overrides from @a source source into @a by_class.
51  */
52 void merge(class_overrides& by_class, YAML::Node source);
53 
54 /**
55  * Recursively clone all the overrides in @a by_class.
56  */
57 class_overrides clone(class_overrides const& by_class);
58 
59 } // namespace yaml
60 } // namespace jb
61 
62 #endif // jb_merge_yaml_hpp
class_overrides clone(class_overrides const &by_class)
Recursively clone all the overrides in by_class.
Definition: merge_yaml.cpp:67
void merge(class_overrides &by_class, YAML::Node source)
Merge the class-overrides from source into by_class.
Definition: merge_yaml.cpp:40
std::map< std::string, YAML::Node > class_overrides
Store the overrides for each class.
Definition: merge_yaml.hpp:17
void merge_sequences(YAML::Node target, YAML::Node const &source)
Memberwise merge two sequences, from source into target.
Definition: merge_yaml.cpp:30
void merge_map(YAML::Node target, YAML::Node const &source)
Merge all the values from source into target.
Definition: merge_yaml.cpp:24
void merge_node(YAML::Node target, YAML::Node const &source)
Merge two YAML nodes.
Definition: merge_yaml.cpp:5
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7