0

tl;dr Is there a way to overwrite the way boost.property_tree serializes bool (other built in) values?

I'm about to replace a self-written key-value storage by boost.property_tree. Therefore in the first run I changed the implementation to use boost.property_tree but now I'm hitting the wall because the old implementation used integers 0/1 to represent bool values and property_tree uses true/false.

So when serializing ptrees, I get true/false strings in my files. That make the generated files not backward-compatible with older releases of our software which is a path I'm currently not willing to walk.

I found an old post boost property tree put/get DBL_MAX which changes the methods to write/read double values but when I try the same for bool, I get a compiler error, that the struct is already defined (which is correct as it is in ptree_translator.hpp).

Community
  • 1
  • 1
An Ky
  • 113
  • 11

1 Answers1

0

This means you can't use this mechanism, because the library already used the customization point.

  • You may not need this

    It looks like the reading side already supports the old format. So, you should be fine reading the old format.

  • You can use a strong typedef (or a custom enum like Bool { my_false_rep, my_true_rep }) for which you can use the customization point without conflict.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Maybe I was imprecise. I understand that property_tree can handle 1/0 true/false when reading. The problem is the old (pre-property_tree) reader which is not able to parse true/false but that's what I *always* get when ptree serializes the bool values. So once the file is saved with the new version the user is unable to open it with an old version of our software which I want to prohibit. The hint with the strongly typed bool is nice, I just wonder wether there is an other way the library provides. – An Ky Mar 31 '16 at 09:33
  • There is not another way. Or rather, all the "other ways" imply using another datatype than `bool` /or/ spelling out the special conversion – sehe Mar 31 '16 at 10:07