ZIO
Python and C++ interface to ZeroMQ and Zyre
outbox.hpp
Go to the documentation of this file.
1 #ifndef ZIO_OUTBOX_HPP_SEEN
2 #define ZIO_OUTBOX_HPP_SEEN
3 
4 #include "zio/message.hpp"
5 
6 #include <functional>
7 
8 namespace zio {
9 
21  template<typename NATIVE>
22  class Outbox {
23  public:
24  typedef NATIVE native_type;
25  typedef typename std::function<void(zio::level::MessageLevel lvl,
26  const native_type&)> sender_type;
27 
28  explicit Outbox(const sender_type& sender) : m_send(sender) { }
29  virtual ~Outbox() { }
30 
31  void operator()(level::MessageLevel lvl, const native_type& nat) {
32  send(lvl, nat);
33  }
34  virtual void send(level::MessageLevel lvl, const native_type& nat) {
35  m_send(lvl, nat);
36  }
37 
38  // bake levels semantics into method names
39  void trace(const native_type& nat)
40  { send(level::trace, nat); }
41  void verbose(const native_type& nat)
42  { send(level::verbose, nat); }
43  void debug(const native_type& nat)
44  { send(level::debug, nat); }
45  void info(const native_type& nat)
46  { send(level::info, nat); }
47  void summary(const native_type& nat)
48  { send(level::summary, nat); }
49  void warning(const native_type& nat)
50  { send(level::warning, nat); }
51  void error(const native_type& nat)
52  { send(level::error, nat); }
53  void fatal(const native_type& nat)
54  { send(level::fatal, nat); }
55 
56  private:
57  sender_type m_send;
58  };
59 
66 
69 
70 }
71 
72 #endif
NATIVE native_type
Definition: outbox.hpp:24
void error(const native_type &nat)
Definition: outbox.hpp:51
virtual void send(level::MessageLevel lvl, const native_type &nat)
Definition: outbox.hpp:34
Outbox< zio::json > Metric
Emit structured data.
Definition: outbox.hpp:68
void trace(const native_type &nat)
Definition: outbox.hpp:39
void info(const native_type &nat)
Definition: outbox.hpp:45
void verbose(const native_type &nat)
Definition: outbox.hpp:41
virtual ~Outbox()
Definition: outbox.hpp:29
Outbox(const sender_type &sender)
Definition: outbox.hpp:28
void debug(const native_type &nat)
Definition: outbox.hpp:43
std::function< void(zio::level::MessageLevel lvl, const native_type &)> sender_type
Definition: outbox.hpp:26
void fatal(const native_type &nat)
Definition: outbox.hpp:53
Outbox< std::string > Logger
two special types of outboxes.
Definition: outbox.hpp:65
void warning(const native_type &nat)
Definition: outbox.hpp:49
void summary(const native_type &nat)
Definition: outbox.hpp:47
implementation of ZIO data flow protocol endpoints
Definition: actor.hpp:14
output objects of a fixed native type with levels expressed as methods.
Definition: outbox.hpp:22
void operator()(level::MessageLevel lvl, const native_type &nat)
Definition: outbox.hpp:31