hyperrealm / libconfig

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

Feature request: Introspection API #168

Closed yrutschle closed 4 years ago

yrutschle commented 4 years ago

Hi, I developed conf2struct, which builds on libconfig and argtable to build a consistent interface that's available from command line or configuration file.

I'd like to add configuration validation, so that some warning or error can be produced if unknown settings are present in the configuration file. It shouldn't be too hard, except for one missing piece in libconfig: I can't see any introspection API, e.g. a "get_first()" + "get_next()" function that returns all settings in a set in turn. The current API only allows you to retrieve settings for which you know the name.

I can get into coding it myself (though I won't dare mention a deadline), but would prefer to check if you're interested in the feature, and if yes, work out the API so it's consistent with the rest of libconfig and you're happy with it. If you're not interested, I'll try and think a way to do it as cleanly as possible from outside libconfig -_-

Y.

hyperrealm commented 4 years ago

Hi, you can enumerate the child settings of any setting by using config_setting_get_length() and config_setting_get_elem(). This works for arrays and lists as well as groups.

yrutschle commented 4 years ago

but of course! Thanks. Hopefully, I'll close #17 with that work, as it's essentially the same thing :)