Cleanup and organization
Delete a useless and unused overload of raw::unpack Also, make the new custom serialization bit work for unreflected types (they still need typename reflection)
This commit is contained in:
parent
907dc57fb6
commit
ac40f449f8
2 changed files with 35 additions and 34 deletions
|
|
@ -235,14 +235,6 @@ namespace fc {
|
|||
vi.value = static_cast<uint64_t>(v);
|
||||
}
|
||||
|
||||
template<typename Stream, typename T> inline void unpack( Stream& s, const T& vi, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
T tmp;
|
||||
fc::raw::unpack( s, tmp, _max_depth - 1 );
|
||||
FC_ASSERT( vi == tmp );
|
||||
}
|
||||
|
||||
template<typename Stream> inline void pack( Stream& s, const char* v, uint32_t _max_depth )
|
||||
{
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
|
|
@ -556,40 +548,50 @@ namespace fc {
|
|||
};
|
||||
template<>
|
||||
struct if_reflected<std::true_type> {
|
||||
private:
|
||||
template<typename...> using void_t = void;
|
||||
|
||||
template<typename T, typename=void>
|
||||
struct has_custom_packing : std::false_type {};
|
||||
template<typename T>
|
||||
struct has_custom_packing<T,
|
||||
void_t<decltype(std::declval<const T>().fc_pack(std::declval<fc::datastream<size_t>&>(), 1)),
|
||||
decltype(std::declval<T>().fc_unpack(std::declval<fc::datastream<size_t>&>(), 1))>>
|
||||
: std::true_type {};
|
||||
public:
|
||||
template<typename Stream, typename T, std::enable_if_t<has_custom_packing<T>::value, bool> = true>
|
||||
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
v.fc_pack( s, _max_depth - 1 );
|
||||
}
|
||||
template<typename Stream, typename T, std::enable_if_t<!has_custom_packing<T>::value, bool> = true>
|
||||
template<typename Stream, typename T>
|
||||
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
if_enum<T>::pack( s, v, _max_depth - 1 );
|
||||
}
|
||||
|
||||
template<typename Stream, typename T, std::enable_if_t<has_custom_packing<T>::value, bool> = true>
|
||||
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
v.fc_unpack( s, _max_depth - 1 );
|
||||
}
|
||||
template<typename Stream, typename T, std::enable_if_t<!has_custom_packing<T>::value, bool> = true>
|
||||
template<typename Stream, typename T>
|
||||
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
if_enum<T>::unpack( s, v, _max_depth - 1 );
|
||||
}
|
||||
};
|
||||
|
||||
template<typename...> using void_t = void;
|
||||
|
||||
template<typename T, typename=void>
|
||||
struct has_custom_packing : std::false_type {};
|
||||
template<typename T>
|
||||
struct has_custom_packing<T,
|
||||
void_t<decltype(std::declval<const T>().fc_pack(std::declval<fc::datastream<size_t>&>(), 1)),
|
||||
decltype(std::declval<T>().fc_unpack(std::declval<fc::datastream<size_t>&>(), 1))>>
|
||||
: std::true_type {};
|
||||
|
||||
template<typename Stream, typename T, std::enable_if_t<has_custom_packing<T>::value, bool> = true>
|
||||
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
v.fc_pack( s, _max_depth - 1 );
|
||||
}
|
||||
template<typename Stream, typename T, std::enable_if_t<!has_custom_packing<T>::value, bool> = true>
|
||||
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
if_reflected< typename fc::reflector<T>::is_defined >::pack( s, v, _max_depth - 1 );
|
||||
}
|
||||
|
||||
template<typename Stream, typename T, std::enable_if_t<has_custom_packing<T>::value, bool> = true>
|
||||
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
v.fc_unpack( s, _max_depth - 1 );
|
||||
}
|
||||
template<typename Stream, typename T, std::enable_if_t<!has_custom_packing<T>::value, bool> = true>
|
||||
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
if_reflected< typename fc::reflector<T>::is_defined >::unpack( s, v, _max_depth - 1 );
|
||||
}
|
||||
} // namesapce detail
|
||||
|
||||
template<typename Stream, typename T>
|
||||
|
|
@ -787,13 +789,13 @@ namespace fc {
|
|||
template<typename Stream, typename T>
|
||||
void pack( Stream& s, const T& v, uint32_t _max_depth ) {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
fc::raw::detail::if_reflected< typename fc::reflector<T>::is_defined >::pack( s, v, _max_depth - 1 );
|
||||
fc::raw::detail::pack(s, v, _max_depth);
|
||||
}
|
||||
template<typename Stream, typename T>
|
||||
void unpack( Stream& s, T& v, uint32_t _max_depth )
|
||||
{ try {
|
||||
FC_ASSERT( _max_depth > 0 );
|
||||
fc::raw::detail::if_reflected< typename fc::reflector<T>::is_defined >::unpack( s, v, _max_depth - 1 );
|
||||
fc::raw::detail::unpack(s, v, _max_depth);
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
|
||||
|
||||
template<typename T>
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ namespace fc {
|
|||
|
||||
|
||||
template<typename Stream, typename T> void unpack( Stream& s, fc::optional<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> void unpack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> void pack( Stream& s, const fc::optional<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> void pack( Stream& s, const safe<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
template<typename Stream, typename T> void unpack( Stream& s, fc::safe<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
|
||||
|
|
|
|||
Loading…
Reference in a new issue