19#ifndef OST_IO_BINARY_DATA_SOURCE_HH
20#define OST_IO_BINARY_DATA_SOURCE_HH
28#include <boost/type_traits/is_floating_point.hpp>
29#include <boost/type_traits/is_integral.hpp>
32namespace ost {
namespace io {
39 template <
typename SERIALIZABLE>
44 template <
typename SERIALIZABLE>
54 std::istream& stream_;
59template <
bool B,
typename T>
60struct SerializeHelper;
63struct SerializeHelper<false, T> {
64 SerializeHelper(BinaryDataSource& source, T& value)
66 value.Serialize(source);
71struct SerializeHelper<true, T> {
72 SerializeHelper(BinaryDataSource& source, T& value)
74 source.Stream().read(
reinterpret_cast<char*
>(&value),
sizeof(T));
82 detail::SerializeHelper<boost::is_integral<T>::value ||
83 boost::is_floating_point<T>::value,
88 char* value,
size_t size)
90 sink.
Stream().read(value, size);
95 static char tmp_buf[1024];
97 source.
Stream().read(
reinterpret_cast<char*
>(&str_len),
sizeof(
size_t));
98 source.
Stream().read(tmp_buf, str_len);
99 str.reserve(str_len+1);
100 str.assign(tmp_buf, str_len);
BinaryDataSource & operator&(SERIALIZABLE &object)
BinaryDataSource(std::istream &stream)
BinaryDataSource & operator>>(SERIALIZABLE &object)
void Serialize(BinaryDataSink &sink, const T &value)
void RawSerialize(BinaryDataSink &sink, char *value, size_t size)