From ba96174e7f8453c0e70c439c8c987458503fffa2 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Sat, 23 Mar 2019 11:35:40 -0500 Subject: [PATCH 1/2] Support for BTS #1670: allow serializing shared_ptr --- include/fc/io/raw.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 2268e3720..6b7bccba1 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -143,6 +143,13 @@ namespace fc { fc::raw::pack( s, *v, _max_depth - 1 ); } + template + inline void pack( Stream& s, const std::shared_ptr& v, uint32_t _max_depth ) + { + FC_ASSERT( _max_depth > 0 ); + fc::raw::pack( s, *v, _max_depth - 1 ); + } + template inline void unpack( Stream& s, fc::array& v, uint32_t _max_depth ) { try { @@ -157,6 +164,15 @@ namespace fc { fc::raw::unpack( s, *v, _max_depth - 1 ); } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr", ("type",fc::get_typename::name()) ) } + template + inline void unpack( Stream& s, std::shared_ptr& v, uint32_t _max_depth ) + { try { + FC_ASSERT( _max_depth > 0 ); + T tmp; + fc::raw::unpack( s, tmp, _max_depth - 1 ); + v = std::make_shared(tmp); + } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr", ("type",fc::get_typename::name()) ) } + template inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth ) { uint64_t val = v.value; do { From 6665406f83215efdcbf59dfcef73d0f943e23874 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Sun, 24 Mar 2019 09:54:57 -0500 Subject: [PATCH 2/2] Requested changes for #115 --- include/fc/io/raw.hpp | 2 +- include/fc/io/raw_fwd.hpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 6b7bccba1..24aff5eca 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -170,7 +170,7 @@ namespace fc { FC_ASSERT( _max_depth > 0 ); T tmp; fc::raw::unpack( s, tmp, _max_depth - 1 ); - v = std::make_shared(tmp); + v = std::make_shared(std::move(tmp)); } FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr", ("type",fc::get_typename::name()) ) } template inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth ) { diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index 87a92084a..df807685f 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -126,6 +126,16 @@ namespace fc { template inline void pack( Stream& s, const fc::array& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, fc::array& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH); + template inline void pack( Stream& s, const shared_ptr& v, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void unpack( Stream& s, shared_ptr& v, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + + template inline void pack( Stream& s, const shared_ptr& v, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void unpack( Stream& s, shared_ptr& v, + uint32_t _max_depth=FC_PACK_MAX_DEPTH ); + template inline void pack( Stream& s, const bool& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH ); template inline void unpack( Stream& s, bool& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );