adding support for more stl types

This commit is contained in:
Awesome Robot
2013-06-13 16:55:56 -07:00
parent bb39747ca9
commit 80d0d4ab05
4 changed files with 105 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ namespace cereal
//! Saving for std::array primitive types to binary
template <class T, size_t N>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
void save( BinaryOutputArchive & ar, std::array<T, N> const & array )
save( BinaryOutputArchive & ar, std::array<T, N> const & array )
{
std::cout << "Saving array (arith)" << std::endl;
ar.save_binary( array.data(), N * sizeof(T) );
@@ -18,7 +18,7 @@ namespace cereal
//! Loading for std::array primitive types to binary
template <class T, size_t N>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
void load( BinaryInputArchive & ar, std::array<T, N> & array )
load( BinaryInputArchive & ar, std::array<T, N> & array )
{
std::cout << "Loading array (arith)" << std::endl;
ar.load_binary( array.data(), N * sizeof(T) );
@@ -26,8 +26,8 @@ namespace cereal
//! Saving for std::array all other types to binary
template <class T, size_t N>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
void save( BinaryOutputArchive & ar, std::array<T, N> const & array )
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
save( BinaryOutputArchive & ar, std::array<T, N> const & array )
{
std::cout << "Saving array" << std::endl;
for( const auto & i : array )
@@ -36,8 +36,8 @@ namespace cereal
//! Loading for std::array all other types to binary
template <class T, size_t N>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
void load( BinaryInputArchive & ar, std::array<T, N> & array )
typename std::enable_if<!std::is_arithmetic<T>::value, void>::type
load( BinaryInputArchive & ar, std::array<T, N> & array )
{
std::cout << "Loading array" << std::endl;
for( auto & i : array )

View File

@@ -0,0 +1,33 @@
#ifndef CEREAL_BINARY_ARCHIVE_DEQUE_HPP_
#define CEREAL_BINARY_ARCHIVE_DEQUE_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <deque>
namespace cereal
{
//! Saving for std::deque all other types to binary
template <class T, size_t A>
void save( BinaryOutputArchive & ar, std::deque<T, A> const & deque )
{
ar & deque.size();
for( const auto & i : deque )
ar & i;
}
//! Loading for std::deque all other types to binary
template <class T, size_t A>
void load( BinaryInputArchive & ar, std::deque<T, A> & deque )
{
size_t size;
ar & size;
deque.resize( size );
for( auto & i : deque )
ar & i;
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_DEQUE_HPP_

View File

@@ -0,0 +1,33 @@
#ifndef CEREAL_BINARY_ARCHIVE_FORWARD_LIST_HPP_
#define CEREAL_BINARY_ARCHIVE_FORWARD_LIST_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <forward_list>
namespace cereal
{
//! Saving for std::forward_list all other types to binary
template <class T, size_t A>
void save( BinaryOutputArchive & ar, std::forward_list<T, A> const & forward_list )
{
ar & forward_list.size();
for( const auto & i : forward_list )
ar & i;
}
//! Loading for std::forward_list all other types to binary
template <class T, size_t A>
void load( BinaryInputArchive & ar, std::forward_list<T, A> & forward_list )
{
size_t size;
ar & size;
forward_list.resize( size );
for( auto & i : forward_list )
ar & i;
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_FORWARD_LIST_HPP_

33
binary_archive/list.hpp Normal file
View File

@@ -0,0 +1,33 @@
#ifndef CEREAL_BINARY_ARCHIVE_LIST_HPP_
#define CEREAL_BINARY_ARCHIVE_LIST_HPP_
#include <cereal/binary_archive/binary_archive.hpp>
#include <list>
namespace cereal
{
//! Saving for std::list all other types to binary
template <class T, size_t A>
void save( BinaryOutputArchive & ar, std::list<T, A> const & list )
{
ar & list.size();
for( const auto & i : list )
ar & i;
}
//! Loading for std::list all other types to binary
template <class T, size_t A>
void load( BinaryInputArchive & ar, std::list<T, A> & list )
{
size_t size;
ar & size;
list.resize( size );
for( auto & i : list )
ar & i;
}
} // namespace cereal
#endif // CEREAL_BINARY_ARCHIVE_LIST_HPP_