Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
jsonld_error.h
1#ifndef SOURCEMETA_CORE_JSONLD_ERROR_H_
2#define SOURCEMETA_CORE_JSONLD_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_JSONLD_EXPORT
5#include <sourcemeta/core/jsonld_export.h>
6#endif
7
8#include <sourcemeta/core/error.h>
9#include <sourcemeta/core/json.h>
10#include <sourcemeta/core/jsonpointer.h>
11
12#include <initializer_list> // std::initializer_list
13#include <utility> // std::move
14
15namespace sourcemeta::core {
16
17SOURCEMETA_CORE_ERROR_WARNINGS_PUSH
18
23class SOURCEMETA_CORE_JSONLD_EXPORT JSONLDError : public Error {
24public:
26 JSONLDError(const StaticString code, Pointer pointer)
27 : Error{code}, pointer_{std::move(pointer)} {}
28
30 JSONLDError(const StaticString code, const WeakPointer &pointer)
31 : Error{code}, pointer_{to_pointer(pointer)} {}
32
35 JSONLDError(const StaticString code, const WeakPointer &pointer,
36 const std::initializer_list<JSON::StringView> children)
37 : Error{code}, pointer_{to_pointer(pointer)} {
38 for (const auto child : children) {
39 this->pointer_.push_back(JSON::String{child});
40 }
41 }
42
45 [[nodiscard]] auto pointer() const noexcept -> const Pointer & {
46 return this->pointer_;
47 }
48
49private:
50 Pointer pointer_;
51};
52
58class SOURCEMETA_CORE_JSONLD_EXPORT JSONLDFragmentError : public JSONLDError {
59public:
63 : JSONLDError{code, std::move(pointer)}, key_{std::move(key)} {}
64
67 [[nodiscard]] auto key() const noexcept -> const JSON::String & {
68 return this->key_;
69 }
70
71private:
72 JSON::String key_;
73};
74
75SOURCEMETA_CORE_ERROR_WARNINGS_POP
76
77} // namespace sourcemeta::core
78
79#endif
Error(const StaticString message) noexcept
Construct the error given its message.
Definition error_base.h:84
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
Definition json_value.h:39
JSONLDError(const StaticString code, const WeakPointer &pointer, const std::initializer_list< JSON::StringView > children)
Definition jsonld_error.h:35
JSONLDError(const StaticString code, Pointer pointer)
Locate the error at an owned pointer.
Definition jsonld_error.h:26
JSONLDFragmentError(const StaticString code, Pointer pointer, JSON::String key)
Locate the error at a fragment entry.
Definition jsonld_error.h:61
JSONLDError(const StaticString code, const WeakPointer &pointer)
Locate the error at a weak pointer, materialising an owned pointer.
Definition jsonld_error.h:30
auto key() const noexcept -> const JSON::String &
Definition jsonld_error.h:67
GenericPointer< JSON::String, PropertyHashJSON< JSON::String > > Pointer
Definition jsonpointer.h:41
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto to_pointer(const JSON &document) -> Pointer
GenericPointer< std::reference_wrapper< const std::string >, PropertyHashJSON< JSON::String > > WeakPointer
Definition jsonpointer.h:46
Definition text_static_string.h:20