NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/common/key_value_iterable_view.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <stddef.h>
7 #include <initializer_list>
8 #include <iterator>
9 #include <type_traits>
10 #include <utility>
11 #include <vector>
12 
13 #include "opentelemetry/common/attribute_value.h"
14 #include "opentelemetry/common/key_value_iterable.h"
15 #include "opentelemetry/nostd/function_ref.h"
16 #include "opentelemetry/nostd/span.h"
17 #include "opentelemetry/nostd/string_view.h"
18 #include "opentelemetry/nostd/type_traits.h"
19 #include "opentelemetry/nostd/utility.h"
20 #include "opentelemetry/version.h"
21 
23 namespace common
24 {
25 // NOTE - code within `detail` namespace implements internal details, and not part
26 // of the public interface.
27 namespace detail
28 {
30 
31 template <class T>
33  -> decltype(take_key_value(std::begin(iterable)->first, std::begin(iterable)->second),
34  nostd::size(iterable),
35  std::true_type{});
36 
38 
39 template <class T>
41 {
42  static const bool value = decltype(detail::is_key_value_iterable_impl(std::declval<T>()))::value;
43 };
44 } // namespace detail
45 
56 template <class T>
58 {
59 
60 public:
61  explicit KeyValueIterableView(const T &container) noexcept : container_{&container} {}
62 
63  // KeyValueIterable
65  callback) const noexcept override
66  {
67  auto iter = std::begin(*container_);
68  auto last = std::end(*container_);
69  for (; iter != last; ++iter)
70  {
71  if (!callback(iter->first, iter->second))
72  {
73  return false;
74  }
75  }
76  return true;
77  }
78 
79  size_t size() const noexcept override { return nostd::size(*container_); }
80 
81 private:
82  const T *container_;
83 };
84 
85 template <class T, nostd::enable_if_t<detail::is_key_value_iterable<T>::value> * = nullptr>
87 {
88  return KeyValueIterableView<T>(container);
89 }
90 
98 MakeAttributes(std::initializer_list<std::pair<nostd::string_view, common::AttributeValue>>
99  attributes) noexcept
100 {
102  attributes.begin(), attributes.end()};
103 }
104 
113  nostd::span<const std::pair<nostd::string_view, common::AttributeValue>> attributes) noexcept
114 {
115  return attributes;
116 }
117 
125  const common::KeyValueIterable &attributes) noexcept
126 {
127  return attributes;
128 }
129 
137 template <
138  class ArgumentType,
141  const ArgumentType &attributes) noexcept
142 {
144 }
145 
146 } // namespace common
half_float::detail::false_type
bool_type< false > false_type
Definition: includes/half.hpp:489
nostd::function_ref
Definition: includes/opentelemetry/nostd/function_ref.h:17
common::KeyValueIterableView::size
size_t size() const noexcept override
Definition: includes/opentelemetry/common/key_value_iterable_view.h:79
absl::OTABSL_OPTION_NAMESPACE_NAME::variant
Definition: includes/opentelemetry/nostd/variant.h:61
common::detail::is_key_value_iterable_impl
auto is_key_value_iterable_impl(T iterable) -> decltype(take_key_value(std::begin(iterable) ->first, std::begin(iterable) ->second), nostd::size(iterable), std::true_type
Definition: includes/opentelemetry/common/key_value_iterable_view.h:32
common::detail::take_key_value
void take_key_value(nostd::string_view, common::AttributeValue)
Definition: includes/opentelemetry/common/key_value_iterable_view.h:29
common::KeyValueIterableView::ForEachKeyValue
bool ForEachKeyValue(nostd::function_ref< bool(nostd::string_view, common::AttributeValue)> callback) const noexcept override
Definition: includes/opentelemetry/common/key_value_iterable_view.h:64
nostd::span::begin
T * begin() const noexcept
Definition: includes/opentelemetry/nostd/span.h:182
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
nostd::span
Back port of std::span.
Definition: includes/opentelemetry/nostd/span.h:51
common::detail::is_key_value_iterable::value
static const bool value
Definition: includes/opentelemetry/common/key_value_iterable_view.h:42
common::KeyValueIterableView::KeyValueIterableView
KeyValueIterableView(const T &container) noexcept
Definition: includes/opentelemetry/common/key_value_iterable_view.h:61
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
common::KeyValueIterable
Supports internal iteration over a collection of key-value pairs.
Definition: includes/opentelemetry/common/key_value_iterable.h:17
half_float::detail::true_type
bool_type< true > true_type
Definition: includes/half.hpp:488
nostd::size
auto size(const C &c) noexcept(noexcept(c.size())) -> decltype(c.size())
Back port of std::size.
Definition: includes/opentelemetry/nostd/utility.h:60
nostd::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Back port of std::enable_if_t.
Definition: includes/opentelemetry/nostd/type_traits.h:40
common::KeyValueIterableView
Container for key-value pairs that can transform every value in it to one of types listed in common::...
Definition: includes/opentelemetry/common/key_value_iterable_view.h:57
common::MakeAttributes
static nostd::span< const std::pair< nostd::string_view, common::AttributeValue > > MakeAttributes(std::initializer_list< std::pair< nostd::string_view, common::AttributeValue >> attributes) noexcept
Utility function to help to make a attribute view from initializer_list.
Definition: includes/opentelemetry/common/key_value_iterable_view.h:98
common::MakeKeyValueIterableView
KeyValueIterableView< T > MakeKeyValueIterableView(const T &container) noexcept
Definition: includes/opentelemetry/common/key_value_iterable_view.h:86
common::detail::is_key_value_iterable
Definition: includes/opentelemetry/common/key_value_iterable_view.h:40
common
Definition: includes/opentelemetry/common/attribute_value.h:14
pydeepstreamdoc::osd::ArrowHeadDoc::end
constexpr const char * end
Definition: service-maker/sources/python/src/bindings/docstrings/osddoc.h:34
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37