Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
contract_table_objects.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <array>
8#include <type_traits>
9
10namespace sysio { namespace chain {
11
15 class table_id_object : public chainbase::object<table_id_object_type, table_id_object> {
17
18 id_type id;
19 account_name code; //< code should not be changed within a chainbase modifier lambda
20 scope_name scope; //< scope should not be changed within a chainbase modifier lambda
21 table_name table; //< table should not be changed within a chainbase modifier lambda
22 account_name payer;
23 uint32_t count = 0;
24 };
25
26 struct by_code_scope_table;
27
30 indexed_by<
31 ordered_unique<tag<by_id>,
32 member<table_id_object, table_id_object::id_type, &table_id_object::id>
33 >,
34 ordered_unique<tag<by_code_scope_table>,
35 composite_key< table_id_object,
36 member<table_id_object, account_name, &table_id_object::code>,
37 member<table_id_object, scope_name, &table_id_object::scope>,
38 member<table_id_object, table_name, &table_id_object::table>
39 >
40 >
41 >
42 >;
43
45
46 struct by_scope_primary;
47 struct by_scope_secondary;
48 struct by_scope_tertiary;
49
50
51 struct key_value_object : public chainbase::object<key_value_object_type, key_value_object> {
53
55 static const int number_of_keys = 1;
56
58 table_id t_id; //< t_id should not be changed within a chainbase modifier lambda
59 uint64_t primary_key; //< primary_key should not be changed within a chainbase modifier lambda
62 };
63
64 using key_value_index = chainbase::shared_multi_index_container<
66 indexed_by<
67 ordered_unique<tag<by_id>, member<key_value_object, key_value_object::id_type, &key_value_object::id>>,
68 ordered_unique<tag<by_scope_primary>,
69 composite_key< key_value_object,
72 >,
73 composite_key_compare< std::less<table_id>, std::less<uint64_t> >
74 >
75 >
76 >;
77
78 struct by_primary;
79 struct by_secondary;
80
81 template<typename SecondaryKey, uint64_t ObjectTypeId, typename SecondaryKeyLess = std::less<SecondaryKey> >
83 {
84 struct index_object : public chainbase::object<ObjectTypeId,index_object> {
86 typedef SecondaryKey secondary_key_type;
87
88 typename chainbase::object<ObjectTypeId,index_object>::id_type id;
89 table_id t_id; //< t_id should not be changed within a chainbase modifier lambda
90 uint64_t primary_key; //< primary_key should not be changed within a chainbase modifier lambda
92 SecondaryKey secondary_key; //< secondary_key should not be changed within a chainbase modifier lambda
93 };
94
95
96 typedef chainbase::shared_multi_index_container<
98 indexed_by<
99 ordered_unique<tag<by_id>, member<index_object, typename index_object::id_type, &index_object::id>>,
100 ordered_unique<tag<by_primary>,
101 composite_key< index_object,
102 member<index_object, table_id, &index_object::t_id>,
103 member<index_object, uint64_t, &index_object::primary_key>
104 >,
105 composite_key_compare< std::less<table_id>, std::less<uint64_t> >
106 >,
107 ordered_unique<tag<by_secondary>,
108 composite_key< index_object,
109 member<index_object, table_id, &index_object::t_id>,
110 member<index_object, SecondaryKey, &index_object::secondary_key>,
111 member<index_object, uint64_t, &index_object::primary_key>
112 >,
113 composite_key_compare< std::less<table_id>, SecondaryKeyLess, std::less<uint64_t> >
114 >
115 >
117 };
118
119 typedef secondary_index<uint64_t,index64_object_type>::index_object index64_object;
120 typedef secondary_index<uint64_t,index64_object_type>::index_index index64_index;
121
122 typedef secondary_index<uint128_t,index128_object_type>::index_object index128_object;
123 typedef secondary_index<uint128_t,index128_object_type>::index_index index128_index;
124
126 typedef secondary_index<key256_t,index256_object_type>::index_object index256_object;
127 typedef secondary_index<key256_t,index256_object_type>::index_index index256_index;
128
130 bool operator()( const float64_t& lhs, const float64_t& rhs ) const {
131 return f64_lt( lhs, rhs );
132 }
133 };
134
136 bool operator()( const float128_t& lhs, const float128_t& rhs ) const {
137 return f128_lt( lhs, rhs );
138 }
139 };
140
149
157
158 template<typename T>
160 using value_type = std::enable_if_t<std::is_integral<T>::value, T>;
161
162 static_assert( std::numeric_limits<value_type>::is_specialized, "value_type does not have specialized numeric_limits" );
163
164 static constexpr value_type true_lowest() { return std::numeric_limits<value_type>::lowest(); }
165 static constexpr value_type true_highest() { return std::numeric_limits<value_type>::max(); }
166 };
167
168 template<size_t N>
169 struct secondary_key_traits<std::array<uint128_t, N>> {
170 private:
171 static constexpr uint128_t max_uint128 = (static_cast<uint128_t>(std::numeric_limits<uint64_t>::max()) << 64) | std::numeric_limits<uint64_t>::max();
172 static_assert( std::numeric_limits<uint128_t>::max() == max_uint128, "numeric_limits for uint128_t is not properly defined" );
173
174 public:
175 using value_type = std::array<uint128_t, N>;
176
178 value_type arr;
179 return arr;
180 }
181
183 value_type arr;
184 for( auto& v : arr ) {
185 v = std::numeric_limits<uint128_t>::max();
186 }
187 return arr;
188 }
189 };
190
191 template<>
194
196 return f64_negative_infinity();
197 }
198
200 return f64_positive_infinity();
201 }
202 };
203
204 template<>
207
209 return f128_negative_infinity();
210 }
211
213 return f128_positive_infinity();
214 }
215 };
216
221 template<typename T>
223
224#define DECLARE_TABLE_ID_TAG( object, tag ) \
225 template<> \
226 struct object_to_table_id_tag<object> { \
227 using tag_type = tag;\
228 };
229
230 DECLARE_TABLE_ID_TAG(key_value_object, by_scope_primary)
231 DECLARE_TABLE_ID_TAG(index64_object, by_primary)
232 DECLARE_TABLE_ID_TAG(index128_object, by_primary)
233 DECLARE_TABLE_ID_TAG(index256_object, by_primary)
234 DECLARE_TABLE_ID_TAG(index_double_object, by_primary)
235 DECLARE_TABLE_ID_TAG(index_long_double_object, by_primary)
236
237 template<typename T>
239
240namespace config {
241 template<>
243 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 2;
244 static const uint64_t value = 44 + overhead;
245 };
246
247 template<>
249 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 2;
250 static const uint64_t value = 32 + 8 + 4 + overhead;
251 };
252
253 template<>
255 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 3;
256 static const uint64_t value = 24 + 8 + overhead;
257 };
258
259 template<>
261 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 3;
262 static const uint64_t value = 24 + 16 + overhead;
263 };
264
265 template<>
267 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 3;
268 static const uint64_t value = 24 + 32 + overhead;
269 };
270
271 template<>
273 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 3;
274 static const uint64_t value = 24 + 8 + overhead;
275 };
276
277 template<>
279 static const uint64_t overhead = overhead_per_row_per_index_ram_bytes * 3;
280 static const uint64_t value = 24 + 16 + overhead;
281 };
282
283} // namespace config
284
285} } // namespace sysio::chain
286
289
295
296FC_REFLECT(sysio::chain::table_id_object, (code)(scope)(table)(payer)(count) )
298
299#define REFLECT_SECONDARY(type)\
300 FC_REFLECT(type, (primary_key)(payer)(secondary_key) )
301
#define OBJECT_CTOR(...)
Definition types.hpp:39
#define CHAINBASE_SET_INDEX_TYPE(OBJECT_TYPE, INDEX_TYPE)
The table_id_object class tracks the mapping of (scope, code, table) to an opaque identifier.
#define REFLECT_SECONDARY(type)
#define DECLARE_TABLE_ID_TAG(object, tag)
int * count
boost::multi_index_container< Object, Args..., chainbase::node_allocator< Object > > shared_multi_index_container
Definition name.hpp:106
secondary_index< uint128_t, index128_object_type >::index_index index128_index
std::array< uint128_t, 2 > key256_t
typename object_to_table_id_tag< T >::tag_type object_to_table_id_tag_t
secondary_index< float64_t, index_double_object_type, soft_double_less >::index_index index_double_index
secondary_index< uint64_t, index64_object_type >::index_index index64_index
unsigned __int128 uint128_t
Definition types.hpp:242
secondary_index< key256_t, index256_object_type >::index_index index256_index
chainbase::shared_multi_index_container< key_value_object, indexed_by< ordered_unique< tag< by_id >, member< key_value_object, key_value_object::id_type, &key_value_object::id > >, ordered_unique< tag< by_scope_primary >, composite_key< key_value_object, member< key_value_object, table_id, &key_value_object::t_id >, member< key_value_object, uint64_t, &key_value_object::primary_key > >, composite_key_compare< std::less< table_id >, std::less< uint64_t > > > > > key_value_index
chainbase::shared_multi_index_container< table_id_object, indexed_by< ordered_unique< tag< by_id >, member< table_id_object, table_id_object::id_type, &table_id_object::id > >, ordered_unique< tag< by_code_scope_table >, composite_key< table_id_object, member< table_id_object, account_name, &table_id_object::code >, member< table_id_object, scope_name, &table_id_object::scope >, member< table_id_object, table_name, &table_id_object::table > > > > > table_id_multi_index
secondary_index< float128_t, index_long_double_object_type, soft_long_double_less >::index_index index_long_double_index
#define value
Definition pkcs11.h:157
#define T(meth, val, expected)
#define FC_REFLECT(TYPE, MEMBERS)
Specializes fc::reflector for TYPE.
Definition reflect.hpp:311
bool f128_lt(float128_t a, float128_t b)
Definition f128_lt.c:43
bool f64_lt(float64_t a, float64_t b)
Definition f64_lt.c:43
float128_t f128_positive_infinity()
float64_t f64_positive_infinity()
float64_t f64_negative_infinity()
float128_t f128_negative_infinity()
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
Immutable except for fc::from_variant.
Definition name.hpp:43
chainbase::shared_multi_index_container< index_object, indexed_by< ordered_unique< tag< by_id >, member< index_object, typename index_object::id_type, &index_object::id > >, ordered_unique< tag< by_primary >, composite_key< index_object, member< index_object, table_id, &index_object::t_id >, member< index_object, uint64_t, &index_object::primary_key > >, composite_key_compare< std::less< table_id >, std::less< uint64_t > > >, ordered_unique< tag< by_secondary >, composite_key< index_object, member< index_object, table_id, &index_object::t_id >, member< index_object, SecondaryKey, &index_object::secondary_key >, member< index_object, uint64_t, &index_object::primary_key > >, composite_key_compare< std::less< table_id >, SecondaryKeyLess, std::less< uint64_t > > > > > index_index
std::enable_if_t< std::is_integral< T >::value, T > value_type
static constexpr value_type true_lowest()
static constexpr value_type true_highest()
bool operator()(const float64_t &lhs, const float64_t &rhs) const
bool operator()(const float128_t &lhs, const float128_t &rhs) const
yubihsm_pkcs11_object_template template