/* Public Domain / CC-0 * Author: tastytea */ #ifndef XDGJSON_HPP #define XDGJSON_HPP #if __cplusplus >= 201703L #include #else #include #endif #include #include #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