-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preliminary support for generic serialization #160
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,10 @@ | |
#include <boost/config.hpp> | ||
#include <boost/serialization/strong_typedef.hpp> | ||
|
||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) | ||
#include <type_traits> // For std::is_same, std::enable_if | ||
#endif | ||
|
||
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | ||
// serialization.hpp: interface for serialization system. | ||
|
||
|
@@ -60,6 +64,44 @@ namespace serialization { | |
|
||
BOOST_STRONG_TYPEDEF(unsigned int, version_type) | ||
|
||
#if __cplusplus==201103L | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use detection from boost.config instead of raw checks like this. |
||
|
||
namespace detail { | ||
|
||
struct has_serialize | ||
{ | ||
|
||
private: | ||
template<class T> | ||
static constexpr auto check(T*) | ||
-> typename | ||
std::is_same< | ||
decltype(std::declval<T>().serialize(std::declval<Archive&>(), std::declval<unsigned int>())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is Archive& coming from here? |
||
void | ||
>::type; | ||
|
||
template<class> | ||
static constexpr std::false_type check(...); | ||
|
||
typedef decltype(check<C>(0)) type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps Boost.Concept should be used instead of writing this manually. |
||
|
||
public: | ||
static constexpr bool value = type::value; | ||
}; | ||
|
||
} //namespace detail | ||
|
||
// default implementation - call the member function "serialize" if it exists, | ||
// else removed from overload resolution. | ||
template<class Archive, class T> | ||
inline typename std::enable_if<detail::has_serialize<Archive, T>::value>::type serialize( | ||
Archive & ar, T & t, const unsigned int file_version | ||
){ | ||
access::serialize(ar, t, static_cast<unsigned int>(file_version)); | ||
} | ||
|
||
#else //__cplusplus==201103L | ||
|
||
// default implementation - call the member function "serialize" | ||
template<class Archive, class T> | ||
inline void serialize( | ||
|
@@ -68,6 +110,8 @@ inline void serialize( | |
access::serialize(ar, t, static_cast<unsigned int>(file_version)); | ||
} | ||
|
||
#endif //__cplusplus==201103L | ||
|
||
// save data required for construction | ||
template<class Archive, class T> | ||
inline void save_construct_data( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need <type_traits>, versions of enable_if and is_same are in boost.core.