Reformat header file to be more readable

Signed-off-by: Cristian Le <cristian.le@mpsd.mpg.de>
This commit is contained in:
Cristian Le 2023-05-10 11:55:01 +02:00
parent e5508ac4a3
commit 4bff849b25
Failed to extract signature
2 changed files with 182 additions and 132 deletions

View File

@ -12,3 +12,7 @@ SpaceAfterCStyleCast: true
TabWidth: 4 TabWidth: 4
AccessModifierOffset: -4 AccessModifierOffset: -4
UseTab: ForIndentation UseTab: ForIndentation
NamespaceIndentation: All
BraceWrapping:
AfterNamespace: false
CompactNamespaces: false

View File

@ -34,16 +34,16 @@
// make yourself a home - welcome to nlohmann's namespace // make yourself a home - welcome to nlohmann's namespace
namespace nlohmann namespace nlohmann
{ {
/**
// A class representing a JSON-URI for schemas derived from * A class representing a JSON-URI for schemas derived from
// section 8 of JSON Schema: A Media Type for Describing JSON Documents * section 8 of JSON Schema: A Media Type for Describing JSON Documents
// draft-wright-json-schema-00 * draft-wright-json-schema-00
// *
// New URIs can be derived from it using the derive()-method. * New URIs can be derived from it using the derive()-method.
// This is useful for resolving refs or subschema-IDs in json-schemas. * This is useful for resolving refs or subschema-IDs in json-schemas.
// *
// This is done implement the requirements described in section 8.2. * This is done implement the requirements described in section 8.2.
// */
class JSON_SCHEMA_VALIDATOR_API json_uri class JSON_SCHEMA_VALIDATOR_API json_uri
{ {
std::string urn_; std::string urn_;
@ -52,16 +52,27 @@ class JSON_SCHEMA_VALIDATOR_API json_uri
std::string authority_; std::string authority_;
std::string path_; std::string path_;
json::json_pointer pointer_; // fragment part if JSON-Pointer /**
std::string identifier_; // fragment part if Locatation Independent ID * fragment part if JSON-Pointer
*/
json::json_pointer pointer_;
/**
* fragment part if Locatation Independent ID
*/
std::string identifier_;
protected: protected:
// decodes a JSON uri and replaces all or part of the currently stored values /**
* decodes a JSON uri and replaces all or part of the currently stored values
*
* @param uri
*/
void update(const std::string &uri); void update(const std::string &uri);
std::tuple<std::string, std::string, std::string, std::string, std::string> as_tuple() const std::tuple<std::string, std::string, std::string, std::string, std::string> as_tuple() const
{ {
return std::make_tuple(urn_, scheme_, authority_, path_, identifier_ != "" ? identifier_ : pointer_.to_string()); return std::make_tuple(urn_, scheme_, authority_, path_,
identifier_ != "" ? identifier_ : pointer_.to_string());
} }
public: public:
@ -71,10 +82,13 @@ public:
} }
const std::string &scheme() const { return scheme_; } const std::string &scheme() const { return scheme_; }
const std::string &authority() const { return authority_; } const std::string &authority() const { return authority_; }
const std::string &path() const { return path_; } const std::string &path() const { return path_; }
const json::json_pointer &pointer() const { return pointer_; } const json::json_pointer &pointer() const { return pointer_; }
const std::string &identifier() const { return identifier_; } const std::string &identifier() const { return identifier_; }
std::string fragment() const std::string fragment() const
@ -86,12 +100,18 @@ public:
} }
std::string url() const { return location(); } std::string url() const { return location(); }
std::string location() const; std::string location() const;
static std::string escape(const std::string &); static std::string escape(const std::string &);
// create a new json_uri based in this one and the given uri /**
// resolves relative changes (pathes or pointers) and resets part if proto or hostname changes * create a new json_uri based in this one and the given uri
* resolves relative changes (pathes or pointers) and resets part if proto or hostname changes
*
* @param uri
* @return
*/
json_uri derive(const std::string &uri) const json_uri derive(const std::string &uri) const
{ {
json_uri u = *this; json_uri u = *this;
@ -99,7 +119,9 @@ public:
return u; return u;
} }
// append a pointer-field to the pointer-part of this uri /**
* append a pointer-field to the pointer-part of this uri
*/
json_uri append(const std::string &field) const json_uri append(const std::string &field) const
{ {
if (identifier_ != "") if (identifier_ != "")
@ -132,14 +154,20 @@ extern json draft7_schema_builtin;
typedef std::function<void(const json_uri & /*id*/, json & /*value*/)> schema_loader; typedef std::function<void(const json_uri & /*id*/, json & /*value*/)> schema_loader;
typedef std::function<void(const std::string & /*format*/, const std::string & /*value*/)> format_checker; typedef std::function<void(const std::string & /*format*/, const std::string & /*value*/)> format_checker;
typedef std::function<void(const std::string & /*contentEncoding*/, const std::string & /*contentMediaType*/, const json & /*instance*/)> content_checker; typedef std::function<void(const std::string & /*contentEncoding*/, const std::string & /*contentMediaType*/,
const json & /*instance*/)>
content_checker;
// Interface for validation error handlers /**
* Interface for validation error handlers
*/
class JSON_SCHEMA_VALIDATOR_API error_handler class JSON_SCHEMA_VALIDATOR_API error_handler
{ {
public: public:
virtual ~error_handler() {} virtual ~error_handler() {}
virtual void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) = 0;
virtual void
error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) = 0;
}; };
class JSON_SCHEMA_VALIDATOR_API basic_error_handler : public error_handler class JSON_SCHEMA_VALIDATOR_API basic_error_handler : public error_handler
@ -147,12 +175,14 @@ class JSON_SCHEMA_VALIDATOR_API basic_error_handler : public error_handler
bool error_{false}; bool error_{false};
public: public:
void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) override void error(const json::json_pointer & /*ptr*/, const json & /*instance*/,
const std::string & /*message*/) override
{ {
error_ = true; error_ = true;
} }
virtual void reset() { error_ = false; } virtual void reset() { error_ = false; }
operator bool() const { return error_; } operator bool() const { return error_; }
}; };
@ -171,24 +201,40 @@ public:
json_validator(schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); json_validator(schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr);
json_validator(const json &, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); json_validator(const json &, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr);
json_validator(json &&, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); json_validator(json &&, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr);
json_validator(json_validator &&); json_validator(json_validator &&);
json_validator &operator=(json_validator &&); json_validator &operator=(json_validator &&);
json_validator(json_validator const &) = delete; json_validator(json_validator const &) = delete;
json_validator &operator=(json_validator const &) = delete; json_validator &operator=(json_validator const &) = delete;
~json_validator(); ~json_validator();
// insert and set the root-schema /**
* insert and set the root-schema
*
*/
void set_root_schema(const json &); void set_root_schema(const json &);
void set_root_schema(json &&); void set_root_schema(json &&);
// validate a json-document based on the root-schema /**
* validate a json-document based on the root-schema
*
* @return
*/
json validate(const json &) const; json validate(const json &) const;
// validate a json-document based on the root-schema with a custom error-handler /**
* validate a json-document based on the root-schema with a custom error-handler
*
* @param initial_uri
* @return
*/
json validate(const json &, error_handler &, const json_uri &initial_uri = json_uri("#")) const; json validate(const json &, error_handler &, const json_uri &initial_uri = json_uri("#")) const;
}; };