map.hpp

00001 /*
00002 This file is part of GraphLab.
00003 
00004 GraphLab is free software: you can redistribute it and/or modify
00005 it under the terms of the GNU Lesser General Public License as 
00006 published by the Free Software Foundation, either version 3 of 
00007 the License, or (at your option) any later version.
00008 
00009 GraphLab is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU Lesser General Public License for more details.
00013 
00014 You should have received a copy of the GNU Lesser General Public 
00015 License along with GraphLab.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #ifndef GRAPHLAB_SERIALIZE_MAP_HPP
00019 #define GRAPHLAB_SERIALIZE_MAP_HPP
00020 
00021 #include <map>
00022 #include <graphlab/serialization/iarchive.hpp>
00023 #include <graphlab/serialization/oarchive.hpp>
00024 #include <graphlab/serialization/iterator.hpp>
00025 
00026 namespace graphlab {
00027 
00028 namespace archive_detail {
00029   /** Serializes a map */
00030   template <typename ArcType, typename T, typename U>
00031   struct serialize_impl<ArcType, std::map<T,U>, false > {
00032   static void exec(ArcType& a, const std::map<T,U>& vec){
00033     serialize_iterator(a,vec.begin(),vec.end(), vec.size());
00034   }
00035   };
00036 
00037   /** deserializes a map  */
00038       
00039   template <typename ArcType, typename T, typename U>
00040   struct deserialize_impl<ArcType, std::map<T,U>, false > {
00041   static void exec(ArcType& a, std::map<T,U>& vec){
00042     vec.clear();
00043     deserialize_iterator<ArcType, std::pair<T,U> >(a, std::inserter(vec,vec.end()));
00044   }
00045   };
00046 
00047 } // archive_detail  
00048 } // graphlab
00049 #endif 
00050