8 #if __cplusplus >= 201703L 11 #include <experimental/filesystem> 16 #include <libconfig.h++> 19 #if __cplusplus >= 201703L 20 namespace fs = std::filesystem;
22 namespace fs = std::experimental::filesystem;
25 using std::uint_fast8_t;
43 explicit xdgcfg(
const string &filename,
const string &subdir =
"")
49 _filepath = xdgConfigHome(&xdg);
56 if (!fs::exists(_filepath))
58 fs::create_directories(_filepath);
60 _filepath /= filename;
72 _cfg.readFile(_filepath.c_str());
74 catch (
const libconfig::FileIOException &e)
78 cerr <<
"I/O error while reading " << _filepath
79 <<
" - " << e.what() << endl;
83 catch (
const libconfig::ParseException &e)
87 cerr <<
"Parse error at " << e.getFile() <<
":" << e.getLine()
88 <<
" - " << e.getError() << endl;
105 _cfg.writeFile(_filepath.c_str());
107 catch (
const libconfig::FileIOException &e)
111 cerr <<
"I/O error while writing " << _filepath
112 <<
" - " << e.what() << endl;
161 libconfig::Config _cfg;
Definition: xdgcfg.hpp:29
libconfig::Config & get_cfg()
Returns a reference to the config as libconfig::Config.
Definition: xdgcfg.hpp:128
xdgcfg(const string &filename, const string &subdir="")
Checks if subdir is present, creates it if necessary.
Definition: xdgcfg.hpp:43
void set_verbose(bool verbose)
Sets verbosity.
Definition: xdgcfg.hpp:144
const fs::path get_filepath() const
Returns the complete filepath.
Definition: xdgcfg.hpp:136
uint_fast8_t read()
Read the file.
Definition: xdgcfg.hpp:68
bool get_verbose() const
Returns verbosity.
Definition: xdgcfg.hpp:152
bool write()
Write the file.
Definition: xdgcfg.hpp:101