From b196c6498d22e47bb9d0da0153068ec54eac7956 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:44:33 +0200 Subject: Adding upstream version 1.6.0. Signed-off-by: Daniel Baumann --- example/tutorial/text_map_carrier.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 example/tutorial/text_map_carrier.h (limited to 'example/tutorial/text_map_carrier.h') diff --git a/example/tutorial/text_map_carrier.h b/example/tutorial/text_map_carrier.h new file mode 100644 index 0000000..2538324 --- /dev/null +++ b/example/tutorial/text_map_carrier.h @@ -0,0 +1,37 @@ +#ifndef LIGHTSTEP_TEXT_MAP_CARRIER +#define LIGHTSTEP_TEXT_MAP_CARRIER + +#include +#include +#include + +using opentracing::expected; +using opentracing::string_view; +using opentracing::TextMapReader; +using opentracing::TextMapWriter; + +class TextMapCarrier : public TextMapReader, public TextMapWriter { + public: + TextMapCarrier(std::unordered_map& text_map) + : text_map_(text_map) {} + + expected Set(string_view key, string_view value) const override { + text_map_[key] = value; + return {}; + } + + expected ForeachKey( + std::function(string_view key, string_view value)> f) + const override { + for (const auto& key_value : text_map_) { + auto result = f(key_value.first, key_value.second); + if (!result) return result; + } + return {}; + } + + private: + std::unordered_map& text_map_; +}; + +#endif // LIGHTSTEP_TEXT_MAP_CARRIER -- cgit v1.2.3