So I have a class, and I'm using boost::property_tree::ptree to serialize the data. My question relates to loading the information from the file using get() using the parameter that allows for a default value in the case that the value isn't found in the tree.
1 2 3 4 5 6
class Object {
public:
std::string Name,
OtherString;
unsignedint SomeInt;
}
I have a default constructor that initializes the data to some reasonable default values. Then in my load function, I wanted to reference these values again for the sake of not having to write them again.
1 2 3 4
// ...
const Object Defaults; // for getting the values from the default constructor
tree.get("Name", Defaults.Name);
// and so on...
While it seems to work (haven't compiled and tested yet), it does seem a little odd to me. Another way I could see was making a bunch of constants in the class like DEFAULT_NAME or something to store this "default" information, and use those constants in the default constructor and the load function. This would give the added bonus of being able to use the defaults anywhere in the code easily.
Anyone have any opinions or suggestions as to what they think would be best?