std::shared_ptr works with pointer tracking

This commit is contained in:
Laurent Itti
2013-06-13 15:54:08 -07:00
parent e11edef4c8
commit 58abf1d2b9
7 changed files with 184 additions and 24 deletions

View File

@@ -6,12 +6,12 @@
namespace cereal
{
//! Serialization for std::vectors of arithmetic types to binary
//! Serialization for std::vectors of arithmetic (but not bool) types to binary
template <class T, class A>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
{
std::cout << "Saving vector" << std::endl;
std::cout << "Saving vector (arithmetic)" << std::endl;
const size_t dataSize = std::addressof(vector.back()) - std::addressof(vector.front());
@@ -20,12 +20,12 @@ namespace cereal
ar.save_binary( array.data(), size ); // actual data
}
//! Serialization for std::vectors of arithmetic types to binary
//! Serialization for std::vectors of arithmetic (but not bool) types to binary
template <class T, class A>
typename std::enable_if<std::is_arithmetic<T>::value, void>::type
load( BinaryInputArchive & ar, std::vector<T, A> & vector )
{
std::cout << "Loading vector" << std::endl;
typename std::enable_if<std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type
load( BinaryInputArchive & ar, std::vector<T, A> & vector )
{
std::cout << "Loading vector (arithmetic)" << std::endl;
size_t dataSize;
size_t vectorSize;
@@ -37,11 +37,11 @@ namespace cereal
ar.load_binary( vector.data(), dataSize );
}
//! Serialization for std::vector<bool, A> types to binary
template <class A>
void save( BinaryOutputArchive & ar, std::vector<bool, A> const & vector )
//! Serialization for all other vector types
template <class T, class A>
void save( BinaryOutputArchive & ar, std::vector<T, A> const & vector )
{
std::cout << "Saving vector of bool" << std::endl;
std::cout << "Saving vector" << std::endl;
ar & vector.size(); // number of elements
for( auto it = vector.begin(), end = vector.end(); it != end; ++it )
@@ -49,8 +49,8 @@ namespace cereal
}
//! Serialization for std::vector<bool, A> to binary
template <class A>
void load( BinaryInputArchive & ar, std::vector<bool, A> & vector )
template <class T, class A>
void load( BinaryInputArchive & ar, std::vector<T, A> & vector )
{
size_t size;
ar & size;