I'm considering creating an input/log file for my code for two main purposes.
1) Be able to log all key parameters that the code was run with so that I can reproduce the same results in the future if I needed to. 2) Be able to start/resume the code without the need to hard-code the parameters in the code.
I'm interested in a header-only approach so that I could simply carry the header files along with my code thus I have turned into boost.property_tree. From the documentation it seems to serve the purpose. My question is which file-format serves my need the best? I need something that:
1) is easily readable/editable by a human 2) can support nested sections 3) can support comments
By default I have turned to xml but I'm not sure that's the best option considering parsing capabilities of boost.property_tree. For instance I want to be able to parse something like this:
<Grid Type = "AMR">
<Domain> -1.0 1.0 -1.0 1.0 </Domain>
<Levels> 10 5 </Levels>
<Path> /path/to/data.bin </Path>
</Grid>
I want to be able to read in Type
property as well as Domain
, Levels
, and Path
sections correctly and separately (for instance Domain
has 4 separate floating points corresponding to the edges of a rectangle). My code looks like this:
using boost::property_tree::ptree;
ptree pt;
double x = pt.get<double>("Grid.Domain");
std::cout << x << std::endl;
but I keep getting conversion of data to type "d" failed
. How should I fix it? Also, is xml the best option I have or should I consider changing to another format?