Skip to content
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

Support for BTS #1670: allow serializing shared_ptr<const T> #115

Merged
merged 2 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/fc/io/raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ namespace fc {
fc::raw::pack( s, *v, _max_depth - 1 );
}

template<typename Stream, typename T>
inline void pack( Stream& s, const std::shared_ptr<const T>& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, *v, _max_depth - 1 );
}

template<typename Stream, typename T, size_t N>
inline void unpack( Stream& s, fc::array<T,N>& v, uint32_t _max_depth )
{ try {
Expand All @@ -157,6 +164,15 @@ namespace fc {
fc::raw::unpack( s, *v, _max_depth - 1 );
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<T>", ("type",fc::get_typename<T>::name()) ) }

template<typename Stream, typename T>
inline void unpack( Stream& s, std::shared_ptr<const T>& 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<const T>(std::move(tmp));
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<const T>", ("type",fc::get_typename<T>::name()) ) }

template<typename Stream> inline void pack( Stream& s, const unsigned_int& v, uint32_t _max_depth ) {
uint64_t val = v.value;
do {
Expand Down
10 changes: 10 additions & 0 deletions include/fc/io/raw_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ namespace fc {
template<typename Stream, typename T, size_t N> inline void pack( Stream& s, const fc::array<T,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T, size_t N> inline void unpack( Stream& s, fc::array<T,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH);

template<typename Stream, typename T> inline void pack( Stream& s, const shared_ptr<T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, shared_ptr<T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );

template<typename Stream, typename T> inline void pack( Stream& s, const shared_ptr<const T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, shared_ptr<const T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );

template<typename Stream> inline void pack( Stream& s, const bool& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, bool& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );

Expand Down