/* Public Domain / CC-0 * Author: tastytea */ #ifndef XDGCFG_HPP #define XDGCFG_HPP #if __cplusplus >= 201703L #include #else #include #endif #include #include #include #if __cplusplus >= 201703L namespace fs = std::filesystem; #else namespace fs = std::experimental::filesystem; #endif using std::string; using std::uint_fast8_t; class xdgcfg { public: /*! * @brief Checks if subdir is present, creates it if necessary * * Example: * @code * xdgcfg config("test.cfg", "subdirectory"); * @endcode * * @param filename The name of the file, including extension * @param subdir The subdir (optional) */ explicit xdgcfg(const string &filename, const string &subdir = ""); /*! * @brief Read the file * * @return 0 on success, 1 on I/O error, 2 on parse error. */ uint_fast8_t read(); /*! * @brief Write the file * * @return `true` on success */ bool write(); /*! * @brief Returns a reference to the config as libconfig::Config * * Example: * @code * libconfig::Config &cfg = config.get_cfg(); * @endcode */ libconfig::Config &get_cfg(); /*! * @brief Returns the complete filepath */ const fs::path get_filepath() const; /*! * @brief Sets verbosity */ void set_verbose(bool verbose); /*! * @brief Returns verbosity */ bool get_verbose() const; private: /*! * Holds the contents of the CFG file */ libconfig::Config _cfg; /*! * Complete filepath */ fs::path _filepath; /*! * Print out error messages if true */ bool _verbose; }; /*! * @example example.cpp */ #endif // XDGCFG_HPP