Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
4
6
8#include <fc/io/varint.hpp>
9#include <fc/io/enum_type.hpp>
10#include <fc/crypto/sha224.hpp>
11#include <fc/safe.hpp>
12#include <fc/container/flat.hpp>
13#include <fc/string.hpp>
14#include <fc/io/raw.hpp>
15#include <fc/static_variant.hpp>
17#include <fc/fixed_string.hpp>
19
20#include <memory>
21#include <vector>
22#include <deque>
23#include <cstdint>
24
25#define OBJECT_CTOR1(NAME) \
26 NAME() = delete; \
27 public: \
28 template<typename Constructor, typename Allocator> \
29 NAME(Constructor&& c, chainbase::allocator<Allocator>) \
30 { c(*this); }
31#define OBJECT_CTOR2_MACRO(x, y, field) ,field(a)
32#define OBJECT_CTOR2(NAME, FIELDS) \
33 NAME() = delete; \
34 public: \
35 template<typename Constructor, typename Allocator> \
36 NAME(Constructor&& c, chainbase::allocator<Allocator> a) \
37 : id(0) BOOST_PP_SEQ_FOR_EACH(OBJECT_CTOR2_MACRO, _, FIELDS) \
38 { c(*this); }
39#define OBJECT_CTOR(...) BOOST_PP_OVERLOAD(OBJECT_CTOR, __VA_ARGS__)(__VA_ARGS__)
40
41#define _V(n, v) fc::mutable_variant_object(n, v)
42
43namespace sysio { namespace chain {
44 using std::map;
45 using std::vector;
46 using std::unordered_map;
47 using std::string;
48 using std::deque;
49 using std::shared_ptr;
50 using std::weak_ptr;
51 using std::unique_ptr;
52 using std::set;
53 using std::pair;
54 using std::make_pair;
55 using std::enable_shared_from_this;
56 using std::tie;
57 using std::move;
58 using std::forward;
59 using std::to_string;
60 using std::all_of;
61
62 using fc::path;
64 using fc::variant;
65 using fc::enum_type;
66 using fc::unsigned_int;
67 using fc::signed_int;
69 using fc::time_point;
70 using fc::safe;
71 using fc::flat_map;
72 using fc::flat_multimap;
73 using fc::flat_set;
74 using std::variant;
75
79
80 struct void_t{};
81
84 template<typename T>
85 using shared_vector = boost::interprocess::vector<T, allocator<T>>;
86 template<typename T>
87 using shared_set = boost::interprocess::set<T, std::less<T>, allocator<T>>;
88 template<typename K, typename V>
89 using shared_flat_multimap = boost::interprocess::flat_multimap< K, V, std::less<K>, allocator< std::pair<K,V> > >;
90
96 class shared_blob : public shared_string {
97 public:
98 shared_blob() = delete;
100
101 shared_blob(const shared_blob& s) = default;
102
103
104 shared_blob& operator=(const shared_blob& s) = default;
105
107
108 template <typename InputIterator>
109 shared_blob(InputIterator f, InputIterator l, const allocator_type& a)
111 {}
112
116 };
117
118 using action_name = name;
123
124
181
229 class account_object;
230
241 using int128_t = __int128;
242 using uint128_t = unsigned __int128;
244
245 struct sha256_less {
246 bool operator()( const fc::sha256& lhs, const fc::sha256& rhs ) const {
247 return
248 std::tie(lhs._hash[0], lhs._hash[1], lhs._hash[2], lhs._hash[3]) <
249 std::tie(rhs._hash[0], rhs._hash[1], rhs._hash[2], rhs._hash[3]);
250 }
251 };
252
253
259
264 inline auto emplace_extension( extensions_type& exts, uint16_t eid, vector<char>&& data) {
265 auto insert_itr = std::upper_bound(exts.begin(), exts.end(), eid, [](uint16_t id, const auto& ext){
266 return id < ext.first;
267 });
268
269 return exts.emplace(insert_itr, eid, std::move(data));
270 }
271
272
273 template<typename Container>
275 {
276 protected:
277 Container* container;
278
279 public:
280 using iterator_category = std::output_iterator_tag;
281 using value_type = void;
282 using difference_type = void;
283 using pointer = void;
284 using reference = void;
285
286 using container_type = Container;
287
288 explicit end_insert_iterator( Container& c )
289 :container(&c)
290 {}
291
292 end_insert_iterator& operator=( typename Container::const_reference value ) {
293 container->insert( container->cend(), value );
294 return *this;
295 }
296
297 end_insert_iterator& operator*() { return *this; }
298 end_insert_iterator& operator++() { return *this; }
299 end_insert_iterator operator++(int) { return *this; }
300 };
301
302 template<typename Container>
305 }
306
307 template<typename T>
309 {
310 static_assert( std::is_enum<T>::value, "enum_hash can only be used on enumeration types" );
311
312 using underlying_type = typename std::underlying_type<T>::type;
313
314 std::size_t operator()(T t) const
315 {
316 return std::hash<underlying_type>{}( static_cast<underlying_type>(t) );
317 }
318 };
319 // enum_hash needed to support old gcc compiler of Ubuntu 16.04
320
321 namespace detail {
323 bool enforce_unique = false;
324 };
325
326 template<typename... Ts>
327 struct decompose;
328
329 template<>
330 struct decompose<> {
331 template<typename ResultVariant>
332 static auto extract( uint16_t id, const vector<char>& data, ResultVariant& result )
333 -> std::optional<extract_match>
334 {
335 return {};
336 }
337 };
338
339 template<typename T, typename... Rest>
340 struct decompose<T, Rest...> {
341 using head_t = T;
342 using tail_t = decompose< Rest... >;
343
344 template<typename ResultVariant>
345 static auto extract( uint16_t id, const vector<char>& data, ResultVariant& result )
346 -> std::optional<extract_match>
347 {
348 if( id == head_t::extension_id() ) {
349 result = fc::raw::unpack<head_t>( data );
350 return { extract_match{ head_t::enforce_unique() } };
351 }
352
353 return tail_t::template extract<ResultVariant>( id, data, result );
354 }
355 };
356
357 template<typename T, typename ... Ts>
358 struct is_any_of {
359 static constexpr bool value = std::disjunction_v<std::is_same<T, Ts>...>;
360 };
361
362 template<typename T, typename ... Ts>
363 constexpr bool is_any_of_v = is_any_of<T, Ts...>::value;
364 }
365
366 template<typename E, typename F>
367 static inline auto has_field( F flags, E field )
368 -> std::enable_if_t< std::is_integral<F>::value && std::is_unsigned<F>::value &&
369 std::is_enum<E>::value && std::is_same< F, std::underlying_type_t<E> >::value, bool>
370 {
371 return ( (flags & static_cast<F>(field)) != 0 );
372 }
373
374 template<typename E, typename F>
375 static inline auto set_field( F flags, E field, bool value = true )
376 -> std::enable_if_t< std::is_integral<F>::value && std::is_unsigned<F>::value &&
377 std::is_enum<E>::value && std::is_same< F, std::underlying_type_t<E> >::value, F >
378 {
379 if( value )
380 return ( flags | static_cast<F>(field) );
381 else
382 return ( flags & ~static_cast<F>(field) );
383 }
384
385 template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
386 template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
387
388} } // sysio::chain
389
390namespace chainbase {
391 // chainbase::shared_cow_string
392 template<typename DataStream> inline DataStream& operator<<( DataStream& s, const chainbase::shared_cow_string& v ) {
395 if( v.size() ) s.write( v.data(), v.size() );
396 return s;
397 }
398
399 template<typename DataStream> inline DataStream& operator>>( DataStream& s, chainbase::shared_cow_string& v ) {
400 fc::unsigned_int size; fc::raw::unpack( s, size );
402 FC_ASSERT( v.size() == 0 );
403 v.resize_and_fill(size.value, [&s](char* buf, std::size_t sz) { s.read(buf, sz); });
404 return s;
405 }
406}
407
std::string name
bip::allocator< char, pinnable_mapped_file::segment_manager > allocator_type
void resize_and_fill(std::size_t new_size, F &&f)
wraps boost::filesystem::path to provide platform independent path manipulation.
uint64_t _hash[4]
Definition sha256.hpp:100
An order-preserving dictionary of variants.
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
end_insert_iterator operator++(int)
Definition types.hpp:299
end_insert_iterator & operator*()
Definition types.hpp:297
std::output_iterator_tag iterator_category
Definition types.hpp:280
end_insert_iterator & operator=(typename Container::const_reference value)
Definition types.hpp:292
end_insert_iterator & operator++()
Definition types.hpp:298
shared_blob(shared_blob &&)=default
shared_blob(const allocator_type &a)
Definition types.hpp:113
shared_blob & operator=(shared_blob &&)=default
shared_blob(InputIterator f, InputIterator l, const allocator_type &a)
Definition types.hpp:109
shared_blob(const shared_blob &s)=default
shared_blob & operator=(const shared_blob &s)=default
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
ehm field
DataStream & operator<<(DataStream &ds, const oid< OidType > &oid)
shared_cow_string shared_string
Definition chainbase.hpp:61
bip::allocator< T, pinnable_mapped_file::segment_manager > allocator
Definition chainbase.hpp:56
DataStream & operator>>(DataStream &ds, oid< OidType > &oid)
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
constexpr bool is_any_of_v
Definition types.hpp:363
end_insert_iterator< Container > end_inserter(Container &c)
Definition types.hpp:303
__int128 int128_t
Definition types.hpp:241
@ UNUSED_account_transaction_history_object_type
Definition types.hpp:158
@ block_summary_object_type
Definition types.hpp:152
@ OBJECT_TYPE_COUNT
Sentry value which contains the number of different object types.
Definition types.hpp:179
@ account_control_history_object_type
Defined by history_plugin.
Definition types.hpp:157
@ resource_usage_object_type
Definition types.hpp:169
@ UNUSED_scope_sequence_object_type
Definition types.hpp:166
@ index256_object_type
Definition types.hpp:147
@ index_double_object_type
Definition types.hpp:148
@ action_history_object_type
Defined by history_plugin.
Definition types.hpp:173
@ account_object_type
Definition types.hpp:138
@ key_value_object_type
Definition types.hpp:144
@ UNUSED_proxy_vote_object_type
Definition types.hpp:165
@ account_history_object_type
Defined by history_plugin.
Definition types.hpp:172
@ index_long_double_object_type
Definition types.hpp:149
@ resource_limits_state_object_type
Definition types.hpp:170
@ generated_transaction_object_type
Definition types.hpp:154
@ resource_limits_object_type
Definition types.hpp:168
@ resource_limits_config_object_type
Definition types.hpp:171
@ transaction_object_type
Definition types.hpp:153
@ permission_object_type
Definition types.hpp:140
@ protocol_state_object_type
Definition types.hpp:175
@ database_header_object_type
Definition types.hpp:178
@ UNUSED_producer_votes_object_type
Definition types.hpp:163
@ account_ram_correction_object_type
Definition types.hpp:176
@ reversible_block_object_type
Definition types.hpp:174
@ table_id_object_type
Definition types.hpp:167
@ UNUSED_transaction_history_object_type
Definition types.hpp:159
@ UNUSED_chain_property_object_type
Definition types.hpp:156
@ permission_usage_object_type
Definition types.hpp:141
@ code_object_type
Definition types.hpp:177
@ UNUSED_staked_balance_object_type
Definition types.hpp:162
@ index64_object_type
Definition types.hpp:145
@ public_key_history_object_type
Defined by history_plugin.
Definition types.hpp:160
@ permission_link_object_type
Definition types.hpp:142
@ null_object_type
Definition types.hpp:137
@ index128_object_type
Definition types.hpp:146
@ UNUSED_producer_schedule_object_type
Definition types.hpp:164
@ global_property_object_type
Definition types.hpp:150
@ UNUSED_producer_object_type
Definition types.hpp:155
@ UNUSED_balance_object_type
Definition types.hpp:161
@ UNUSED_action_code_object_type
Definition types.hpp:143
@ account_metadata_object_type
Definition types.hpp:139
@ dynamic_global_property_object_type
Definition types.hpp:151
auto emplace_extension(extensions_type &exts, uint16_t eid, vector< char > &&data)
Definition types.hpp:264
int64_t share_type
Definition types.hpp:240
boost::interprocess::set< T, std::less< T >, allocator< T > > shared_set
Definition types.hpp:87
vector< std::pair< uint16_t, vector< char > > > extensions_type
Definition types.hpp:258
sysio::chain::action_name action_name
unsigned __int128 uint128_t
Definition types.hpp:242
boost::interprocess::vector< T, allocator< T > > shared_vector
Definition types.hpp:85
uint32_t block_num_type
Definition types.hpp:239
uint16_t weight_type
Definition types.hpp:238
overloaded(Ts...) -> overloaded< Ts... >
fc::sha256 checksum_type
Definition types.hpp:232
boost::interprocess::flat_multimap< K, V, std::less< K >, allocator< std::pair< K, V > > > shared_flat_multimap
Definition types.hpp:89
#define value
Definition pkcs11.h:157
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define T(meth, val, expected)
#define FC_REFLECT_EMPTY(TYPE)
Definition reflect.hpp:317
#define extract(n)
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
serializes a 32 bit signed interger in as few bytes as possible
Definition varint.hpp:41
uint32_t value
Definition varint.hpp:17
static auto extract(uint16_t id, const vector< char > &data, ResultVariant &result) -> std::optional< extract_match >
Definition types.hpp:345
static auto extract(uint16_t id, const vector< char > &data, ResultVariant &result) -> std::optional< extract_match >
Definition types.hpp:332
static constexpr bool value
Definition types.hpp:359
typename std::underlying_type< T >::type underlying_type
Definition types.hpp:312
std::size_t operator()(T t) const
Definition types.hpp:314
Immutable except for fc::from_variant.
Definition name.hpp:43
bool operator()(const fc::sha256 &lhs, const fc::sha256 &rhs) const
Definition types.hpp:246
#define MAX_SIZE_OF_BYTE_ARRAYS
Definition utility.hpp:19
char * s
uint8_t buf[2048]
int l
pInfo flags