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++
Raw Normal View History

2018-08-10 03:28:31 +02:00
/* 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
2018-08-10 03:28:31 +02:00
#include <string>
#include <jsoncpp/json/json.h>
#if __cplusplus >= 201703L
namespace fs = std::filesystem;
#else
namespace fs = std::experimental::filesystem;
#endif
2018-08-10 03:28:31 +02:00
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
*/
2019-01-01 09:42:42 +01:00
bool read();
2018-08-10 03:28:31 +02:00
/*!
* @brief Write the file
*
* @return `true` on success
*/
2019-01-01 09:42:42 +01:00
bool write();
2018-08-10 03:28:31 +02:00
/*!
* @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;
2018-08-10 03:28:31 +02:00
private:
/*!
* Holds the contents of the JSON file
*/
Json::Value _json;
/*!
* Complete filepath
*/
fs::path _filepath;
2018-08-10 03:28:31 +02:00
};
/*!
* @example example.cpp
*/
#endif // XDGJSON_HPP