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__));
20 namespace lfbstream_detail {
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));
102 Buffer& buf() {
return buffer_;}
103 Buffer
const & buf()
const {
return buffer_;}
105 template <
typename ...Args>
106 ThisT& operator()(Args&&... args) {
107 auto sz =
sizeof...(Args);
108 auto it = buffer_.claim(sz);
109 stream(it, std::forward<Args>(args)...);
110 buffer_.commit(it, sz);
114 template <
typename Message>
115 static void dump(std::ostream& os, Message& m,
bool callStreamableDtor =
true) {
116 auto ptr =
reinterpret_cast<Streamable*
>(m.payload);
118 if (callStreamableDtor) ptr->~Streamable();
122 template <
typename Arg,
typename ...Args>
123 void stream(
typename Buffer::iterator it, Arg&& arg, Args&&... args) {
125 static_assert(
sizeof(Actual) <= PAYLOAD_SIZE,
"one of item too big");
126 auto ptr =
static_cast<BufferItem*
>(*it);
127 ptr->typeTag = STREAMABLE_TYPE_TAG;
128 new (&ptr->payload) Actual(std::forward<Arg>(arg));
129 stream(++it, std::forward<Args>(args)...);
131 void stream(
typename Buffer::iterator) {}
Definition: LfbStream.hpp:23
Definition: LfbStream.hpp:15
Definition: LfbStream.hpp:82