Turi Create  4.0
map.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_SERIALIZE_MAP_HPP
7 #define TURI_SERIALIZE_MAP_HPP
8 
9 #include <map>
10 #include <core/storage/serialization/iarchive.hpp>
11 #include <core/storage/serialization/oarchive.hpp>
12 #include <core/storage/serialization/iterator.hpp>
13 
14 namespace turi {
15 
16 namespace archive_detail {
17  /** Serializes a map */
18  template <typename OutArcType, typename T, typename U>
19  struct serialize_impl<OutArcType, std::map<T,U>, false > {
20  static void exec(OutArcType& oarc, const std::map<T,U>& vec){
21  serialize_iterator(oarc,
22  vec.begin(), vec.end(), vec.size());
23  }
24  };
25 
26  /** deserializes a map */
27 
28  template <typename InArcType, typename T, typename U>
29  struct deserialize_impl<InArcType, std::map<T,U>, false > {
30  static void exec(InArcType& iarc, std::map<T,U>& vec){
31  vec.clear();
32  deserialize_iterator<InArcType,
33  std::pair<T,U> >(iarc,
34  std::inserter(vec,vec.end()));
35  }
36  };
37 
38 } // archive_detail
39 } // turicreate
40 #endif
STL namespace.
void serialize_iterator(OutArcType &oarc, RandomAccessIterator begin, RandomAccessIterator end)
Serializes the contents between the iterators begin and end.
Definition: iterator.hpp:36
void deserialize_iterator(InArcType &iarc, OutputIterator result)
The accompanying function to serialize_iterator() Reads elements from the stream and writes it to the...
Definition: iterator.hpp:100