hyperrealm / libconfig

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

can i get config file path from a libconfig::Config object? #192

Closed nickhuangxinyu closed 3 years ago

nickhuangxinyu commented 3 years ago

i know the normal usage is:

libconfig::Config cfg;
cfg.readFile(path);

my question is:

Can i get the path from cfg object?

like: cfg.getpath() to get filepath?

hyperrealm commented 3 years ago

libconfig::Setting has methods getSourceFile() and getSourceLine() that give you this information. So call getSourceFile() on the root setting to get the toplevel filename. There can be multiple files if include statements are used, so each setting potentially has a unique filename/line.

hyperrealm commented 3 years ago

Closing as working as intended.