mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
adding support for more stl types
This commit is contained in:
@@ -9,7 +9,7 @@ namespace cereal
|
|||||||
//! Saving for std::array primitive types to binary
|
//! Saving for std::array primitive types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
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;
|
std::cout << "Saving array (arith)" << std::endl;
|
||||||
ar.save_binary( array.data(), N * sizeof(T) );
|
ar.save_binary( array.data(), N * sizeof(T) );
|
||||||
@@ -18,7 +18,7 @@ namespace cereal
|
|||||||
//! Loading for std::array primitive types to binary
|
//! Loading for std::array primitive types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
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;
|
std::cout << "Loading array (arith)" << std::endl;
|
||||||
ar.load_binary( array.data(), N * sizeof(T) );
|
ar.load_binary( array.data(), N * sizeof(T) );
|
||||||
@@ -26,8 +26,8 @@ namespace cereal
|
|||||||
|
|
||||||
//! Saving for std::array all other types to binary
|
//! Saving for std::array all other types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
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" << std::endl;
|
std::cout << "Saving array" << std::endl;
|
||||||
for( const auto & i : array )
|
for( const auto & i : array )
|
||||||
@@ -36,8 +36,8 @@ namespace cereal
|
|||||||
|
|
||||||
//! Loading for std::array all other types to binary
|
//! Loading for std::array all other types to binary
|
||||||
template <class T, size_t N>
|
template <class T, size_t N>
|
||||||
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
|
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" << std::endl;
|
std::cout << "Loading array" << std::endl;
|
||||||
for( auto & i : array )
|
for( auto & i : array )
|
||||||
|
|||||||
33
binary_archive/dequeue.hpp
Normal file
33
binary_archive/dequeue.hpp
Normal 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_
|
||||||
33
binary_archive/forward_list.hpp
Normal file
33
binary_archive/forward_list.hpp
Normal 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
33
binary_archive/list.hpp
Normal 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_
|
||||||
Reference in New Issue
Block a user