hjson / hjson-cpp

Hjson for C++
https://hjson.github.io/
MIT License
70 stars 20 forks source link

Only dump assigned values to file #27

Closed maldag closed 4 years ago

maldag commented 4 years ago

It seems like this library keeps track of assigned values during their lifecycle via the variable wasAssigned.

If it's possible to write only assigned variables to a file it would be able to distinguish between base and overwritten values. Thus, it could be possible to use Merge() to assemble it back together.

trobro commented 4 years ago

wasAssigned is only used in the class MapProxy, which is only used when the [] operator is used on a Value of type MAP.

Here wasAssigned will be false, therefore no element is created in val as a result of this statement:

int myInt = val["a"];

Here wasAssigned will be true, and therefore an element (with key "a") is created in val if it did not already exist:

val["a"] = myInt;

I think it would get too complicated to keep track of changes in an entire Value tree.