blob: a05e62d0e9125e3ef20a364ea06e00fbb2c2b348 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#ifndef ERROR_ATTRIBUTES_INL_H_
#error "Direct inclusion of this file is not allowed, include error_attributes.h"
// For the sake of sane code completion.
#include "error_attributes.h"
#endif
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
template <class T>
T TErrorAttributes::GetAndRemove(const TString& key)
{
auto result = Get<T>(key);
Remove(key);
return result;
}
template <class T>
T TErrorAttributes::Get(TStringBuf key, const T& defaultValue) const
{
return Find<T>(key).value_or(defaultValue);
}
template <class T>
T TErrorAttributes::GetAndRemove(const TString& key, const T& defaultValue)
{
auto result = Find<T>(key);
if (result) {
Remove(key);
return *result;
} else {
return defaultValue;
}
}
template <class T>
typename TOptionalTraits<T>::TOptional TErrorAttributes::FindAndRemove(const TString& key)
{
auto result = Find<T>(key);
if (result) {
Remove(key);
}
return result;
}
template <CMergeableDictionary TDictionary>
void TErrorAttributes::MergeFrom(const TDictionary& dict)
{
using TTraits = TMergeDictionariesTraits<TDictionary>;
for (const auto& [key, value] : TTraits::MakeIterableView(dict)) {
SetYson(key, value);
}
}
////////////////////////////////////////////////////////////////////////////////
template <>
struct TMergeDictionariesTraits<TErrorAttributes>
{
static auto MakeIterableView(const TErrorAttributes& attributes)
{
return attributes.ListPairs();
}
};
static_assert(CMergeableDictionary<TErrorAttributes>);
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|