1 #include "hmbdc/Copyright.hpp" 3 #include "hmbdc/Exception.hpp" 11 namespace hmbdc {
namespace text {
13 namespace lfb_stream {
16 virtual void dump(std::ostream& os)
const = 0;
18 } __attribute__ ((__may_alias__));
22 template <u
int32_t SIZE_LIMIT,
typename T>
26 : payload(std::forward<T>(m)){}
27 typename std::remove_reference<T>::type payload;
28 virtual void dump(std::ostream& os)
const {os << payload;}
29 }__attribute__ ((__may_alias__));
31 template<u
int32_t SIZE_LIMIT, std::
size_t N >
39 virtual void dump(std::ostream& os)
const {os << payload;}
40 }__attribute__ ((__may_alias__));
42 template<u
int32_t SIZE_LIMIT, std::
size_t N >
50 virtual void dump(std::ostream& os)
const {os << payload;}
51 }__attribute__ ((__may_alias__));
53 template<u
int32_t SIZE_LIMIT, std::
size_t N >
60 strncpy(payload, s,
sizeof(payload));
61 payload[
sizeof(payload) - 1] = 0;
63 virtual void dump(std::ostream& os)
const {os << payload;}
64 }__attribute__ ((__may_alias__));
66 template <u
int32_t SIZE_LIMIT>
73 strncpy(payload, m,
sizeof(payload));
74 payload[
sizeof(payload) - 1] = 0;
76 virtual void dump(std::ostream& os)
const {os << payload;}
77 }__attribute__ ((__may_alias__));
81 template <
typename Buffer,
typename BufferItem, u
int32_t STREAMABLE_TYPE_TAG>
85 using BufItem =
typename Buffer::value_type;
87 PAYLOAD_SIZE =
sizeof(BufferItem::payload),
94 if (q.maxItemSize() <
sizeof(BufferItem)) {
95 HMBDC_THROW(std::out_of_range,
96 "buffer not able to hold item " << q.maxItemSize() <<
'<' <<
sizeof(BufferItem));
100 Buffer& buf() {
return buffer_;}
101 Buffer
const & buf()
const {
return buffer_;}
103 template <
typename ...Args>
104 ThisT& operator()(Args&&... args) {
105 auto sz =
sizeof...(Args);
106 auto it = buffer_.claim(sz);
107 stream(it, std::forward<Args>(args)...);
108 buffer_.commit(it, sz);
112 template <
typename Message>
113 static void dump(std::ostream& os, Message& m,
bool callStreamableDtor =
true) {
114 auto ptr =
reinterpret_cast<Streamable*
>(m.payload);
116 if (callStreamableDtor) ptr->~Streamable();
120 template <
typename Arg,
typename ...Args>
121 void stream(
typename Buffer::iterator it, Arg&& arg, Args&&... args) {
123 static_assert(
sizeof(Actual) <= PAYLOAD_SIZE,
"one of item too big");
124 auto ptr =
static_cast<BufferItem*
>(*it);
125 ptr->typeTag = STREAMABLE_TYPE_TAG;
126 new (&ptr->payload) Actual(std::forward<Arg>(arg));
127 stream(++it, std::forward<Args>(args)...);
129 void stream(
typename Buffer::iterator) {}
Definition: LfbStream.hpp:15
Definition: LfbStream.hpp:82
Definition: LfbStream.hpp:23
Definition: Client.hpp:11