19 #ifndef OMNI_SERIALIZATION_CONTAINER_H_
20 #define OMNI_SERIALIZATION_CONTAINER_H_
31 namespace serialization {
34 template<
typename T,
size_t N>
35 struct Read<std::array<T, N>, false>{
36 template<
typename STREAM,
typename OBJ>
38 for (
size_t i = 0; i < N; ++i) {
39 _obj[i] = deserializeReturn<T>(_stream);
45 template<
typename T,
typename ALLOCATOR>
46 struct Read<std::vector<T, ALLOCATOR>, false>{
47 template<
typename STREAM,
typename OBJ>
49 uint32_t _size = deserializeReturn<uint32_t>(_stream, 0);
53 for (uint32_t i = 0; i < _size; ++i) {
54 _obj.push_back(deserializeReturn<T>(_stream));
61 template<
typename T,
typename ALLOCATOR>
62 struct Read<std::deque<T, ALLOCATOR>, false>:
63 Read<std::vector<T, ALLOCATOR> >{};
66 template<
typename T,
typename ALLOCATOR>
67 struct Read<std::list<T, ALLOCATOR>, false>:
68 Read<std::vector<T, ALLOCATOR> >{};
71 template<
typename T,
typename SORT,
typename ALLOCATOR>
72 struct Read<std::set<T, SORT, ALLOCATOR>, false>{
73 template<
typename STREAM,
typename OBJ>
75 uint32_t _size = deserializeReturn<uint32_t>(_stream, 0);
79 for (uint32_t i = 0; i < _size; ++i) {
80 _obj.insert(deserializeReturn<T>(_stream));
87 template<
typename KEY,
typename T,
typename COMPARE,
typename ALLOCATOR>
88 struct Read<std::map<KEY, T, COMPARE, ALLOCATOR>, false>{
89 template<
typename STREAM,
typename OBJ>
91 uint32_t _size = deserializeReturn<uint32_t>(_stream, 0);
95 for (uint32_t i = 0; i < _size; ++i) {
96 KEY && _key = deserializeReturn<KEY>(_stream);
97 T && _value = deserializeReturn<T>(_stream);
105 template<
typename T,
size_t N>
106 struct Write<std::array<T, N>, false>{
107 template<
typename STREAM,
typename OBJ>
109 for (
size_t i = 0; i < N; ++i) {
117 template<
typename T,
typename ALLOCATOR>
118 struct Write<std::vector<T, ALLOCATOR>, false>{
119 template<
typename STREAM,
typename OBJ>
121 serialize(_stream, uint32_t(_obj.size()));
123 for (
auto& _element : _obj) {
131 template<
typename T,
typename ALLOCATOR>
132 struct Write<std::deque<T, ALLOCATOR>, false>:
133 Write<std::vector<T, ALLOCATOR>, false>{};
136 template<
typename T,
typename ALLOCATOR>
137 struct Write<std::list<T, ALLOCATOR>, false>:
138 Write<std::vector<T, ALLOCATOR>, false>{};
141 template<
typename T,
typename SORT,
typename ALLOCATOR>
142 struct Write<std::set<T, SORT, ALLOCATOR>, false>:
143 Write<std::vector<T, ALLOCATOR>, false>{};
146 template<
typename KEY,
typename T,
typename COMPARE,
typename ALLOCATOR>
147 struct Write<std::map<KEY, T, COMPARE, ALLOCATOR>, false>{
148 template<
typename STREAM,
typename OBJ>
150 serialize(_stream, uint32_t(_obj.size()));
152 for (
auto& _keyValue : _obj) {
STREAM & operator()(STREAM &_stream, OBJ const &_obj)
Definition: container.h:149
STREAM & operator()(STREAM &_stream, OBJ const &_obj)
Definition: container.h:120
STREAM & operator()(STREAM &_stream, OBJ const &_obj)
Definition: container.h:108
STREAM & operator()(STREAM &_stream, OBJ &_obj)
Definition: container.h:90
STREAM & serialize(STREAM &_stream, T const &_t)
Serialize object to stream.
Definition: traits.h:140
STREAM & operator()(STREAM &_stream, OBJ &_obj)
Definition: container.h:48
Traits for reading a value from stream.
Definition: traits.h:34
STREAM & operator()(STREAM &_stream, OBJ &_obj)
Definition: container.h:37
STREAM & operator()(STREAM &_stream, OBJ &_obj)
Definition: container.h:74