@@ -60,8 +60,15 @@ CompoundWrite CompoundWrite::EmptyWrite() { return CompoundWrite(); }
60
60
61
61
CompoundWrite CompoundWrite::AddWrite (const Path& path,
62
62
const Optional<Variant>& variant) const {
63
+ CompoundWrite target = *this ;
64
+ target.AddWriteInline (path, variant);
65
+ return target;
66
+ }
67
+
68
+ void CompoundWrite::AddWriteInline (const Path& path,
69
+ const Optional<Variant>& variant) {
63
70
if (path.empty ()) {
64
- return CompoundWrite (Tree<Variant>(variant));
71
+ * this = CompoundWrite (Tree<Variant>(variant));
65
72
} else {
66
73
Optional<Path> root_most_path = write_tree_.FindRootMostPathWithValue (path);
67
74
if (root_most_path.has_value ()) {
@@ -78,18 +85,13 @@ CompoundWrite CompoundWrite::AddWrite(const Path& path,
78
85
if (!relative_path->empty () && IsPriorityKey (back) &&
79
86
VariantIsEmpty (VariantGetChild (value, relative_path->GetParent ()))) {
80
87
// Ignore priority updates on empty variants
81
- return *this ;
82
88
} else {
83
- CompoundWrite result = *this ;
84
89
Variant updated_variant = *value;
85
90
VariantUpdateChild (&updated_variant, *relative_path, *variant);
86
- result.write_tree_ .SetValueAt (*root_most_path, updated_variant);
87
- return result;
91
+ write_tree_.SetValueAt (*root_most_path, updated_variant);
88
92
}
89
93
} else {
90
- CompoundWrite result = *this ;
91
- result.write_tree_ .SetValueAt (path, variant);
92
- return result;
94
+ write_tree_.SetValueAt (path, variant);
93
95
}
94
96
}
95
97
}
@@ -109,6 +111,20 @@ CompoundWrite CompoundWrite::AddWrite(const std::string& key,
109
111
return AddWrite (Path (key), Optional<Variant>(value));
110
112
}
111
113
114
+ void CompoundWrite::AddWriteInline (const Path& path, const Variant& value) {
115
+ AddWriteInline (path, Optional<Variant>(value));
116
+ }
117
+
118
+ void CompoundWrite::AddWriteInline (const std::string& key,
119
+ const Optional<Variant>& value) {
120
+ AddWriteInline (Path (key), value);
121
+ }
122
+
123
+ void CompoundWrite::AddWriteInline (const std::string& key,
124
+ const Variant& value) {
125
+ AddWriteInline (Path (key), Optional<Variant>(value));
126
+ }
127
+
112
128
CompoundWrite CompoundWrite::AddWrites (const Path& path,
113
129
const CompoundWrite& updates) const {
114
130
return updates.write_tree_ .Fold (
@@ -118,6 +134,15 @@ CompoundWrite CompoundWrite::AddWrites(const Path& path,
118
134
});
119
135
}
120
136
137
+ void CompoundWrite::AddWritesInline (const Path& path,
138
+ const CompoundWrite& updates) {
139
+ updates.write_tree_ .Fold (
140
+ 0 , [&path, this ](Path relative_path, Variant value, int ) {
141
+ AddWriteInline (path.GetChild (relative_path), Optional<Variant>(value));
142
+ return 0 ;
143
+ });
144
+ }
145
+
121
146
CompoundWrite CompoundWrite::RemoveWrite (const Path& path) const {
122
147
if (path.empty ()) {
123
148
return CompoundWrite ();
@@ -133,6 +158,18 @@ CompoundWrite CompoundWrite::RemoveWrite(const Path& path) const {
133
158
return CompoundWrite ();
134
159
}
135
160
161
+ void CompoundWrite::RemoveWriteInline (const Path& path) {
162
+ if (path.empty ()) {
163
+ *this = CompoundWrite ();
164
+ } else {
165
+ Tree<Variant>* subtree = write_tree_.GetChild (path);
166
+ if (subtree) {
167
+ subtree->children ().clear ();
168
+ subtree->value ().reset ();
169
+ }
170
+ }
171
+ }
172
+
136
173
bool CompoundWrite::HasCompleteWrite (const Path& path) const {
137
174
return GetCompleteVariant (path).has_value ();
138
175
}
0 commit comments