ZIO
Python and C++ interface to ZeroMQ and Zyre
tens.hpp
Go to the documentation of this file.
1 
5 #ifndef ZIO_TENS_H_SEEN
6 #define ZIO_TENS_H_SEEN
7 
8 #include "zio/message.hpp"
9 
10 namespace zio {
11 
12  namespace tens {
13 
14  // The default message "form", if none set.
15  const char* form = "TENS";
16 
17  const char* type_name(const std::type_info& t);
18 
19  template<typename Type>
20  const char* dtype() { return type_name(typeid(Type)); }
21 
23  void append(Message& msg, message_t&& data,
24  const std::vector<size_t>& shape,
25  size_t word_size, const char* tn);
26 
33  template<typename ElementType>
34  void append(Message& msg, const ElementType* data, const std::vector<size_t>& shape) {
35  size_t nbytes = sizeof(ElementType);
36  size_t word = nbytes;
37  for (auto s : shape) { nbytes *= s; }
38  append(msg, zio::message_t((const void*)data, nbytes),
39  shape, word, type_name(typeid(ElementType)));
40  }
41 
49  const zio::message_t& at(const Message& msg, size_t index);
50 
57  template<typename ElementType>
58  const ElementType* at(const Message& msg, size_t index) {
59  const zio::message_t& ret = at(msg, index);
60  if (ret.empty()) { return nullptr; }
61  return (const ElementType*) ret.data();
62  }
63 
64  }
65 }
66 
67 #endif
const zio::message_t & at(const Message &msg, size_t index)
Definition: tens.hpp:58
const char * form
Definition: tens.hpp:15
ZMQ_NODISCARD bool empty() const ZMQ_NOTHROW
Definition: zmq.hpp:493
void * data() ZMQ_NOTHROW
Definition: zmq.hpp:481
const char * dtype()
Definition: tens.hpp:20
void append(Message &msg, message_t &&data, const std::vector< size_t > &shape, size_t word_size, const char *tn)
Definition: tens.cpp:34
a ZIO message
Definition: message.hpp:59
implementation of ZIO data flow protocol endpoints
Definition: actor.hpp:14
const char * type_name(const std::type_info &t)
Definition: tens.cpp:6