Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Pointer.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_DataExchange_JSON_Pointer_h_
5#define _Stroika_Foundation_DataExchange_JSON_Pointer_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
10#include "Stroika/Foundation/Common/Concepts.h"
11#include "Stroika/Foundation/Containers/Sequence.h"
13#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
15
16/**
17 */
19
20 using namespace Stroika::Foundation;
21
25
26 /**
27 * @see https://datatracker.ietf.org/doc/html/rfc6901/
28 *
29 * Note this really only supports fully looking up data in an VariantValue, not (yet) providing the ability
30 * to index to update a VariantValue (like add to an array elt - need fancier Apply API support for that).
31 * @todo http://stroika-bugs.sophists.com/browse/STK-1007 - improve API to allow update
32 */
34 public:
35 /**
36 */
37 template <Characters::IConvertibleToString STRINGISH_TYPE = String>
38 PointerType (STRINGISH_TYPE&& s);
39 PointerType () = default;
40
41 public:
42 /**
43 * When applying a JSONPointer to a VariantValue, sometimes you just want the result. Sometimes
44 * you want info about the surrounding object (to modify).
45 */
46 struct Context {
47 struct MapElt {
49 String fEltName;
50 bool operator== (const MapElt&) const = default; // @todo understand why this declaration needed (Iterable<>find...)
51
52 /**
53 */
54 String ToString () const;
55 };
56 struct SeqElt {
57 Sequence<VariantValue> fOrigValue;
58 size_t fIndex;
59
60 bool operator== (const SeqElt&) const = default; // @todo understand why this declaration needed (Iterable<>find...)
61
62 /**
63 */
64 String ToString () const;
65 };
67
68 /**
69 * Take the context in 'this' - and treat all offsets as Set (not remove or add); leafToUse only applied
70 * to replace the 'value' that would have been returned by Apply (or ApplyWithContext).
71 */
72 optional<VariantValue> ConstructNewFrom (const optional<VariantValue>& leafToUse) const;
73
74 /**
75 */
76 String ToString () const;
77 };
78
79 public:
80 /**
81 * Some references might be to non-existent objects, so return nullopt in that case - like bad array reference, or missing object member.
82 */
83 nonvirtual optional<VariantValue> Apply (const VariantValue& v) const;
84
85 public:
86 /**
87 * Some references might be to non-existent objects, so return nullopt in that case - like bad array reference, or missing object member.
88 */
89 nonvirtual optional<tuple<Context, VariantValue>> ApplyWithContext (const VariantValue& v) const;
90 nonvirtual optional<VariantValue> ApplyWithContext (const VariantValue& v, Context* contextOut) const;
91
92 public:
93 /**
94 */
95 template <Common::IAnyOf<String> T>
96 nonvirtual T As () const;
97
98 public:
99 /**
100 */
101 nonvirtual bool operator== (const PointerType&) const = default;
102
103 public:
104 /**
105 */
106 nonvirtual auto operator<=> (const PointerType&) const = default;
107
108 public:
109 /**
110 */
111 nonvirtual String ToString () const;
112
113 public:
114 static const DataExchange::ObjectVariantMapper kMapper;
115
116 private:
117 // first component refers to top of tree;
118 // components are raw strings and must match nodes exactly (unescaped already)
119 Sequence<String> fComponents_;
120 };
121 template <>
122 PointerType::PointerType (const String& s);
123
124}
125
126/*
127 ********************************************************************************
128 ***************************** Implementation Details ***************************
129 ********************************************************************************
130 */
131#include "Pointer.inl"
132
133#endif /*_Stroika_Foundation_DataExchange_JSON_Pointer_h_*/
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
A generalization of a vector: a container whose elements are keyed by the natural numbers.
Definition Sequence.h:187
nonvirtual optional< VariantValue > Apply(const VariantValue &v) const
Definition Pointer.inl:28
nonvirtual optional< tuple< Context, VariantValue > > ApplyWithContext(const VariantValue &v) const
Definition Pointer.inl:32
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
optional< VariantValue > ConstructNewFrom(const optional< VariantValue > &leafToUse) const
Definition Pointer.cpp:89