hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.12k stars 365 forks source link

Automatic data type detection on "add" #37

Open ponzipoh opened 8 years ago

ponzipoh commented 8 years ago

When I let a user set a new property to add to a setting, I don't know the type in advance. For example, the user may want to add the config setting balance=42, name="My Name", or loadPlugin=True. The problem is, when I go to store this property in a config file I need to supply a type according to the function definition Setting & add(const std::string &name, Setting::Type type).

Would it please be possible to add a function that selects the type automatically based on the new value that I want to store?

jltallon commented 8 years ago

Doesn't sound like it'd make much sense to do at the libconfig level. You should do the detection yourself from the program before adding the setting. It's not difficult ...

Anyway, it's Mark's call.

hyperrealm commented 8 years ago

We could overload add() I guess, to take each type of value, e.g.:

Setting &add(const std::string &name, int value) Setting &add(const std::string &name, double value) Setting &add(const std::string &name, const char *value) ...