An Ky
An Ky

Reputation: 133

boost property tree value (de-)serialization

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).

Upvotes: 0

Views: 291

Answers (1)

sehe
sehe

Reputation: 393249

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.

Upvotes: 0

Related Questions