From 1f5cc9f8b091d1a952819fc1de7fbd0a7491570b Mon Sep 17 00:00:00 2001 From: Awesome Robot Date: Thu, 13 Jun 2013 17:04:02 -0700 Subject: [PATCH] adding map and multimap --- binary_archive/dequeue.hpp | 4 +- binary_archive/forward_list.hpp | 4 +- binary_archive/list.hpp | 4 +- binary_archive/map.hpp | 72 +++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 binary_archive/map.hpp diff --git a/binary_archive/dequeue.hpp b/binary_archive/dequeue.hpp index f8315609..fb1885ef 100644 --- a/binary_archive/dequeue.hpp +++ b/binary_archive/dequeue.hpp @@ -7,7 +7,7 @@ namespace cereal { //! Saving for std::deque all other types to binary - template + template void save( BinaryOutputArchive & ar, std::deque const & deque ) { ar & deque.size(); @@ -17,7 +17,7 @@ namespace cereal } //! Loading for std::deque all other types to binary - template + template void load( BinaryInputArchive & ar, std::deque & deque ) { size_t size; diff --git a/binary_archive/forward_list.hpp b/binary_archive/forward_list.hpp index 15483168..8b416e93 100644 --- a/binary_archive/forward_list.hpp +++ b/binary_archive/forward_list.hpp @@ -7,7 +7,7 @@ namespace cereal { //! Saving for std::forward_list all other types to binary - template + template void save( BinaryOutputArchive & ar, std::forward_list const & forward_list ) { ar & forward_list.size(); @@ -17,7 +17,7 @@ namespace cereal } //! Loading for std::forward_list all other types to binary - template + template void load( BinaryInputArchive & ar, std::forward_list & forward_list ) { size_t size; diff --git a/binary_archive/list.hpp b/binary_archive/list.hpp index 5ccfdb7e..1b95ee1b 100644 --- a/binary_archive/list.hpp +++ b/binary_archive/list.hpp @@ -7,7 +7,7 @@ namespace cereal { //! Saving for std::list all other types to binary - template + template void save( BinaryOutputArchive & ar, std::list const & list ) { ar & list.size(); @@ -17,7 +17,7 @@ namespace cereal } //! Loading for std::list all other types to binary - template + template void load( BinaryInputArchive & ar, std::list & list ) { size_t size; diff --git a/binary_archive/map.hpp b/binary_archive/map.hpp new file mode 100644 index 00000000..78e77053 --- /dev/null +++ b/binary_archive/map.hpp @@ -0,0 +1,72 @@ +#ifndef CEREAL_BINARY_ARCHIVE_MAP_HPP_ +#define CEREAL_BINARY_ARCHIVE_MAP_HPP_ + +#include +#include + +namespace cereal +{ + //! Saving for std::map all other types to binary + template + void save( BinaryOutputArchive & ar, std::map 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 + void load( BinaryInputArchive & ar, std::map & 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 + void save( BinaryOutputArchive & ar, std::multimap 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 + void load( BinaryInputArchive & ar, std::multimap & 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_