From 35f569c1959a03d92445b5ecf530954dffa81b8b Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 9 Feb 2018 15:23:46 +0100 Subject: [PATCH 1/3] add fc::raw::pack/unpack for std::multiset --- include/fc/io/raw.hpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index b0a9e7cdc..7668d6807 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -500,8 +500,8 @@ namespace fc { } } - template - inline void pack( Stream& s, const std::set& value ) { + template + inline void pack( Stream& s, const std::set& value ) { fc::raw::pack( s, unsigned_int((uint32_t)value.size()) ); auto itr = value.begin(); auto end = value.end(); @@ -511,8 +511,30 @@ namespace fc { } } - template - inline void unpack( Stream& s, std::set& value ) { + template + inline void unpack( Stream& s, std::set& value ) { + unsigned_int size; fc::raw::unpack( s, size ); + for( uint64_t i = 0; i < size.value; ++i ) + { + T tmp; + fc::raw::unpack( s, tmp ); + value.insert( std::move(tmp) ); + } + } + + template + inline void pack( Stream& s, const std::multiset& value ) { + fc::raw::pack( s, unsigned_int((uint32_t)value.size()) ); + auto itr = value.begin(); + auto end = value.end(); + while( itr != end ) { + fc::raw::pack( s, *itr ); + ++itr; + } + } + + template + inline void unpack( Stream& s, std::multiset& value ) { unsigned_int size; fc::raw::unpack( s, size ); for( uint64_t i = 0; i < size.value; ++i ) { From f30207f441c6123f2189d7d23568be652480ebb5 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 9 Feb 2018 15:23:46 +0100 Subject: [PATCH 2/3] add fc::raw::pack/unpack for std::multiset --- include/fc/io/raw.hpp | 32 +++++++++++++++++++++++++++----- include/fc/io/raw_fwd.hpp | 6 ++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index b0a9e7cdc..12dbf164d 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -500,8 +500,8 @@ namespace fc { } } - template - inline void pack( Stream& s, const std::set& value ) { + template + inline void pack( Stream& s, const std::set& value ) { fc::raw::pack( s, unsigned_int((uint32_t)value.size()) ); auto itr = value.begin(); auto end = value.end(); @@ -511,12 +511,34 @@ namespace fc { } } - template - inline void unpack( Stream& s, std::set& value ) { + template + inline void unpack( Stream& s, std::set& value ) { + unsigned_int size; fc::raw::unpack( s, size ); + for( uint64_t i = 0; i < size.value; ++i ) + { + typename std::set::value_type tmp; + fc::raw::unpack( s, tmp ); + value.insert( std::move(tmp) ); + } + } + + template + inline void pack( Stream& s, const std::multiset& value ) { + fc::raw::pack( s, unsigned_int((uint32_t)value.size()) ); + auto itr = value.begin(); + auto end = value.end(); + while( itr != end ) { + fc::raw::pack( s, *itr ); + ++itr; + } + } + + template + inline void unpack( Stream& s, std::multiset& value ) { unsigned_int size; fc::raw::unpack( s, size ); for( uint64_t i = 0; i < size.value; ++i ) { - T tmp; + typename std::multiset::value_type tmp; fc::raw::unpack( s, tmp ); value.insert( std::move(tmp) ); } diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index 72e8c604d..d25c20c18 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -41,8 +41,10 @@ namespace fc { - template inline void pack( Stream& s, const std::set& value ); - template inline void unpack( Stream& s, std::set& value ); + template inline void pack( Stream& s, const std::set& value ); + template inline void unpack( Stream& s, std::set& value ); + template inline void pack( Stream& s, const std::multiset& value ); + template inline void unpack( Stream& s, std::multiset& value ); template inline void pack( Stream& s, const std::unordered_set& value ); template inline void unpack( Stream& s, std::unordered_set& value ); From 2d526cd9b5b0031678c693e2d0da8fb6a76f2f98 Mon Sep 17 00:00:00 2001 From: Marek Kochanowicz Date: Fri, 9 Feb 2018 16:10:33 +0100 Subject: [PATCH 3/3] add fc::to_variant/from_variant for std::multiset --- include/fc/variant.hpp | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index ccb2960d7..f0b3cc612 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -125,10 +125,15 @@ namespace fc template void from_variant( const variant& var, fc::flat_set& vo ); - template - void to_variant( const std::set& var, variant& vo ); - template - void from_variant( const variant& var, std::set& vo ); + template + void to_variant( const std::set& var, variant& vo ); + template + void from_variant( const variant& var, std::set& vo ); + + template + void to_variant( const std::multiset& var, variant& vo ); + template + void from_variant( const variant& var, std::multiset& vo ); void to_variant( const time_point& var, variant& vo ); void from_variant( const variant& var, time_point& vo ); @@ -453,8 +458,8 @@ namespace fc } - template - void to_variant( const std::set& var, variant& vo ) + template + void to_variant( const std::set& var, variant& vo ) { std::vector vars(var.size()); size_t i = 0; @@ -462,14 +467,33 @@ namespace fc vars[i] = variant(*itr); vo = vars; } - template - void from_variant( const variant& var, std::set& vo ) + template + void from_variant( const variant& var, std::set& vo ) { const variants& vars = var.get_array(); vo.clear(); //vo.reserve( vars.size() ); for( auto itr = vars.begin(); itr != vars.end(); ++itr ) - vo.insert( itr->as() ); + vo.insert( itr->as::value_type>() ); + } + + template + void to_variant( const std::multiset& var, variant& vo ) + { + std::vector vars(var.size()); + size_t i = 0; + for( auto itr = var.begin(); itr != var.end(); ++itr, ++i ) + vars[i] = variant(*itr); + vo = vars; + } + template + void from_variant( const variant& var, std::multiset& vo ) + { + const variants& vars = var.get_array(); + vo.clear(); + //vo.reserve( vars.size() ); + for( auto itr = vars.begin(); itr != vars.end(); ++itr ) + vo.insert( itr->as::value_type>() ); } /** @ingroup Serializable */