userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
merge.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/formats/common/merge.hpp
4
/// @brief @copybrief formats::common::Merge
5
/// @ingroup userver_universal
6
7
#
include
<
userver
/
formats
/
common
/
items
.
hpp
>
8
9
USERVER_NAMESPACE_BEGIN
10
11
namespace
formats::common {
12
13
/// @brief Add to `original` new non-object elements from `patch` (overwriting
14
/// the old ones, if any) and merge object elements recursively.
15
/// @note For the missing `patch`, it does nothing with the `original`.
16
/// @note Arrays are not merged.
17
template
<
typename
Value>
18
void
Merge
(
typename
Value::Builder& original,
const
Value& patch) {
19
if
(patch.IsObject() && original.IsObject() && !original.IsEmpty()) {
20
for
(
const
auto
& [elem_key, elem_value] : common::Items(patch)) {
21
auto
next_origin = original[elem_key];
22
Merge(next_origin, elem_value);
23
}
24
}
else
if
(!patch.IsMissing()) {
25
original = patch;
26
}
27
}
28
29
}
// namespace formats::common
30
31
USERVER_NAMESPACE_END
userver
formats
common
merge.hpp
Generated on
for userver by
Doxygen
1.17.0