Permalink
Browse files

Converting TextMapReader callback to functor (#2)

* Update tracer.h

* Update tracer.cc

* Update tracer.h

* Update tracer.h

* Update opentracing.t.cc
  • Loading branch information...
1 parent 8b1efd1 commit e0ea9ebc67664f4961d9cef1a5dfcdf2ddd045d7 @lookfwd lookfwd committed on GitHub Dec 3, 2016
Showing with 20 additions and 4 deletions.
  1. +4 −0 opentracing/tracer.cc
  2. +15 −3 opentracing/tracer.h
  3. +1 −1 test/opentracing.t.cc
@@ -58,6 +58,10 @@ TextMapReader::~TextMapReader()
{
}
+TextMapReader::ReadCallback::~ReadCallback()
+{
+}
+
namespace {
class NoopSpan : public virtual Span
View
@@ -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;
};
/**
@@ -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)
{

0 comments on commit e0ea9eb

Please sign in to comment.