Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
jsonpointer.h
1#ifndef SOURCEMETA_CORE_JSONPOINTER_H_
2#define SOURCEMETA_CORE_JSONPOINTER_H_
3
4#ifndef SOURCEMETA_CORE_JSONPOINTER_EXPORT
5#include <sourcemeta/core/jsonpointer_export.h>
6#endif
7
8#include <sourcemeta/core/json.h>
9#include <sourcemeta/core/uri.h>
10
11// NOLINTBEGIN(misc-include-cleaner)
12#include <sourcemeta/core/jsonpointer_error.h>
13#include <sourcemeta/core/jsonpointer_pointer.h>
14#include <sourcemeta/core/jsonpointer_position.h>
15#include <sourcemeta/core/jsonpointer_walker.h>
16// NOLINTEND(misc-include-cleaner)
17
18#include <cassert> // assert
19#include <functional> // std::reference_wrapper
20#include <memory> // std::allocator
21#include <optional> // std::optional
22#include <ostream> // std::basic_ostream
23#include <string> // std::basic_string
24#include <string_view> // std::string_view
25
34
35namespace sourcemeta::core {
36
40
45 // We use this instead of a string view as the latter occupies more memory
46 std::reference_wrapper<const std::string>, PropertyHashJSON<JSON::String>>;
47
51
55
75SOURCEMETA_CORE_JSONPOINTER_EXPORT
76auto get(const JSON &document, const Pointer &pointer) -> const JSON &;
77
78// Constant reference parameters can accept xvalues which will be destructed
79// after the call. When the function returns such a parameter also as constant
80// reference, then the returned reference can be used after the object it refers
81// to has been destroyed.
82// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
83// This overload avoids mis-uses of retuning const reference parameter as
84// constant reference.
85auto get(JSON &&document, const Pointer &pointer) -> const JSON & = delete;
86
108SOURCEMETA_CORE_JSONPOINTER_EXPORT
109auto get(const JSON &document, const WeakPointer &pointer) -> const JSON &;
110
111// Constant reference parameters can accept xvalues which will be destructed
112// after the call. When the function returns such a parameter also as constant
113// reference, then the returned reference can be used after the object it refers
114// to has been destroyed.
115// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/return-const-ref-from-parameter.html
116// This overload avoids mis-uses of retuning const reference parameter as
117// constant reference.
118auto get(JSON &&document, const WeakPointer &pointer) -> const JSON & = delete;
119
139SOURCEMETA_CORE_JSONPOINTER_EXPORT
140auto get(JSON &document, const WeakPointer &pointer) -> JSON &;
141
159SOURCEMETA_CORE_JSONPOINTER_EXPORT
160auto try_get(const JSON &document, const Pointer &pointer) -> const JSON *;
161
180SOURCEMETA_CORE_JSONPOINTER_EXPORT
181auto try_get(const JSON &document, const WeakPointer &pointer) -> const JSON *;
182
204SOURCEMETA_CORE_JSONPOINTER_EXPORT
205auto get(JSON &document, const Pointer &pointer) -> JSON &;
206
227SOURCEMETA_CORE_JSONPOINTER_EXPORT
228auto get(const JSON &document, const Pointer::Token &token) -> const JSON &;
229
251SOURCEMETA_CORE_JSONPOINTER_EXPORT
252auto get(const JSON &document, const WeakPointer::Token &token) -> const JSON &;
253
273SOURCEMETA_CORE_JSONPOINTER_EXPORT
274auto get(JSON &document, const Pointer::Token &token) -> JSON &;
275
299SOURCEMETA_CORE_JSONPOINTER_EXPORT
300auto set(JSON &document, const Pointer &pointer, const JSON &value) -> void;
301
324SOURCEMETA_CORE_JSONPOINTER_EXPORT
325auto set(JSON &document, const Pointer &pointer, JSON &&value) -> void;
326
349SOURCEMETA_CORE_JSONPOINTER_EXPORT
350auto remove(JSON &document, const Pointer &pointer) -> bool;
351
375SOURCEMETA_CORE_JSONPOINTER_EXPORT
376auto remove(JSON &document, const WeakPointer &pointer) -> bool;
377
392SOURCEMETA_CORE_JSONPOINTER_EXPORT
393auto to_pointer(const JSON &document) -> Pointer;
394
406SOURCEMETA_CORE_JSONPOINTER_EXPORT
408 const std::basic_string_view<JSON::Char, JSON::CharTraits> input)
409 -> Pointer;
410
427SOURCEMETA_CORE_JSONPOINTER_EXPORT
428auto fragment_to_pointer(const URI &uri) -> std::optional<Pointer>;
429
445SOURCEMETA_CORE_JSONPOINTER_EXPORT
446auto to_pointer(const WeakPointer &pointer) -> Pointer;
447
460SOURCEMETA_CORE_JSONPOINTER_EXPORT
461auto is_pointer(std::string_view input) noexcept -> bool;
462
480SOURCEMETA_CORE_JSONPOINTER_EXPORT
481auto is_relative_pointer(std::string_view input) noexcept -> bool;
482
500SOURCEMETA_CORE_JSONPOINTER_EXPORT
501auto to_weak_pointer(const Pointer &pointer) -> WeakPointer;
502
518SOURCEMETA_CORE_JSONPOINTER_EXPORT
519auto stringify(const Pointer &pointer,
520 std::basic_ostream<JSON::Char, JSON::CharTraits> &stream)
521 -> void;
522
539SOURCEMETA_CORE_JSONPOINTER_EXPORT
540auto stringify(const WeakPointer &pointer,
541 std::basic_ostream<JSON::Char, JSON::CharTraits> &stream)
542 -> void;
543
557SOURCEMETA_CORE_JSONPOINTER_EXPORT
558auto to_string(const Pointer &pointer)
559 -> std::basic_string<JSON::Char, JSON::CharTraits,
560 std::allocator<JSON::Char>>;
561
577SOURCEMETA_CORE_JSONPOINTER_EXPORT
578auto to_string(const WeakPointer &pointer)
579 -> std::basic_string<JSON::Char, JSON::CharTraits,
580 std::allocator<JSON::Char>>;
581
598SOURCEMETA_CORE_JSONPOINTER_EXPORT
599auto to_uri(const Pointer &pointer) -> URI;
600
618SOURCEMETA_CORE_JSONPOINTER_EXPORT
619auto to_uri(const Pointer &pointer, const URI &base) -> URI;
620
623SOURCEMETA_CORE_JSONPOINTER_EXPORT
624auto to_uri(const WeakPointer &pointer) -> URI;
625
629SOURCEMETA_CORE_JSONPOINTER_EXPORT
630auto to_uri(const WeakPointer &pointer, const URI &base) -> URI;
631
635SOURCEMETA_CORE_JSONPOINTER_EXPORT
636auto to_uri(const WeakPointer &pointer, const std::string_view base) -> URI;
637
668
669} // namespace sourcemeta::core
670
671#endif
SOURCEMETA_CORE_DIFF_EXPORT auto stringify(const Diff &document, std::ostream &stream, const Diff::Format format, const Diff::FormatOptions &options={}) -> void
char Char
The character type used by the JSON document.
Definition json_value.h:42
std::char_traits< Char > CharTraits
The character traits used by the JSON document.
Definition json_value.h:44
Definition json_value.h:39
Definition json_hash.h:36
GenericToken< JSON::String, PropertyHashJSON< JSON::String > > Token
Definition jsonpointer_pointer.h:28
Definition jsonpointer_pointer.h:25
Definition jsonpointer_walker.h:16
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto try_get(const JSON &document, const Pointer &pointer) -> const JSON *
const Pointer empty_pointer
Definition jsonpointer.h:50
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto set(JSON &document, const Pointer &pointer, const JSON &value) -> void
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto to_uri(const Pointer &pointer) -> URI
GenericPointerWalker< WeakPointer > PointerWalker
Definition jsonpointer.h:667
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto remove(JSON &document, const Pointer &pointer) -> bool
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto is_relative_pointer(std::string_view input) noexcept -> bool
GenericPointer< JSON::String, PropertyHashJSON< JSON::String > > Pointer
Definition jsonpointer.h:39
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto fragment_to_pointer(const URI &uri) -> std::optional< Pointer >
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto to_pointer(const JSON &document) -> Pointer
const WeakPointer empty_weak_pointer
Definition jsonpointer.h:54
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto to_weak_pointer(const Pointer &pointer) -> WeakPointer
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto get(const JSON &document, const Pointer &pointer) -> const JSON &
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto to_string(const Pointer &pointer) -> std::basic_string< JSON::Char, JSON::CharTraits, std::allocator< JSON::Char > >
GenericPointer< std::reference_wrapper< const std::string >, PropertyHashJSON< JSON::String > > WeakPointer
Definition jsonpointer.h:44
SOURCEMETA_CORE_JSONPOINTER_EXPORT auto is_pointer(std::string_view input) noexcept -> bool
Definition uri.h:43