Program Listing for File key_value_iterable.h

Return to documentation for file (/home/docs/checkouts/readthedocs.org/user_builds/opentelemetry-cpp/checkouts/v1.8.3/api/include/opentelemetry/common/key_value_iterable.h)

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "opentelemetry/common/attribute_value.h"
#include "opentelemetry/nostd/function_ref.h"
#include "opentelemetry/version.h"

OPENTELEMETRY_BEGIN_NAMESPACE
namespace common
{
class KeyValueIterable
{
public:
  virtual ~KeyValueIterable() = default;

  virtual bool ForEachKeyValue(nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>
                                   callback) const noexcept = 0;

  virtual size_t size() const noexcept = 0;
};

class NoopKeyValueIterable : public KeyValueIterable
{
public:
  ~NoopKeyValueIterable() override = default;

  bool ForEachKeyValue(
      nostd::function_ref<bool(nostd::string_view, common::AttributeValue)>) const noexcept override
  {
    return true;
  }

  size_t size() const noexcept override { return 0; }
};

}  // namespace common
OPENTELEMETRY_END_NAMESPACE