mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
working on more stl functionality
This commit is contained in:
62
binary_archive/set.hpp
Normal file
62
binary_archive/set.hpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#ifndef CEREAL_BINARY_ARCHIVE_SET_HPP_
|
||||||
|
#define CEREAL_BINARY_ARCHIVE_SET_HPP_
|
||||||
|
|
||||||
|
#include <cereal/binary_archive/binary_archive.hpp>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
namespace cereal
|
||||||
|
{
|
||||||
|
//! Saving for std::set all other types to binary
|
||||||
|
template <class K, class H, class KE, class A>
|
||||||
|
void save( BinaryOutputArchive & ar, std::set<K, H, KE, A> const & set )
|
||||||
|
{
|
||||||
|
ar & set.size();
|
||||||
|
|
||||||
|
for( const auto & i : set )
|
||||||
|
ar & i;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Loading for std::set all other types to binary
|
||||||
|
template <class K, class H, class KE, class A>
|
||||||
|
void load( BinaryInputArchive & ar, std::set<K, H, KE, A> & 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 <class K, class H, class KE, class A>
|
||||||
|
void save( BinaryOutputArchive & ar, std::multiset<K, H, KE, A> const & multiset )
|
||||||
|
{
|
||||||
|
ar & multiset.size();
|
||||||
|
|
||||||
|
for( const auto & i : multiset )
|
||||||
|
ar & i;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Loading for std::multiset all other types to binary
|
||||||
|
template <class K, class H, class KE, class A>
|
||||||
|
void load( BinaryInputArchive & ar, std::multiset<K, H, KE, A> & 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_
|
||||||
64
binary_archive/unordered_set.hpp
Normal file
64
binary_archive/unordered_set.hpp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#ifndef CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_
|
||||||
|
#define CEREAL_BINARY_ARCHIVE_UNORDERED_SET_HPP_
|
||||||
|
|
||||||
|
#include <cereal/binary_archive/binary_archive.hpp>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
namespace cereal
|
||||||
|
{
|
||||||
|
//! Saving for std::unordered_set all other types to binary
|
||||||
|
template <class K, class H, class KE, class A>
|
||||||
|
void save( BinaryOutputArchive & ar, std::unordered_set<K, H, KE, A> 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 <class K, class H, class KE, class A>
|
||||||
|
void load( BinaryInputArchive & ar, std::unordered_set<K, H, KE, A> & 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 <class K, class H, class KE, class A>
|
||||||
|
void save( BinaryOutputArchive & ar, std::unordered_multiset<K, H, KE, A> const & unordered_multiset )
|
||||||
|
{
|
||||||
|
ar & multiset.size();
|
||||||
|
|
||||||
|
for( const auto & i : multiset )
|
||||||
|
ar & i;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Loading for std::multiset all other types to binary
|
||||||
|
template <class K, class H, class KE, class A>
|
||||||
|
void load( BinaryInputArchive & ar, std::multiset<K, H, KE, A> & 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_
|
||||||
Reference in New Issue
Block a user