nfx-serialization 0.3.0
Cross-platform C++ JSON serialization library with extensible trait capabilities
Loading...
Searching...
No Matches
Document.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 nfx
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
29
30#pragma once
31
32#include <cstdint>
33#include <iterator>
34#include <memory>
35#include <optional>
36#include <span>
37#include <string>
38#include <string_view>
39#include <type_traits>
40#include <utility>
41#include <vector>
42
43#include "Concepts.h"
44
45namespace nfx::serialization::json
46{
47 class Document_impl;
48
49 //=====================================================================
50 // Document class
51 //=====================================================================
52
58 class Document final
59 {
60 public:
61 //----------------------------------------------
62 // Forward declarations
63 //----------------------------------------------
64
65 class Array;
66 class Object;
67
68 //----------------------------------------------
69 // Friends
70 //----------------------------------------------
71
72 friend class Document_impl;
73 friend class SchemaValidator_impl;
74
75 //----------------------------------------------
76 // Construction
77 //----------------------------------------------
78
83
88 Document( const Document& other );
89
94 Document( Document&& other ) noexcept;
95
96 //----------------------------------------------
97 // Destruction
98 //----------------------------------------------
99
104
105 //----------------------------------------------
106 // Assignment
107 //----------------------------------------------
108
114 Document& operator=( const Document& other );
115
121 Document& operator=( Document&& other ) noexcept;
122
123 //----------------------------------------------
124 // Comparison
125 //----------------------------------------------
126
132 bool operator==( const Document& other ) const;
133
139 bool operator!=( const Document& other ) const;
140
141 //----------------------------------------------
142 // Factory
143 //----------------------------------------------
144
150 static std::optional<Document> fromString( std::string_view jsonStr );
151
158 static bool fromString( std::string_view jsonStr, Document& doc );
159
165 static std::optional<Document> fromBytes( std::span<const uint8_t> bytes );
166
173 static bool fromBytes( std::span<const uint8_t> bytes, Document& doc );
174
175 //----------------------------------------------
176 // Output
177 //----------------------------------------------
178
186 std::string toString( int indent = 0 ) const;
187
192 std::vector<uint8_t> toBytes() const;
193
194 //----------------------------------------------
195 // Merge / update operations
196 //----------------------------------------------
197
203 void merge( const Document& other, bool overwriteArrays = true );
204
210 void update( std::string_view path, const Document& value );
211
212 //----------------------------------------------
213 // Value existence
214 //----------------------------------------------
215
221 bool contains( std::string_view path ) const;
222
223 //----------------------------------------------
224 // Value access
225 //----------------------------------------------
226
233 template <JsonValue T>
234 std::optional<T> get( std::string_view path ) const;
235
243 template <JsonValue T>
244 bool get( std::string_view path, T& value ) const;
245
246 //----------------------------------------------
247 // Value modification
248 //----------------------------------------------
249
256 template <JsonValue T>
257 void set( std::string_view path, const T& value );
258
265 template <JsonValue T>
266 void set( std::string_view path, T&& value );
267
268 //-----------------------------
269 // Type-only creation
270 //-----------------------------
271
277 template <JsonContainer T>
278 void set( std::string_view path );
279
280 //-----------------------------
281 // Null operations
282 //-----------------------------
283
288 void setNull( std::string_view path );
289
290 //----------------------------------------------
291 // Type checking
292 //----------------------------------------------
293
300 template <JsonCheckable T>
301 bool is( std::string_view path ) const;
302
308 bool isNull( std::string_view path ) const;
309
310 //----------------------------------------------
311 // Validation and error handling
312 //----------------------------------------------
313
318 bool isValid() const;
319
324 std::string lastError() const;
325
326 //----------------------------------------------
327 // Document::Object class
328 //----------------------------------------------
329
335 class Object final
336 {
337 //----------------------------------------------
338 // Friends
339 //----------------------------------------------
340
341 friend class Document;
342 friend class Document_impl;
343
344 //-----------------------------
345 // Construction
346 //-----------------------------
347
348 private:
349 Object( Document* doc, std::string_view path );
350
351 public:
356
361 Object( const Document::Object& other );
362
367 Object( Document::Object&& other ) noexcept;
368
369 //-----------------------------
370 // Destruction
371 //-----------------------------
372
374 ~Object() = default;
375
376 //-----------------------------
377 // Assignment
378 //-----------------------------
379
386
393
394 //-----------------------------
395 // Comparison
396 //-----------------------------
397
403 bool operator==( const Document::Object& other ) const;
404
410 bool operator!=( const Document::Object& other ) const;
411
412 //-----------------------------
413 // Output
414 //-----------------------------
415
423 std::string toString( int indent = 0 ) const;
424
429 std::vector<uint8_t> toBytes() const;
430
431 //-----------------------------
432 // Size
433 //-----------------------------
434
439 size_t size() const;
440
441 //-----------------------------
442 // Clearing
443 //-----------------------------
444
448 void clear();
449
450 //-----------------------------
451 // Field removal
452 //-----------------------------
453
459 bool removeField( std::string_view key );
460
461 //-----------------------------
462 // Field existence
463 //-----------------------------
464
470 bool contains( std::string_view fieldName ) const;
471
472 //-----------------------------
473 // Field access
474 //-----------------------------
475
482 template <JsonValue T>
483 std::optional<T> get( std::string_view path ) const;
484
492 template <JsonValue T>
493 bool get( std::string_view path, T& value ) const;
494
495 //-----------------------------
496 // Field modification
497 //-----------------------------
498
505 template <JsonValue T>
506 void set( std::string_view path, const T& value );
507
514 template <JsonValue T>
515 void set( std::string_view path, T&& value );
516
517 //-----------------------------
518 // Validation and error handling
519 //-----------------------------
520
525 bool isValid() const;
526
531 std::string lastError() const;
532
533 //----------------------------------------------
534 // Document::Object::Iterator class
535 //----------------------------------------------
536
543 {
544 public:
545 //-----------------------------
546 // Iterator traits
547 //-----------------------------
548
550 using iterator_category = std::forward_iterator_tag;
552 using value_type = std::pair<std::string, Document>;
554 using difference_type = std::ptrdiff_t;
559
560 //-----------------------------
561 // Construction
562 //-----------------------------
563
566
572 Iterator( const Object* obj, size_t index );
573
574 //-----------------------------
575 // Operators
576 //-----------------------------
577
583
589
595
601 bool operator==( const Iterator& other ) const;
602
608 bool operator!=( const Iterator& other ) const;
609
610 private:
611 const Object* m_obj;
612 size_t m_index;
613 };
614
620
625 Iterator end() const;
626
627 private:
628 //----------------------------------------------
629 // Private helper methods for iterator
630 //----------------------------------------------
631
637 std::string keyAt( size_t index ) const;
638
644 Document valueAt( size_t index ) const;
645
646 //----------------------------------------------
647 // Private data members
648 //----------------------------------------------
649
650 Document* m_doc;
651 std::string m_path;
652 };
653
654 //----------------------------------------------
655 // Document::Array class
656 //----------------------------------------------
657
663 class Array final
664 {
665 //-----------------------------
666 // Friends
667 //-----------------------------
668
669 friend class Document;
670 friend class Document_impl;
671
672 //-----------------------------
673 // Construction
674 //-----------------------------
675
676 private:
677 Array( Document* doc, std::string_view path );
678
679 public:
684
689 Array( const Document::Array& other );
690
695 Array( Document::Array&& other ) noexcept;
696
697 //-----------------------------
698 // Destruction
699 //-----------------------------
700
702 ~Array() = default;
703
704 //-----------------------------
705 // Assignment
706 //-----------------------------
707
714
721
722 //-----------------------------
723 // Comparison
724 //-----------------------------
725
731 bool operator==( const Document::Array& other ) const;
732
738 bool operator!=( const Document::Array& other ) const;
739
740 //-----------------------------
741 // Output
742 //-----------------------------
743
751 std::string toString( int indent = 0 ) const;
752
757 std::vector<uint8_t> toBytes() const;
758
759 //-----------------------------
760 // Size
761 //-----------------------------
762
767 size_t size() const;
768
769 //-----------------------------
770 // Clearing
771 //-----------------------------
772
776 void clear();
777
778 //-----------------------------
779 // Element removal
780 //-----------------------------
781
787 bool remove( size_t index );
788
789 //-----------------------------
790 // Element existence
791 //-----------------------------
792
798 bool contains( std::string_view indexStr ) const;
799
800 //-----------------------------
801 // Element access
802 //-----------------------------
803
810 template <JsonValue T>
811 std::optional<T> get( size_t index ) const;
812
820 template <JsonValue T>
821 bool get( size_t index, T& value ) const;
822
823 //-----------------------------
824 // Nested element access
825 //-----------------------------
826
833 template <JsonValue T>
834 std::optional<T> get( std::string_view path ) const;
835
843 template <JsonValue T>
844 bool get( std::string_view path, T& value ) const;
845
846 //-----------------------------
847 // Element modification
848 //-----------------------------
849
856 template <JsonValue T>
857 void set( size_t index, const T& value );
858
865 template <JsonValue T>
866 void set( size_t index, T&& value );
867
868 //-----------------------------
869 // Nested element modification
870 //-----------------------------
871
878 template <JsonValue T>
879 void set( std::string_view path, const T& value );
880
887 template <JsonValue T>
888 void set( std::string_view path, T&& value );
889
890 //-----------------------------
891 // Element addition
892 //-----------------------------
893
899 template <JsonValue T>
900 void append( const T& value );
901
907 template <JsonValue T>
908 void append( T&& value );
909
914 void append( Document& value );
915
920 void append( Document::Array& value );
921
926 void append( Document::Object& value );
927
928 //-----------------------------
929 // Element insertion
930 //-----------------------------
931
938 template <JsonValue T>
939 void insert( size_t index, const T& value );
940
947 template <JsonValue T>
948 void insert( size_t index, T&& value );
949
955 void insert( size_t index, Document& value );
956
962 void insert( size_t index, Document::Array& value );
963
969 void insert( size_t index, Document::Object& value );
970
971 //-----------------------------
972 // Validation and error handling
973 //-----------------------------
974
979 bool isValid() const;
980
985 std::string lastError() const;
986
987 //----------------------------------------------
988 // Document::Array::Iterator class
989 //----------------------------------------------
990
997 {
998 public:
999 //-----------------------------
1000 // Iterator traits
1001 //-----------------------------
1002
1004 using iterator_category = std::forward_iterator_tag;
1006 using value_type = Document;
1008 using difference_type = std::ptrdiff_t;
1013
1014 //-----------------------------
1015 // Construction
1016 //-----------------------------
1017
1020
1026 Iterator( const Array* arr, size_t index );
1027
1028 //-----------------------------
1029 // Operators
1030 //-----------------------------
1031
1037
1043
1049
1055 bool operator==( const Iterator& other ) const;
1056
1062 bool operator!=( const Iterator& other ) const;
1063
1064 private:
1065 const Array* m_arr;
1066 size_t m_index;
1067 };
1068
1074
1079 Iterator end() const;
1080
1081 private:
1082 //-----------------------------
1083 // Private data members
1084 //-----------------------------
1085
1086 Document* m_doc;
1087 std::string m_path;
1088 };
1089
1090 //----------------------------------------------
1091 // Document::PathView class
1092 //----------------------------------------------
1093
1106 class PathView final
1107 {
1108 public:
1109 //-----------------------------
1110 // Forward declaration
1111 //-----------------------------
1112
1113 class Iterator;
1114
1115 //-----------------------------
1116 // Format
1117 //-----------------------------
1118
1122 enum class Format : bool
1123 {
1126 };
1127
1128 //-----------------------------
1129 // Path entry structure
1130 //-----------------------------
1131
1135 struct Entry
1136 {
1137 std::string path;
1138 std::unique_ptr<Document> valuePtr;
1139 size_t depth;
1140 bool isLeaf;
1141
1146 const Document& value() const { return *valuePtr; }
1147
1149 Entry() : depth{ 0 }, isLeaf{ false } {}
1150
1155 Entry( Entry&& other ) noexcept = default;
1156
1162 Entry& operator=( Entry&& other ) noexcept = default;
1163
1168 Entry( const Entry& other );
1169
1175 Entry& operator=( const Entry& other );
1176 };
1177
1178 //----------------------------------------------
1179 // Construction
1180 //----------------------------------------------
1181
1195 explicit PathView(
1196 const Document& doc,
1197 Format format = Format::JsonPointer,
1198 bool includeContainers = true );
1199
1200 //----------------------------------------------
1201 // Range interface (for range-for loops)
1202 //----------------------------------------------
1203
1208 Iterator begin() const { return Iterator{ &m_entries, 0 }; }
1209
1214 Iterator end() const { return Iterator{ &m_entries, m_entries.size() }; }
1215
1216 //----------------------------------------------
1217 // Direct access
1218 //----------------------------------------------
1219
1224 size_t size() const { return m_entries.size(); }
1225
1230 bool empty() const { return m_entries.empty(); }
1231
1237 const Entry& operator[]( size_t index ) const { return m_entries[index]; }
1238
1239 //----------------------------------------------
1240 // Filtering
1241 //----------------------------------------------
1242
1247 std::vector<Entry> leaves() const;
1248
1249 //----------------------------------------------
1250 // Document::PathView::Iterator class
1251 //----------------------------------------------
1252
1257 {
1258 public:
1260 using iterator_category = std::forward_iterator_tag;
1264 using difference_type = std::ptrdiff_t;
1266 using pointer = const Entry*;
1268 using reference = const Entry&;
1269
1272 : m_entries{ nullptr },
1273 m_index{ 0 }
1274 {
1275 }
1276
1282 Iterator( const std::vector<Entry>* entries, size_t index )
1283 : m_entries{ entries },
1284 m_index{ index }
1285 {
1286 }
1287
1292 reference operator*() const { return ( *m_entries )[m_index]; }
1293
1298 pointer operator->() const { return &( *m_entries )[m_index]; }
1299
1305 {
1306 ++m_index;
1307 return *this;
1308 }
1309
1315 {
1316 Iterator tmp = *this;
1317 ++m_index;
1318 return tmp;
1319 }
1320
1326 bool operator==( const Iterator& other ) const
1327 {
1328 if ( !m_entries && !other.m_entries )
1329 {
1330 return true;
1331 }
1332 if ( !m_entries )
1333 {
1334 return other.m_index >= other.m_entries->size();
1335 }
1336 if ( !other.m_entries )
1337 {
1338 return m_index >= m_entries->size();
1339 }
1340 return m_entries == other.m_entries && m_index == other.m_index;
1341 }
1342
1348 bool operator!=( const Iterator& other ) const { return !( *this == other ); }
1349
1350 private:
1351 const std::vector<Entry>* m_entries;
1352 size_t m_index;
1353 };
1354
1355 private:
1356 //----------------------------------------------
1357 // Private helper methods
1358 //----------------------------------------------
1359
1364 void buildEntries( const Document& doc );
1365
1371 std::string formatPath( const std::vector<std::string>& segments ) const;
1372
1373 //----------------------------------------------
1374 // Private data members
1375 //----------------------------------------------
1376
1377 Format m_format;
1378 bool m_includeContainers;
1379 std::vector<Entry> m_entries;
1380 };
1381
1382 private:
1383 //----------------------------------------------
1384 // Pimpl
1385 //----------------------------------------------
1386
1387 void* m_impl;
1388 };
1389
1390 //=====================================================================
1391 // Type trait specializations for Document nested classes
1392 //=====================================================================
1393
1397 template <>
1398 struct is_json_container<Document::Object> : std::true_type
1399 {
1400 };
1401
1405 template <>
1406 struct is_json_container<Document::Array> : std::true_type
1407 {
1408 };
1409} // namespace nfx::serialization::json
C++20 concepts for JSON serialization type constraints.
Type trait to identify JSON container types (Object, Array).
Definition Concepts.h:56
Generic JSON document abstraction for serialization.
Definition Document.h:59
Document(Document &&other) noexcept
Move constructor.
std::string lastError() const
Get last error message.
static bool fromString(std::string_view jsonStr, Document &doc)
Parse JSON string into existing document.
void set(std::string_view path, T &&value)
Set typed value at specified path (move version).
bool isNull(std::string_view path) const
Check if value at path is null.
void update(std::string_view path, const Document &value)
Update value at specific path.
Document()
Default constructor - creates an empty document.
bool is(std::string_view path) const
Check if value at path is of specified type.
void set(std::string_view path)
Create empty container at specified path.
bool operator==(const Document &other) const
Equality comparison operator.
bool isValid() const
Check if document is in valid state.
~Document()
Destructor - cleans up document resources.
void set(std::string_view path, const T &value)
Set typed value at specified path (copy version).
bool contains(std::string_view path) const
Check if a value exists at the specified path.
std::optional< T > get(std::string_view path) const
Get typed value at specified path.
static std::optional< Document > fromBytes(std::span< const uint8_t > bytes)
Create document from JSON bytes.
Document & operator=(const Document &other)
Copy assignment operator.
std::string toString(int indent=0) const
Convert document to JSON string.
void setNull(std::string_view path)
Set null value at specified path.
static std::optional< Document > fromString(std::string_view jsonStr)
Create document from JSON string.
Document(const Document &other)
Copy constructor.
void merge(const Document &other, bool overwriteArrays=true)
Merge another document into this one.
Document & operator=(Document &&other) noexcept
Move assignment operator.
static bool fromBytes(std::span< const uint8_t > bytes, Document &doc)
Parse JSON bytes into existing document.
std::vector< uint8_t > toBytes() const
Convert document to JSON bytes.
bool get(std::string_view path, T &value) const
Get typed value at specified path into output parameter.
bool operator!=(const Document &other) const
Inequality comparison operator.
JSON object wrapper for Document.
Definition Document.h:336
bool get(std::string_view path, T &value) const
Get field value into output parameter.
size_t size() const
Get number of fields in object.
Document::Object & operator=(Document::Object &&other) noexcept
Move assignment operator.
bool isValid() const
Check if object is valid.
void clear()
Clear all fields from object.
Document::Object & operator=(const Document::Object &other)
Copy assignment operator.
bool contains(std::string_view fieldName) const
Check if a field exists in this object.
Iterator end() const
Get iterator past last field.
void set(std::string_view path, const T &value)
Set field value (copy version).
std::string lastError() const
Get last error message.
void set(std::string_view path, T &&value)
Set field value (move version).
Iterator begin() const
Get iterator to first field.
std::optional< T > get(std::string_view path) const
Get field value by key.
std::vector< uint8_t > toBytes() const
Convert object to JSON bytes.
Object(Document::Object &&other) noexcept
Move constructor.
Object()
Default constructor - creates invalid object.
bool operator==(const Document::Object &other) const
Equality comparison operator.
bool removeField(std::string_view key)
Remove field from object.
bool operator!=(const Document::Object &other) const
Inequality comparison operator.
Object(const Document::Object &other)
Copy constructor.
std::string toString(int indent=0) const
Convert object to JSON string.
Forward iterator for Object fields.
Definition Document.h:543
value_type operator*() const
Dereference operator.
Iterator & operator++()
Pre-increment operator.
std::ptrdiff_t difference_type
Type for iterator difference.
Definition Document.h:554
bool operator!=(const Iterator &other) const
Inequality comparison.
Iterator(const Object *obj, size_t index)
Construct iterator at specific position.
value_type & reference
Reference to value type.
Definition Document.h:558
value_type * pointer
Pointer to value type.
Definition Document.h:556
std::pair< std::string, Document > value_type
Type of value yielded by iterator.
Definition Document.h:552
Iterator()
Default constructor - creates end iterator.
Iterator operator++(int)
Post-increment operator.
bool operator==(const Iterator &other) const
Equality comparison.
std::forward_iterator_tag iterator_category
Iterator category tag for STL compatibility.
Definition Document.h:550
JSON array wrapper for Document.
Definition Document.h:664
void append(Document &value)
Append Document to end of array (reference version).
bool operator==(const Document::Array &other) const
Equality comparison.
std::optional< T > get(size_t index) const
Get element at index.
void insert(size_t index, const T &value)
Insert element at index (copy version).
void set(size_t index, const T &value)
Set element at index (copy version).
std::string toString(int indent=0) const
Convert array to JSON string.
bool get(size_t index, T &value) const
Get element at index into output parameter.
void set(size_t index, T &&value)
Set element at index (move version).
void insert(size_t index, Document::Array &value)
Insert Array at index (reference version).
Document::Array & operator=(const Document::Array &other)
Copy assignment operator.
void set(std::string_view path, const T &value)
Set nested element at path (copy version).
bool contains(std::string_view indexStr) const
Check if an element exists at the specified index.
Array(Document::Array &&other) noexcept
Move constructor.
bool operator!=(const Document::Array &other) const
Inequality comparison.
void append(Document::Object &value)
Append Object to end of array (reference version).
Document::Array & operator=(Document::Array &&other) noexcept
Move assignment operator.
void append(T &&value)
Append element to end of array (move version).
size_t size() const
Get number of elements in array.
bool isValid() const
Check if array is valid.
void insert(size_t index, Document &value)
Insert Document at index (reference version).
Iterator end() const
Get iterator past last element.
void insert(size_t index, Document::Object &value)
Insert Object at index (reference version).
void set(std::string_view path, T &&value)
Set nested element at path (move version).
bool remove(size_t index)
Remove element at index.
void clear()
Clear all elements from array.
std::vector< uint8_t > toBytes() const
Convert array to JSON bytes.
void append(Document::Array &value)
Append Array to end of array (reference version).
Array(const Document::Array &other)
Copy constructor.
void insert(size_t index, T &&value)
Insert element at index (move version).
void append(const T &value)
Append element to end of array (copy version).
Array()
Default constructor - creates empty array.
std::string lastError() const
Get last error message.
std::optional< T > get(std::string_view path) const
Get nested element at path.
Iterator begin() const
Get iterator to first element.
bool get(std::string_view path, T &value) const
Get nested element at path into output parameter.
Forward iterator for Array elements.
Definition Document.h:997
Document value_type
Type of value yielded by iterator.
Definition Document.h:1006
value_type * pointer
Pointer to value type.
Definition Document.h:1010
Iterator(const Array *arr, size_t index)
Construct iterator at specific position.
Iterator & operator++()
Pre-increment operator.
std::ptrdiff_t difference_type
Type for iterator difference.
Definition Document.h:1008
bool operator!=(const Iterator &other) const
Inequality comparison.
bool operator==(const Iterator &other) const
Equality comparison.
value_type operator*() const
Dereference operator.
std::forward_iterator_tag iterator_category
Iterator category tag for STL compatibility.
Definition Document.h:1004
value_type & reference
Reference to value type.
Definition Document.h:1012
Iterator operator++(int)
Post-increment operator.
Iterator()
Default constructor - creates end iterator.
bool empty() const
Check if empty.
Definition Document.h:1230
Iterator end() const
Get iterator past last entry.
Definition Document.h:1214
Format
Format for path string representation.
Definition Document.h:1123
@ DotNotation
Dot notation format (e.g., "user.addresses[0].city").
Definition Document.h:1125
@ JsonPointer
RFC 6901 JSON Pointer format (e.g., "/user/addresses/0/city").
Definition Document.h:1124
size_t size() const
Get number of path entries.
Definition Document.h:1224
const Entry & operator[](size_t index) const
Access entry by index.
Definition Document.h:1237
std::vector< Entry > leaves() const
Get only leaf entries (primitives).
Iterator begin() const
Get iterator to first entry.
Definition Document.h:1208
PathView(const Document &doc, Format format=Format::JsonPointer, bool includeContainers=true)
Construct PathView for a document.
Represents a single path entry in the document.
Definition Document.h:1136
Entry(const Entry &other)
Copy constructor (deep copy).
bool isLeaf
True if value is a primitive (not object/array).
Definition Document.h:1140
std::unique_ptr< Document > valuePtr
The value at this path (owned pointer).
Definition Document.h:1138
Entry(Entry &&other) noexcept=default
Move constructor.
std::string path
Full path to this value.
Definition Document.h:1137
Entry & operator=(const Entry &other)
Copy assignment (deep copy).
Entry & operator=(Entry &&other) noexcept=default
Move assignment.
size_t depth
Nesting depth (0 = root level).
Definition Document.h:1139
const Document & value() const
Get the value as a Document reference.
Definition Document.h:1146
bool operator==(const Iterator &other) const
Equality comparison.
Definition Document.h:1326
bool operator!=(const Iterator &other) const
Inequality comparison.
Definition Document.h:1348
std::forward_iterator_tag iterator_category
Iterator category tag for STL compatibility.
Definition Document.h:1260
Iterator operator++(int)
Post-increment operator.
Definition Document.h:1314
Iterator(const std::vector< Entry > *entries, size_t index)
Construct iterator at position.
Definition Document.h:1282
const Entry * pointer
Pointer to value type.
Definition Document.h:1266
Entry value_type
Type of value yielded by iterator.
Definition Document.h:1262
Iterator & operator++()
Pre-increment operator.
Definition Document.h:1304
reference operator*() const
Dereference operator.
Definition Document.h:1292
Iterator()
Default constructor - creates end iterator.
Definition Document.h:1271
std::ptrdiff_t difference_type
Type for iterator difference.
Definition Document.h:1264
const Entry & reference
Reference to value type.
Definition Document.h:1268