-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,828 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include "opentelemetry/common/attribute_value.h" | ||
#include "opentelemetry/nostd/function_ref.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace trace | ||
{ | ||
/** | ||
* Supports internal iteration over a collection of key-value pairs. | ||
*/ | ||
class KeyValueIterable | ||
{ | ||
public: | ||
virtual ~KeyValueIterable() = default; | ||
|
||
/** | ||
* Iterate over key-value pairs | ||
* @param callback a callback to invoke for each key-value. If the callback returns false, | ||
* the iteration is aborted. | ||
* @return true if every key-value pair was iterated over | ||
*/ | ||
virtual bool ForEachKeyValue(nostd::function_ref<bool(nostd::string_view, common::AttributeValue)> | ||
callback) const noexcept = 0; | ||
|
||
/** | ||
* @return the number of key-value pairs | ||
*/ | ||
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 trace | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
|
||
#include <iterator> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "opentelemetry/nostd/utility.h" | ||
#include "opentelemetry/trace/key_value_iterable.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace trace | ||
{ | ||
namespace detail | ||
{ | ||
inline void take_key_value(nostd::string_view, common::AttributeValue) {} | ||
|
||
template <class T> | ||
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{}); | ||
|
||
std::false_type is_key_value_iterable_impl(...); | ||
|
||
template <class T> | ||
struct is_key_value_iterable | ||
{ | ||
static const bool value = decltype(detail::is_key_value_iterable_impl(std::declval<T>()))::value; | ||
}; | ||
} // namespace detail | ||
|
||
template <class T> | ||
class KeyValueIterableView final : public KeyValueIterable | ||
{ | ||
#if 0 // TODO: [MG] - confirm if we really need this | ||
static_assert(detail::is_key_value_iterable<T>::value, "Must be a key-value iterable"); | ||
#endif | ||
|
||
public: | ||
explicit KeyValueIterableView(const T &container) noexcept : container_{&container} {}; | ||
|
||
// KeyValueIterable | ||
bool ForEachKeyValue(nostd::function_ref<bool(nostd::string_view, common::AttributeValue)> | ||
callback) const noexcept override | ||
{ | ||
auto iter = std::begin(*container_); | ||
auto last = std::end(*container_); | ||
for (; iter != last; ++iter) | ||
{ | ||
if (!callback(iter->first, iter->second)) | ||
{ | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
size_t size() const noexcept override { return nostd::size(*container_); } | ||
|
||
private: | ||
const T *container_; | ||
}; | ||
} // namespace trace | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.