6 #ifndef TURI_SERIALIZE_VECTOR_HPP 7 #define TURI_SERIALIZE_VECTOR_HPP 9 #include <core/storage/serialization/iarchive.hpp> 10 #include <core/storage/serialization/oarchive.hpp> 11 #include <core/storage/serialization/iterator.hpp> 15 namespace archive_detail {
20 template <
typename OutArcType,
typename ValueType,
bool IsPOD>
21 struct vector_serialize_impl {
22 static void exec(OutArcType& oarc,
const ValueType& vec) {
25 BOOST_STATIC_ASSERT(
sizeof(OutArcType) == 0);
33 template <
typename InArcType,
typename ValueType,
bool IsPOD>
34 struct vector_deserialize_impl {
35 static void exec(InArcType& iarc, ValueType& vec) {
38 BOOST_STATIC_ASSERT(
sizeof(InArcType) == 0);
44 template <
typename OutArcType,
typename ValueType>
45 struct vector_serialize_impl<OutArcType, ValueType, false > {
46 static void exec(OutArcType& oarc,
const std::vector<ValueType>& vec) {
47 oarc << size_t(vec.size());
48 for (
size_t i = 0;i < vec.size(); ++i) {
55 template <
typename OutArcType,
typename ValueType>
56 struct vector_serialize_impl<OutArcType, ValueType, true > {
57 static void exec(OutArcType& oarc,
const std::vector<ValueType>& vec) {
58 oarc << size_t(vec.size());
59 serialize(oarc, vec.data(),
sizeof(ValueType)*vec.size());
64 template <
typename InArcType,
typename ValueType>
65 struct vector_deserialize_impl<InArcType, ValueType, false > {
66 static void exec(InArcType& iarc, std::vector<ValueType>& vec){
69 vec.clear(); vec.resize(len);
70 for (
size_t i = 0;i < len; ++i) {
77 template <
typename InArcType,
typename ValueType>
78 struct vector_deserialize_impl<InArcType, ValueType, true > {
79 static void exec(InArcType& iarc, std::vector<ValueType>& vec){
82 vec.clear(); vec.resize(len);
83 deserialize(iarc, vec.data(),
sizeof(ValueType)*vec.size());
91 template <
typename OutArcType,
typename ValueType>
92 struct serialize_impl<OutArcType,
std::vector<ValueType>, false > {
93 static void exec(OutArcType& oarc,
const std::vector<ValueType>& vec) {
94 vector_serialize_impl<OutArcType, ValueType,
95 gl_is_pod_or_scaler<ValueType>::value >::exec(oarc, vec);
100 template <
typename InArcType,
typename ValueType>
101 struct deserialize_impl<InArcType,
std::vector<ValueType>, false > {
102 static void exec(InArcType& iarc, std::vector<ValueType>& vec){
103 vector_deserialize_impl<InArcType, ValueType,
104 gl_is_pod_or_scaler<ValueType>::value >::exec(iarc, vec);