1 #ifndef VTESTBED_BASE_BSTREAM_HH 2 #define VTESTBED_BASE_BSTREAM_HH 10 #include <vtestbed/base/byte_order.hh> 12 #define VTB_PUT_GET(type) \ 13 inline bstream& operator<<(type rhs) { this->do_write(rhs); return *this; } \ 14 inline bstream& operator>>(type& rhs) { this->do_read(rhs); return *this; } 16 #define VTB_METHOD_TYPE(type, method) decltype(::std::declval<type>().method) 31 using char_type = char;
45 inline streambuf* rdbuf() {
return this->_buffer; }
46 inline const streambuf* rdbuf()
const {
return this->_buffer; }
55 inline void sync() { this->_buffer->pubsync(); }
56 inline void flush() { this->sync(); }
60 this->_buffer->sputn(s, n);
65 this->_buffer->sgetn(s, n);
75 template <
class Ch,
class Tr>
79 size_type size = static_cast<size_type>(rhs.size());
81 this->write(reinterpret_cast<const char_type*>(rhs.data()), size);
85 template <
class Ch,
class Tr>
92 this->read(reinterpret_cast<char_type*>(&rhs[0]), size);
98 operator<<(
const T& rhs) {
99 size_type s = std::distance(rhs.begin(), rhs.end());
101 size_type size = static_cast<size_type>(s);
102 this->do_write(size);
103 for (
const auto& value : rhs) { *
this << value; }
122 operator<<(
float rhs) {
123 this->do_write(static_cast<double>(rhs));
128 operator>>(
float& rhs) {
131 rhs = static_cast<float>(tmp);
157 this->write(u.bytes,
sizeof(T)*
sizeof(char_type));
167 this->read(u.bytes,
sizeof(T)*
sizeof(char_type));
183 typedef ::vtb::base::bstream
bstream;
190 #undef VTB_METHOD_TYPE 192 #endif // vim:filetype=cpp