43 #define SERIALIZERST_CC
45 #include "Serializers.hh"
61 template <
typename Stream,
typename T>
65 template<
class U>
static true_type
test(
char(*)[
sizeof(decllval<Stream>() >> decllval<U>(),
void(), 0)]);
66 template<
class U>
static false_type test(...);
69 enum { bool_value =
sizeof(true_type) ==
sizeof(
test<T>(0)) };
74 template <
typename Stream,
typename T>
78 template <
typename Stream,
typename T>
82 template<
class U>
static true_type test(
char(*)[
sizeof(decllval<Stream>() << decllval<U>(),
void(), 0)]);
83 template<
class U>
static false_type test(...);
86 enum { bool_value =
sizeof(true_type) ==
sizeof(
test<T>(0)) };
91 template <
typename Stream,
typename T>
95 template <
typename ValueT>
96 std::ostream& serialize_helper(std::ostream& _ostr, ValueT& _rhs, true_type)
102 template <
typename ValueT>
103 std::ostream& serialize_helper(std::ostream& _ostr, ValueT&, false_type)
105 std::cout <<
"Warning: trying to serialize a type that does not have a serialize function" << std::endl;
109 template <
typename ValueT>
110 std::ostream& serialize(std::ostream& _ostr,
const ValueT& _rhs)
116 template <
typename ValueT>
117 std::istream& deserialize_helper(std::istream& _istr, ValueT& _rhs, true_type)
123 template <
typename ValueT>
124 std::istream& deserialize_helper(std::istream& _istr, ValueT&, false_type)
126 std::cout <<
"Warning: trying to deserialize a type that does not have a deserialize function" << std::endl;
130 template <
typename ValueT>
131 std::istream& deserialize(std::istream& _istr, ValueT& _rhs)
136 template <
typename KeyT,
typename ValueT>
137 std::ostream& serialize(std::ostream& os,
const std::map< KeyT, ValueT >& rhs)
139 os << rhs.size() << std::endl;
140 for (
typename std::map< KeyT, ValueT >::const_iterator it = rhs.begin();
144 serialize(os,it->first) << std::endl;
145 serialize(os, it->second) << std::endl;
151 template <
typename KeyT,
typename ValueT>
152 std::istream& deserialize(std::istream& is, std::map< KeyT, ValueT >& rhs)
158 for (
size_t i=0; i<size; i++)
162 deserialize(is, key);
163 deserialize(is, value);
170 template <
typename ValueT>
171 std::ostream& serialize(std::ostream& _ostr,
const std::vector< ValueT >& _rhs)
173 _ostr << _rhs.size() << std::endl;
174 for (
size_t i = 0; i < _rhs.size(); ++i)
175 serialize(_ostr, _rhs[i]) << std::endl;
179 template <
typename ValueT>
180 std::istream& deserialize(std::istream& _istr, std::vector< ValueT >& _rhs)
185 for (
size_t i=0; i<size; i++)
186 deserialize(_istr,_rhs[i]);