Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Converting TextMapReader callback to functor #2

Merged
merged 5 commits into from
Dec 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions opentracing/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ TextMapReader::~TextMapReader()
{
}

TextMapReader::ReadCallback::~ReadCallback()
{
}

namespace {

class NoopSpan : public virtual Span
Expand Down
18 changes: 15 additions & 3 deletions opentracing/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,26 @@ class TextMapReader : public virtual Reader
virtual ~TextMapReader();

/**
* The type of callback which will be called for each key.
* Callback functor typically implemented from the tracer in order to retrieve
* key-value pairs from the `TextMapReader`.
*/
typedef void (*PairReadCallback)(const std::string& key, const std::string& value, bool isBaggage);
struct ReadCallback
{
/**
* Destroys this ReadCallback.
*/
virtual ~ReadCallback();

/**
* Will be called for each key-value pair.
*/
virtual void operator() (const std::string& key, const std::string& value, bool isBaggage) const = 0;
};

/**
* Reads from the carrier and calls the `callback()` for each key-value pair.
*/
virtual void forEachPair(const PairReadCallback & callback) const = 0;
virtual void forEachPair(const ReadCallback & callback) const = 0;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion test/opentracing.t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class MapTextAdapter : public TextMapWriter, public TextMapReader
m_carrier.insert(typename T::value_type(key, std::make_pair(value, isBaggage)));
}

virtual void forEachPair(const PairReadCallback & callback) const
virtual void forEachPair(const ReadCallback & callback) const
{
for (typename T::const_iterator i = m_carrier.begin(); i != m_carrier.end(); ++i)
{
Expand Down