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

Commit

Permalink
Converting TextMapReader callback to functor (#2)
Browse files Browse the repository at this point in the history
* Update tracer.h

* Update tracer.cc

* Update tracer.h

* Update tracer.h

* Update opentracing.t.cc
  • Loading branch information
lookfwd authored Dec 3, 2016
1 parent 8b1efd1 commit e0ea9eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
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

0 comments on commit e0ea9eb

Please sign in to comment.