Program Listing for File key_value_iterable.h

Return to documentation for file (include/opentelemetry/common/key_value_iterable.h)

#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;
};

//
// NULL object pattern empty iterable.
//
class NullKeyValueIterable : public KeyValueIterable
{
public:
  NullKeyValueIterable(){};

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

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

}  // namespace common
OPENTELEMETRY_END_NAMESPACE