85 lines
1.6 KiB
C++
85 lines
1.6 KiB
C++
/* Public Domain / CC-0
|
|
* Author: tastytea <tastytea@tastytea.de>
|
|
*/
|
|
|
|
#ifndef XDGJSON_HPP
|
|
#define XDGJSON_HPP
|
|
|
|
#if __cplusplus >= 201703L
|
|
#include <filesystem>
|
|
#else
|
|
#include <experimental/filesystem>
|
|
#endif
|
|
#include <string>
|
|
#include <jsoncpp/json/json.h>
|
|
|
|
#if __cplusplus >= 201703L
|
|
namespace fs = std::filesystem;
|
|
#else
|
|
namespace fs = std::experimental::filesystem;
|
|
#endif
|
|
using std::string;
|
|
|
|
class xdgjson
|
|
{
|
|
public:
|
|
/*!
|
|
* @brief Checks if subdir is present, creates it if necessary
|
|
*
|
|
* Example:
|
|
* @code
|
|
* xdgjson config("test.json", "subdirectory");
|
|
* @endcode
|
|
*
|
|
* @param filename The name of the file, including extension
|
|
* @param subdir The subdir (optional)
|
|
*/
|
|
explicit xdgjson(const string &filename, const string &subdir = "");
|
|
|
|
/*!
|
|
* @brief Read the file
|
|
*
|
|
* @return `true` on success
|
|
*/
|
|
const bool read();
|
|
|
|
/*!
|
|
* @brief Write the file
|
|
*
|
|
* @return `true` on success
|
|
*/
|
|
const bool write();
|
|
|
|
/*!
|
|
* @brief Returns a reference to the config as Json::Value
|
|
*
|
|
* Example:
|
|
* @code
|
|
* Json::Value &json = config.get_json();
|
|
* @endcode
|
|
*/
|
|
Json::Value &get_json();
|
|
|
|
/*!
|
|
* @brief Returns the complete filepath
|
|
*/
|
|
const fs::path get_filepath() const;
|
|
|
|
private:
|
|
/*!
|
|
* Holds the contents of the JSON file
|
|
*/
|
|
Json::Value _json;
|
|
|
|
/*!
|
|
* Complete filepath
|
|
*/
|
|
fs::path _filepath;
|
|
};
|
|
|
|
/*!
|
|
* @example example.cpp
|
|
*/
|
|
|
|
#endif // XDGJSON_HPP
|