File tree 2 files changed +54
-0
lines changed
2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ class MRDOX_DECL
55
55
{
56
56
std::atomic<std::size_t > mutable refs_ = 1 ;
57
57
58
+ protected:
59
+ Any () noexcept ;
60
+ Any (Any const &) noexcept ;
61
+
58
62
public:
59
63
virtual ~Any () = 0 ;
60
64
@@ -213,6 +217,8 @@ using ArrayPtr = Pointer<Array>;
213
217
class MRDOX_DECL
214
218
Object : public Any
215
219
{
220
+ Object (Object const &);
221
+
216
222
public:
217
223
using value_type = std::pair<std::string, Value>;
218
224
using list_type = std::vector<value_type>;
@@ -222,6 +228,7 @@ class MRDOX_DECL
222
228
list_type const & list () const noexcept ;
223
229
void append (std::string_view key, Value value);
224
230
void append (std::initializer_list<value_type>);
231
+ virtual Value copy () const ;
225
232
virtual bool empty () const noexcept ;
226
233
virtual Value get (std::string_view key) const ;
227
234
virtual void set (std::string_view key, Value value);
@@ -357,6 +364,10 @@ class MRDOX_DECL
357
364
{
358
365
}
359
366
367
+ /* * Return a copy.
368
+ */
369
+ Value copy () const ;
370
+
360
371
dom::Kind kind () const noexcept ;
361
372
bool isNull () const noexcept { return kind_ == Kind::Null; }
362
373
bool isBool () const noexcept { return kind_ == Kind::Boolean ; }
Original file line number Diff line number Diff line change @@ -14,6 +14,15 @@ namespace clang {
14
14
namespace mrdox {
15
15
namespace dom {
16
16
17
+ Any::
18
+ Any () noexcept = default ;
19
+
20
+ Any::
21
+ Any (Any const &) noexcept
22
+ {
23
+ MRDOX_ASSERT (refs_ == 1 );
24
+ }
25
+
17
26
Any::
18
27
~Any () = default ;
19
28
@@ -35,6 +44,10 @@ get(std::size_t) const
35
44
36
45
// ------------------------------------------------
37
46
47
+ Object::
48
+ Object (
49
+ Object const &) = default ;
50
+
38
51
Object::
39
52
Object () noexcept = default ;
40
53
@@ -70,6 +83,13 @@ append(
70
83
list_.insert (list_.end (), init);
71
84
}
72
85
86
+ Value
87
+ Object::
88
+ copy () const
89
+ {
90
+ return create<Object>(list_);
91
+ }
92
+
73
93
bool
74
94
Object::
75
95
empty () const noexcept
@@ -333,6 +353,29 @@ operator=(
333
353
return *this ;
334
354
}
335
355
356
+ Value
357
+ Value::
358
+ copy () const
359
+ {
360
+ switch (kind_)
361
+ {
362
+ case Kind::Null:
363
+ case Kind::Boolean :
364
+ case Kind::Integer:
365
+ case Kind::String:
366
+ return *this ;
367
+ case Kind::Array:
368
+ // VFALCO currently, arrays are immutable so
369
+ // we can just give the caller shared ownership.
370
+ return *this ;
371
+ case Kind::Object:
372
+ case Kind::LazyObject:
373
+ return obj_->copy ();
374
+ default :
375
+ MRDOX_UNREACHABLE ();
376
+ }
377
+ }
378
+
336
379
dom::Kind
337
380
Value::
338
381
kind () const noexcept
You can’t perform that action at this time.
0 commit comments