Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
container_detail.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fc/variant.hpp>
4#include <fc/io/raw_fwd.hpp>
5
6namespace fc {
7
8 namespace raw {
9
10 namespace detail {
11
12 template<template<typename...> class Set, typename Stream, typename T, typename... U>
13 inline void pack_set( Stream& s, const Set<T, U...>& value ) {
15 pack( s, unsigned_int((uint32_t)value.size()) );
16 for( const auto& item : value ) {
17 pack( s, item );
18 }
19 }
20
21 template<template<typename...> class Set, typename Stream, typename T, typename... U>
22 inline void unpack_set( Stream& s, Set<T, U...>& value ) {
23 unsigned_int size; unpack( s, size );
25 value.clear();
26 for( uint32_t i = 0; i < size.value; ++i ) {
27 auto tmp = ::fc::detail::construct_maybe_with_allocator<T>( value.get_allocator() );
28 unpack( s, tmp );
29 value.insert( value.end(), std::move(tmp) );
30 }
31 }
32
33 template<template<typename...> class Set, typename Stream, typename T, typename... U>
34 inline void unpack_flat_set( Stream& s, Set<T, U...>& value ) {
35 unsigned_int size; unpack( s, size );
37 value.clear();
38 value.reserve( size.value );
39 for( uint32_t i = 0; i < size.value; ++i ) {
40 auto tmp = ::fc::detail::construct_maybe_with_allocator<T>( value.get_allocator() );
41 unpack( s, tmp );
42 value.insert( value.end(), std::move(tmp) );
43 }
44 }
45
46 template<template<typename...> class Map, typename Stream, typename K, typename V, typename... U>
47 inline void pack_map( Stream& s, const Map<K, V, U...>& value ) {
49 pack( s, unsigned_int((uint32_t)value.size()) );
50 for( const auto& item : value ) {
51 pack( s, item );
52 }
53 }
54
55 template<template<typename...> class Map, typename Stream, typename K, typename V, typename... U>
56 inline void unpack_map( Stream& s, Map<K, V, U...>& value ) {
57 unsigned_int size; unpack( s, size );
59 value.clear();
60 for( uint32_t i = 0; i < size.value; ++i ) {
62 unpack( s, tmp );
63 value.insert( value.end(), std::move(tmp) );
64 }
65 }
66
67 template<template<typename...> class Map, typename Stream, typename K, typename V, typename... U>
68 inline void unpack_flat_map( Stream& s, Map<K, V, U...>& value ) {
69 unsigned_int size; unpack( s, size );
71 value.clear();
72 value.reserve( size.value );
73 for( uint32_t i = 0; i < size.value; ++i ) {
75 unpack( s, tmp );
76 value.insert( value.end(), std::move(tmp) );
77 }
78 }
79
80 }
81
82 }
83
84 namespace detail {
85
86 template<template<typename...> class Set, typename T, typename... U>
87 void to_variant_from_set( const Set<T, U...>& s, fc::variant& vo ) {
89 variants vars;
90 vars.reserve( s.size() );
91 for( const auto& item : s ) {
92 vars.emplace_back( item );
93 }
94 vo = std::move( vars );
95 }
96
97 template<template<typename...> class Set, typename T, typename... U>
98 void from_variant_to_set( const fc::variant& v, Set< T, U... >& s ) {
99 const variants& vars = v.get_array();
100 FC_ASSERT( vars.size() <= MAX_NUM_ARRAY_ELEMENTS );
101 s.clear();
102 for( const auto& var : vars ) {
103 auto item = construct_maybe_with_allocator<T>( s.get_allocator() );
104 var.as<T>( item );
105 s.insert( s.end(), std::move(item) );
106 }
107 }
108
109 template<template<typename...> class Set, typename T, typename... U>
110 void from_variant_to_flat_set( const fc::variant& v, Set< T, U... >& s ) {
111 const variants& vars = v.get_array();
112 FC_ASSERT( vars.size() <= MAX_NUM_ARRAY_ELEMENTS );
113 s.clear();
114 s.reserve( vars.size() );
115 for( const auto& var : vars ) {
116 auto item = construct_maybe_with_allocator<T>( s.get_allocator() );
117 var.as<T>( item );
118 s.insert( s.end(), std::move(item) );
119 }
120 }
121
122 template<template<typename...> class Map, typename K, typename V, typename... U >
123 void to_variant_from_map( const Map< K, V, U... >& m, fc::variant& vo ) {
124 FC_ASSERT( m.size() <= MAX_NUM_ARRAY_ELEMENTS );
125 variants vars;
126 vars.reserve( m.size() );
127 for( const auto& item : m ) {
128 vars.emplace_back( item );
129 }
130 vo = std::move( vars );
131 }
132
133 template<template<typename...> class Map, typename K, typename V, typename... U>
134 void from_variant_to_map( const variant& v, Map<K, V, U...>& m ) {
135 const variants& vars = v.get_array();
136 FC_ASSERT( vars.size() <= MAX_NUM_ARRAY_ELEMENTS );
137 m.clear();
138 for( const auto& var : vars ) {
139 auto item = default_construct_pair_maybe_with_allocator<K, V>( m.get_allocator() );
140 var.as< std::pair<K,V> >( item );
141 m.insert( m.end(), std::move(item) );
142 }
143 }
144
145 template<template<typename...> class Map, typename K, typename V, typename... U>
146 void from_variant_to_flat_map( const variant& v, Map<K, V, U...>& m ) {
147 const variants& vars = v.get_array();
148 FC_ASSERT( vars.size() <= MAX_NUM_ARRAY_ELEMENTS );
149 m.clear();
150 m.reserve( vars.size() );
151 for( const auto& var : vars ) {
152 auto item = default_construct_pair_maybe_with_allocator<K, V>( m.get_allocator() );
153 var.as< std::pair<K,V> >( item );
154 m.insert( m.end(), std::move(item) );
155 }
156 }
157
158 }
159
160}
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
variants & get_array()
Definition variant.cpp:496
Concept for reading and writing characters.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
const uint64 K
Definition make_512.cpp:78
void to_variant_from_set(const Set< T, U... > &s, fc::variant &vo)
auto construct_maybe_with_allocator(A &&allocator, Args &&... args) -> std::enable_if_t< supports_allocator< T, A >::value &&supports_allocator< T, A >::leading_allocator, T >
Definition utility.hpp:60
void from_variant_to_flat_set(const fc::variant &v, Set< T, U... > &s)
std::pair< T1, T2 > default_construct_pair_maybe_with_allocator(A &&allocator)
Definition utility.hpp:124
void from_variant_to_map(const variant &v, Map< K, V, U... > &m)
void from_variant_to_flat_map(const variant &v, Map< K, V, U... > &m)
void to_variant_from_map(const Map< K, V, U... > &m, fc::variant &vo)
void from_variant_to_set(const fc::variant &v, Set< T, U... > &s)
void unpack_map(Stream &s, Map< K, V, U... > &value)
void pack_map(Stream &s, const Map< K, V, U... > &value)
void pack_set(Stream &s, const Set< T, U... > &value)
void unpack_set(Stream &s, Set< T, U... > &value)
void unpack_flat_map(Stream &s, Map< K, V, U... > &value)
void unpack_flat_set(Stream &s, Set< T, U... > &value)
void unpack(Stream &s, std::deque< T > &value)
Definition raw.hpp:540
void pack(Stream &s, const std::deque< T > &value)
Definition raw.hpp:531
namespace sysio::chain
Definition authority.cpp:3
std::vector< fc::variant > variants
Definition variant.hpp:173
#define value
Definition pkcs11.h:157
#define T(meth, val, expected)
unsigned int uint32_t
Definition stdint.h:126
Definition test_zm.cpp:19
uint32_t value
Definition varint.hpp:17
Definition dtoa.c:306
#define MAX_NUM_ARRAY_ELEMENTS
Definition utility.hpp:18
char * s