From 3785c759c82d05c92ed928dceef701a91ce926fe Mon Sep 17 00:00:00 2001 From: Shane Grant Date: Fri, 14 Jun 2013 13:43:49 -0700 Subject: [PATCH] working on more stl functionality --- binary_archive/set.hpp | 62 +++++++++++++++++++++++++++++++ binary_archive/unordered_set.hpp | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 binary_archive/set.hpp create mode 100644 binary_archive/unordered_set.hpp diff --git a/binary_archive/set.hpp b/binary_archive/set.hpp new file mode 100644 index 00000000..ab6e79de --- /dev/null +++ b/binary_archive/set.hpp @@ -0,0 +1,62 @@ +#ifndef CEREAL_BINARY_ARCHIVE_SET_HPP_ +#define CEREAL_BINARY_ARCHIVE_SET_HPP_ + +#include +#include + +namespace cereal +{ + //! Saving for std::set all other types to binary + template + void save( BinaryOutputArchive & ar, std::set const & set ) + { + ar & set.size(); + + for( const auto & i : set ) + ar & i; + } + + //! Loading for std::set all other types to binary + template + void load( BinaryInputArchive & ar, std::set & set ) + { + size_t size; + ar & size; + + for( size_t i = 0; i < size; ++i ) + { + K key; + + ar & key; + set.insert( key ); + } + } + + //! Saving for std::multiset all other types to binary + template + void save( BinaryOutputArchive & ar, std::multiset const & multiset ) + { + ar & multiset.size(); + + for( const auto & i : multiset ) + ar & i; + } + + //! Loading for std::multiset all other types to binary + template + void load( BinaryInputArchive & ar, std::multiset & multiset ) + { + size_t size; + ar & size; + + for( size_t i = 0; i < size; ++i ) + { + K key; + + ar & key; + multiset.insert( key ); + } + } +} // namespace cereal + +#endif // CEREAL_BINARY_ARCHIVE_SET_HPP_ diff --git a/binary_archive/unordered_set.hpp b/binary_archive/unordered_set.hpp new file mode 100644 index 00000000..73ef8413 --- /dev/null +++ b/binary_archive/unordered_set.hpp @@ -0,0 +1,64 @@ +#ifndef CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_ +#define CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_ + +#include +#include + +namespace cereal +{ + //! Saving for std::unordered_set all other types to binary + template + void save( BinaryOutputArchive & ar, std::unordered_set const & unordered_set ) + { + ar & unordered_set.size(); + + for( const auto & i : unordered_set ) + ar & i; + } + + //! Loading for std::unordered_set all other types to binary + template + void load( BinaryInputArchive & ar, std::unordered_set & unordered_set ) + { + size_t size; + ar & size; + + unordered_set.reserve( size ); + + for( size_t i = 0; i < size; ++i ) + { + K key; + + ar & key; + unordered_set.insert( key ); + } + } + + //! Saving for std::unordered_multiset all other types to binary + template + void save( BinaryOutputArchive & ar, std::unordered_multiset const & unordered_multiset ) + { + ar & multiset.size(); + + for( const auto & i : multiset ) + ar & i; + } + + //! Loading for std::multiset all other types to binary + template + void load( BinaryInputArchive & ar, std::multiset & multiset ) + { + size_t size; + ar & size; + + for( size_t i = 0; i < size; ++i ) + { + K key; + + ar & key; + multiset.insert( key ); + } + } +} // namespace cereal + +#endif // CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_