From 0843aa6652db29f15305a9edb511b72e91e7ff63 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sun, 16 Feb 2014 01:17:31 -0500 Subject: [PATCH] adding raw serialization for unordered_map --- CMakeLists.txt | 1 + include/fc/io/raw.hpp | 39 +++++++++++++++++++++++++++++++++++++++ include/fc/io/raw_fwd.hpp | 8 ++++++++ src/io/iostream.cpp | 2 +- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e82ea52..df7a42b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ set( fc_sources src/io/sstream.cpp src/io/json.cpp src/io/varint.cpp + src/io/console.cpp src/filesystem.cpp src/interprocess/process.cpp src/interprocess/signals.cpp diff --git a/include/fc/io/raw.hpp b/include/fc/io/raw.hpp index 874483d..5e1d0ca 100644 --- a/include/fc/io/raw.hpp +++ b/include/fc/io/raw.hpp @@ -254,6 +254,45 @@ namespace fc { } } + + template + inline void pack( Stream& s, const std::pair& value ) { + pack( s, value.first ); + pack( s, value.second ); + } + template + inline void unpack( Stream& s, std::pair& value ) + { + unpack( s, value.first ); + unpack( s, value.second ); + } + + template + inline void pack( Stream& s, const std::unordered_map& value ) { + pack( s, unsigned_int(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::unordered_map& value ) + { + unsigned_int size; unpack( s, size ); + value.clear(); + FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE ); + value.reserve(size.value); + for( uint32_t i = 0; i < size.value; ++i ) + { + std::pair tmp; + fc::raw::unpack( s, tmp ); + value.insert( std::move(tmp) ); + } + } + + template inline void pack( Stream& s, const std::vector& value ) { pack( s, unsigned_int(value.size()) ); diff --git a/include/fc/io/raw_fwd.hpp b/include/fc/io/raw_fwd.hpp index b4f67ca..cf17bd5 100644 --- a/include/fc/io/raw_fwd.hpp +++ b/include/fc/io/raw_fwd.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace fc { @@ -26,6 +27,13 @@ namespace fc { template inline void unpack( Stream& s, std::set& value ); template inline void pack( Stream& s, const std::unordered_set& value ); template inline void unpack( Stream& s, std::unordered_set& value ); + + template inline void pack( Stream& s, const std::unordered_map& value ); + template inline void unpack( Stream& s, std::unordered_map& value ); + + template inline void pack( Stream& s, const std::pair& value ); + template inline void unpack( Stream& s, std::pair& value ); + template inline void pack( Stream& s, const variant_object& v ); template inline void unpack( Stream& s, variant_object& v ); template inline void pack( Stream& s, const variant& v ); diff --git a/src/io/iostream.cpp b/src/io/iostream.cpp index 69ddc69..1f9b6a4 100644 --- a/src/io/iostream.cpp +++ b/src/io/iostream.cpp @@ -354,4 +354,4 @@ namespace fc { return *this; } -} +} // namespace fc