adding map and multimap

This commit is contained in:
Awesome Robot
2013-06-13 17:04:02 -07:00
parent 80d0d4ab05
commit 1f5cc9f8b0
4 changed files with 78 additions and 6 deletions

72
binary_archive/map.hpp Normal file
View File

@@ -0,0 +1,72 @@
#ifndef CEREAL_BINARY_ARCHIVE_MAP_HPP_
#define CEREAL_BINARY_ARCHIVE_MAP_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <map>
namespace cereal
{
//! Saving for std::map all other types to binary
template <class K, class T, class C, class A>
void save( BinaryOutputArchive & ar, std::map<K, T, C, A> const & map )
{
ar & map.size();
for( const auto & i : map )
{
ar & i.first;
ar & i.second;
}
}
//! Loading for std::map all other types to binary
template <class K, class T, class C, class A>
void load( BinaryInputArchive & ar, std::map<K, T, C, A> & map )
{
size_t size;
ar & size;
for( size_t i = 0; i < size; ++i )
{
K key;
T value;
ar & key;
ar & value;
map.insert( {key, value} );
}
}
//! Saving for std::multimap all other types to binary
template <class K, class T, class C, class A>
void save( BinaryOutputArchive & ar, std::multimap<K, T, C, A> const & multimap )
{
ar & multimap.size();
for( const auto & i : multimap )
{
ar & i.first;
ar & i.second;
}
}
//! Loading for std::multimap all other types to binary
template <class K, class T, class C, class A>
void load( BinaryInputArchive & ar, std::multimap<K, T, C, A> & multimap )
{
size_t size;
ar & size;
for( size_t i = 0; i < size; ++i )
{
K key;
T value;
ar & key;
ar & value;
multimap.insert( {key, value} );
}
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_MAP_HPP_