xdgcfg  0.4.1
xdgcfg.hpp
1 /* Public Domain / CC-0
2  * Author: tastytea <tastytea@tastytea.de>
3  */
4 
5 #ifndef XDGCFG_HPP
6 #define XDGCFG_HPP
7 
8 #if __cplusplus >= 201703L
9  #include <filesystem>
10 #else
11  #include <experimental/filesystem>
12 #endif
13 #include <string>
14 #include <iostream>
15 #include <cstdint>
16 #include <libconfig.h++>
17 
18 #if __cplusplus >= 201703L
19  namespace fs = std::filesystem;
20 #else
21  namespace fs = std::experimental::filesystem;
22 #endif
23 using std::string;
24 using std::uint_fast8_t;
25 using std::cerr;
26 using std::endl;
27 
28 class xdgcfg
29 {
30 public:
42  explicit xdgcfg(const string &filename, const string &subdir = "");
43 
49  uint_fast8_t read();
50 
56  bool write();
57 
66  libconfig::Config &get_cfg();
67 
71  const fs::path get_filepath() const;
72 
76  void set_verbose(bool verbose);
77 
81  bool get_verbose() const;
82 
83 private:
87  libconfig::Config _cfg;
88 
92  fs::path _filepath;
93 
97  bool _verbose;
98 };
99 
104 #endif // XDGCFG_HPP
Definition: xdgcfg.hpp:28
xdgcfg(const string &filename, const string &subdir="")
Checks if subdir is present, creates it if necessary.
Definition: xdgcfg.cpp:8
libconfig::Config & get_cfg()
Returns a reference to the config as libconfig::Config.
Definition: xdgcfg.cpp:75
void set_verbose(bool verbose)
Sets verbosity.
Definition: xdgcfg.cpp:85
const fs::path get_filepath() const
Returns the complete filepath.
Definition: xdgcfg.cpp:80
uint_fast8_t read()
Read the file.
Definition: xdgcfg.cpp:28
bool get_verbose() const
Returns verbosity.
Definition: xdgcfg.cpp:90
bool write()
Write the file.
Definition: xdgcfg.cpp:56