diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:44:33 +0000 |
commit | b196c6498d22e47bb9d0da0153068ec54eac7956 (patch) | |
tree | 1a994a492581e93224a7ee6455f5d4e9d2ec8e59 /example/tutorial/text_map_carrier.h | |
parent | Initial commit. (diff) | |
download | opentracing-cpp-upstream.tar.xz opentracing-cpp-upstream.zip |
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'example/tutorial/text_map_carrier.h')
-rw-r--r-- | example/tutorial/text_map_carrier.h | 37 |
1 files changed, 37 insertions, 0 deletions
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 <opentracing/propagation.h> +#include <string> +#include <unordered_map> + +using opentracing::expected; +using opentracing::string_view; +using opentracing::TextMapReader; +using opentracing::TextMapWriter; + +class TextMapCarrier : public TextMapReader, public TextMapWriter { + public: + TextMapCarrier(std::unordered_map<std::string, std::string>& text_map) + : text_map_(text_map) {} + + expected<void> Set(string_view key, string_view value) const override { + text_map_[key] = value; + return {}; + } + + expected<void> ForeachKey( + std::function<expected<void>(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<std::string, std::string>& text_map_; +}; + +#endif // LIGHTSTEP_TEXT_MAP_CARRIER |