#pragma once #include #include #include #include #include namespace fc { namespace raw { template inline void pack( Stream& s, const flat_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { fc::raw::pack( s, *itr, _max_depth ); ++itr; } } template inline void unpack( Stream& s, flat_set& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; unsigned_int size; unpack( s, size, _max_depth ); value.clear(); FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE ); value.reserve(size.value); for( uint32_t i = 0; i < size.value; ++i ) { T tmp; fc::raw::unpack( s, tmp, _max_depth ); value.insert( std::move(tmp) ); } } template inline void pack( Stream& s, const flat_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); auto itr = value.begin(); auto end = value.end(); while( itr != end ) { fc::raw::pack( s, *itr, _max_depth ); ++itr; } } template inline void unpack( Stream& s, flat_map& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; unsigned_int size; unpack( s, size, _max_depth ); 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, _max_depth ); value.insert( std::move(tmp) ); } } template void pack( Stream& s, const bip::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; pack( s, unsigned_int((uint32_t)value.size()), _max_depth ); if( !std::is_fundamental::value ) { auto itr = value.begin(); auto end = value.end(); while( itr != end ) { fc::raw::pack( s, *itr, _max_depth ); ++itr; } } else { s.write( (const char*)value.data(), value.size() ); } } template void unpack( Stream& s, bip::vector& value, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; unsigned_int size; unpack( s, size, _max_depth ); value.resize( size ); if( !std::is_fundamental::value ) { for( auto& item : value ) unpack( s, item, _max_depth ); } else { s.read( (char*)value.data(), value.size() ); } } } // namespace raw template void to_variant( const flat_set& var, variant& vo, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; std::vector vars(var.size()); size_t i = 0; for( const auto& item : var ) vars[i++] = variant( item, _max_depth ); vo = vars; } template void from_variant( const variant& var, flat_set& vo, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; const variants& vars = var.get_array(); vo.clear(); vo.reserve( vars.size() ); for( const auto& item : vars ) vo.insert( item.as(_max_depth) ); } template void to_variant( const flat_map& var, variant& vo, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; std::vector< variant > vars(var.size()); size_t i = 0; for( const auto& item : var ) vars[i++] = variant( item, _max_depth ); vo = vars; } template void from_variant( const variant& var, flat_map& vo, uint32_t _max_depth ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; const variants& vars = var.get_array(); vo.clear(); for( const auto& item : vars ) vo.insert( item.as>(_max_depth) ); } }