kicad/thirdparty/json_schema_validator/json-patch.hpp

40 lines
925 B
C++
Raw Normal View History

2021-03-12 05:59:23 +00:00
#pragma once
#include <nlohmann/json.hpp>
#include <string>
namespace nlohmann
{
class JsonPatchFormatException : public std::exception
{
public:
2024-04-13 00:00:12 +00:00
explicit JsonPatchFormatException( std::string msg ) : ex_{ std::move( msg ) } {}
2021-03-12 05:59:23 +00:00
2024-04-13 00:00:12 +00:00
inline const char* what() const noexcept override final { return ex_.c_str(); }
2021-03-12 05:59:23 +00:00
private:
2024-04-13 00:00:12 +00:00
std::string ex_;
2021-03-12 05:59:23 +00:00
};
class json_patch
{
public:
2024-04-13 00:00:12 +00:00
json_patch() = default;
json_patch( json&& patch );
json_patch( const json& patch );
2021-03-12 05:59:23 +00:00
2024-04-13 00:00:12 +00:00
json_patch& add( const json::json_pointer&, json value );
json_patch& replace( const json::json_pointer&, json value );
json_patch& remove( const json::json_pointer& );
2021-03-12 05:59:23 +00:00
2024-04-13 00:00:12 +00:00
json& get_json() { return j_; }
const json& get_json() const { return j_; }
operator json() const { return j_; }
2021-03-12 05:59:23 +00:00
private:
2024-04-13 00:00:12 +00:00
json j_ = nlohmann::json::array();
2021-03-12 05:59:23 +00:00
2024-04-13 00:00:12 +00:00
static void validateJsonPatch( json const& patch );
2021-03-12 05:59:23 +00:00
};
2024-04-13 00:00:12 +00:00
} // namespace nlohmann