#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 requires CConvertibleFromAttributeValue T TErrorAttributes::Get(TStringBuf key) const { auto value = GetValue(key); try { return NYT::FromErrorAttributeValue(value); } catch (const std::exception& ex) { ThrowCannotParseAttributeException(key, ex); } } template requires CConvertibleFromAttributeValue typename TOptionalTraits::TOptional TErrorAttributes::Find(TStringBuf key) const { auto value = FindValue(key); if (!value) { return typename TOptionalTraits::TOptional(); } try { return NYT::FromErrorAttributeValue(*value); } catch (const std::exception& ex) { ThrowCannotParseAttributeException(key, ex); } } template requires CConvertibleFromAttributeValue T TErrorAttributes::GetAndRemove(const TKey& key) { auto result = Get(key); Remove(key); return result; } template requires CConvertibleFromAttributeValue T TErrorAttributes::Get(TStringBuf key, const T& defaultValue) const { return Find(key).value_or(defaultValue); } template requires CConvertibleFromAttributeValue T TErrorAttributes::GetAndRemove(const TKey& key, const T& defaultValue) { auto value = Find(key); if (value) { Remove(key); return *value; } else { return defaultValue; } } template requires CConvertibleFromAttributeValue typename TOptionalTraits::TOptional TErrorAttributes::FindAndRemove(const TKey& key) { auto value = Find(key); if (value) { Remove(key); } return value; } template void TErrorAttributes::MergeFrom(const TDictionary& dict) { for (auto range = AsMergeableRange(dict); const auto& [key, value] : range) { SetValue(key, value); } } //////////////////////////////////////////////////////////////////////////////// namespace NMergeableRangeImpl { inline TMergeableRange TagInvoke(TTagInvokeTag, const TErrorAttributes& attributes) { return attributes.ListPairs(); } } // namespace NMergeableRangeImpl static_assert(CMergeableDictionary); //////////////////////////////////////////////////////////////////////////////// } // namespace NYT