tastytea
2fb329a302
Some checks failed
continuous-integration/drone/push Build is failing
* Compile a library again. * Made CMake recipes modular. * Added xdgcfgConfig.cmake. * Added pkg-config file. * Updated readme.
105 lines
1.9 KiB
C++
105 lines
1.9 KiB
C++
/* Public Domain / CC-0
|
|
* Author: tastytea <tastytea@tastytea.de>
|
|
*/
|
|
|
|
#ifndef XDGCFG_HPP
|
|
#define XDGCFG_HPP
|
|
|
|
#if __cplusplus >= 201703L
|
|
#include <filesystem>
|
|
#else
|
|
#include <experimental/filesystem>
|
|
#endif
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <cstdint>
|
|
#include <libconfig.h++>
|
|
|
|
#if __cplusplus >= 201703L
|
|
namespace fs = std::filesystem;
|
|
#else
|
|
namespace fs = std::experimental::filesystem;
|
|
#endif
|
|
using std::string;
|
|
using std::uint_fast8_t;
|
|
using std::cerr;
|
|
using std::endl;
|
|
|
|
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
|