C++ Representing Objects in a YAML file

Viewed 22

I used to work with the Java framework spring boot which has this neat functionality where you can have an yaml file like this:

config:
  example_int: 17

And a java class like this:

public class Config {
  int example_int;
  config(example_int) {
    this.example_int = example_int;
  }
}

The framework would then (if I remember correctly) inject into the runtime an instance of class Config with example_int data member initialized to 17.

I'm looking to implement a similar functionality in C++ i.e. parse a yaml file and then construct a c++ object based on the files contents.

While (I think) Spring uses runtime injection I think I could do this via meta programming to reduce complexity. TLDR:

  1. Parse yaml with C++
  2. Based on yaml configs inject an object into the runtime, or generate code via metaprogramming, which has the characteristics defined in the yaml file.
0 Answers
Related