This repository has been archived on 2020-05-16. You can view files and clone it, but cannot push or open issues or pull requests.
xdgjson/src/xdgjson.hpp

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
*/
bool read();
/*!
* @brief Write the file
*
* @return `true` on success
*/
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