mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
C style arrays now exist in common.hpp, no longer need to do them for each archive type
This commit is contained in:
@@ -119,22 +119,6 @@ namespace cereal
|
|||||||
ar( t.size );
|
ar( t.size );
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Saving arrays
|
|
||||||
template <class T> inline
|
|
||||||
typename std::enable_if<std::is_array<T>::value, void>::type
|
|
||||||
save(BinaryOutputArchive & ar, T const & array)
|
|
||||||
{
|
|
||||||
ar.saveBinary(array, traits::sizeof_array<T>() * sizeof(typename std::remove_all_extents<T>::type));
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Loading arrays
|
|
||||||
template <class T> inline
|
|
||||||
typename std::enable_if<std::is_array<T>::value, void>::type
|
|
||||||
load(BinaryInputArchive & ar, T & array)
|
|
||||||
{
|
|
||||||
ar.loadBinary(array, traits::sizeof_array<T>() * sizeof(typename std::remove_all_extents<T>::type));
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Saving binary data
|
//! Saving binary data
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
void save(BinaryOutputArchive & ar, BinaryData<T> const & bd)
|
void save(BinaryOutputArchive & ar, BinaryData<T> const & bd)
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
#include <cereal/details/traits.hpp>
|
#include <cereal/details/traits.hpp>
|
||||||
#include <cereal/details/helpers.hpp>
|
#include <cereal/details/helpers.hpp>
|
||||||
#include <cereal/types/base_class.hpp>
|
#include <cereal/types/base_class.hpp>
|
||||||
#include <cereal/types/common.hpp>
|
|
||||||
|
|
||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
@@ -556,4 +555,7 @@ namespace cereal
|
|||||||
}; // class InputArchive
|
}; // class InputArchive
|
||||||
} // namespace cereal
|
} // namespace cereal
|
||||||
|
|
||||||
|
// This include needs to come after things such as binary_data, make_nvp, etc
|
||||||
|
#include <cereal/types/common.hpp>
|
||||||
|
|
||||||
#endif // CEREAL_CEREAL_HPP_
|
#endif // CEREAL_CEREAL_HPP_
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
#ifndef CEREAL_TYPES_COMMON_HPP_
|
#ifndef CEREAL_TYPES_COMMON_HPP_
|
||||||
#define CEREAL_TYPES_COMMON_HPP_
|
#define CEREAL_TYPES_COMMON_HPP_
|
||||||
|
|
||||||
#include <type_traits>
|
#include <cereal/cereal.hpp>
|
||||||
|
|
||||||
namespace cereal
|
namespace cereal
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,34 @@ namespace cereal
|
|||||||
static_assert(!sizeof(T), "Cereal does not support serializing raw pointers - please use a smart pointer");
|
static_assert(!sizeof(T), "Cereal does not support serializing raw pointers - please use a smart pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: move C style arrays into here
|
namespace common_detail
|
||||||
|
{
|
||||||
|
//! Serialization for arrays if BinaryData is supported
|
||||||
|
/*! @internal */
|
||||||
|
template <class Archive, class T> inline
|
||||||
|
void serializeArray( Archive & ar, T & array, std::true_type /* binary_supported */ )
|
||||||
|
{
|
||||||
|
ar( binary_data( array, traits::sizeof_array<T>() * sizeof(typename std::remove_all_extents<T>::type) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Serialization for arrays if BinaryData is not supported
|
||||||
|
/*! @internal */
|
||||||
|
template <class Archive, class T> inline
|
||||||
|
void serializeArray( Archive & ar, T & array, std::false_type /* binary_supported */ )
|
||||||
|
{
|
||||||
|
for( auto & i : array )
|
||||||
|
ar( i );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Serialization for arrays
|
||||||
|
template <class Archive, class T> inline
|
||||||
|
typename std::enable_if<std::is_array<T>::value, void>::type
|
||||||
|
serialize(Archive & ar, T & array)
|
||||||
|
{
|
||||||
|
common_detail::serializeArray( ar, array,
|
||||||
|
std::integral_constant<bool, traits::is_output_serializable<BinaryData<T>, Archive>()>() );
|
||||||
|
}
|
||||||
} // namespace cereal
|
} // namespace cereal
|
||||||
|
|
||||||
#endif // CEREAL_TYPES_COMMON_HPP_
|
#endif // CEREAL_TYPES_COMMON_HPP_
|
||||||
|
|||||||
@@ -315,6 +315,15 @@ int main()
|
|||||||
|
|
||||||
assert(e_in == e_out);
|
assert(e_in == e_out);
|
||||||
|
|
||||||
|
{
|
||||||
|
cereal::BinaryOutputArchive archive(std::cout);
|
||||||
|
int xxx[] = {-1, 95, 3};
|
||||||
|
archive( xxx );
|
||||||
|
|
||||||
|
cereal::XMLOutputArchive archive2(std::cout);
|
||||||
|
archive2( xxx );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::ofstream os("out.xml");
|
std::ofstream os("out.xml");
|
||||||
cereal::XMLOutputArchive oar( os );
|
cereal::XMLOutputArchive oar( os );
|
||||||
|
|||||||
Reference in New Issue
Block a user