NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/sdk/common/circular_buffer_range.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 <cassert>
8 #include <type_traits>
9 
10 #include "opentelemetry/nostd/span.h"
11 #include "opentelemetry/version.h"
12 
14 namespace sdk
15 {
16 namespace common
17 {
21 template <class T>
23 {
24 public:
25  CircularBufferRange() noexcept = default;
26 
27  explicit CircularBufferRange(nostd::span<T> first) noexcept : first_{first} {}
28 
30  : first_{first}, second_{second}
31  {}
32 
33  operator CircularBufferRange<const T>() const noexcept { return {first_, second_}; }
34 
40  template <class Callback>
41  bool ForEach(Callback callback) const
42  noexcept(noexcept(std::declval<Callback>()(std::declval<T &>())))
43  {
44  for (auto &value : first_)
45  {
46  if (!callback(value))
47  {
48  return false;
49  }
50  }
51  for (auto &value : second_)
52  {
53  if (!callback(value))
54  {
55  return false;
56  }
57  }
58  return true;
59  }
60 
64  size_t size() const noexcept { return first_.size() + second_.size(); }
65 
69  bool empty() const noexcept { return first_.empty(); }
70 
76  CircularBufferRange Take(size_t n) const noexcept
77  {
78  assert(n <= size());
79  if (first_.size() >= n)
80  {
81  return CircularBufferRange{nostd::span<T>{first_.data(), n}};
82  }
83  return {first_, nostd::span<T>{second_.data(), n - first_.size()}};
84  }
85 
86 private:
87  nostd::span<T> first_;
88  nostd::span<T> second_;
89 };
90 } // namespace common
91 } // namespace sdk
sdk::common::CircularBufferRange::Take
CircularBufferRange Take(size_t n) const noexcept
Return a subrange taken from the start of this range.
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:76
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
nostd::span< T >
nostd::span::data
T * data() const noexcept
Definition: includes/opentelemetry/nostd/span.h:172
sdk::common::CircularBufferRange::CircularBufferRange
CircularBufferRange(nostd::span< T > first) noexcept
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:27
nostd::span::size
size_t size() const noexcept
Definition: includes/opentelemetry/nostd/span.h:174
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
nostd::span::empty
bool empty() const noexcept
Definition: includes/opentelemetry/nostd/span.h:170
sdk
Definition: includes/opentelemetry/sdk/common/atomic_shared_ptr.h:13
sdk::common::CircularBufferRange::CircularBufferRange
CircularBufferRange(nostd::span< T > first, nostd::span< T > second) noexcept
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:29
sdk::common::CircularBufferRange::ForEach
bool ForEach(Callback callback) const noexcept(noexcept(std::declval< Callback >()(std::declval< T & >())))
Iterate over the elements in the range.
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:41
sdk::common::CircularBufferRange::CircularBufferRange
CircularBufferRange() noexcept=default
sdk::common::CircularBufferRange::size
size_t size() const noexcept
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:64
sdk::common::CircularBufferRange::empty
bool empty() const noexcept
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:69
common
Definition: includes/opentelemetry/common/attribute_value.h:14
sdk::common::CircularBufferRange
A non-owning view into a range of elements in a circular buffer.
Definition: includes/opentelemetry/sdk/common/circular_buffer_range.h:22