@@ -187,14 +187,15 @@ static constexpr eosio::name kv_disk = "eosio.kvdisk"_n;
187
187
template <typename ...Types>
188
188
using non_unique = std::tuple<Types...>;
189
189
190
+ namespace kv {
190
191
template <typename T>
191
- class kv_table ;
192
+ class table ;
192
193
193
- namespace kv_detail {
194
+ namespace internal {
194
195
195
- class kv_table_base ;
196
+ class table_base ;
196
197
197
- class kv_index {
198
+ class index_base {
198
199
199
200
public:
200
201
eosio::name index_name;
@@ -204,10 +205,10 @@ namespace kv_detail {
204
205
key_type to_table_key (const key_type& k) const { return prefix + k; }
205
206
206
207
protected:
207
- kv_index () = default ;
208
+ index_base () = default ;
208
209
209
210
template <typename KF, typename T>
210
- kv_index (eosio::name index_name, KF&& kf, T*) : index_name{index_name} {
211
+ index_base (eosio::name index_name, KF&& kf, T*) : index_name{index_name} {
211
212
key_function = [=](const void * t) {
212
213
return make_key (std::invoke (kf, static_cast <const T*>(t)));
213
214
};
@@ -219,32 +220,32 @@ namespace kv_detail {
219
220
220
221
void get (const key_type& key, void * ret_val, void (*deserialize)(void *, const void *, std::size_t )) const ;
221
222
222
- kv_table_base * tbl;
223
+ table_base * tbl;
223
224
key_type prefix;
224
225
225
226
private:
226
227
template <typename T>
227
- friend class eosio ::kv_table ;
228
- friend class kv_table_base ;
228
+ friend class eosio ::kv::table ;
229
+ friend class table_base ;
229
230
friend class iterator_base ;
230
231
231
232
std::function<key_type(const void *)> key_function;
232
233
233
234
virtual void setup () = 0;
234
235
};
235
236
236
- class kv_table_base {
237
+ class table_base {
237
238
protected:
238
- friend class kv_index ;
239
+ friend class index_base ;
239
240
friend class iterator_base ;
240
241
eosio::name contract_name;
241
242
eosio::name table_name;
242
243
uint64_t db_name;
243
244
244
245
eosio::name primary_index_name;
245
246
246
- kv_index * primary_index;
247
- std::vector<kv_index *> secondary_indices;
247
+ index_base * primary_index;
248
+ std::vector<index_base *> secondary_indices;
248
249
249
250
void put (const void * value, void * old_value,
250
251
std::size_t (*get_size)(const void *),
@@ -328,7 +329,7 @@ namespace kv_detail {
328
329
}
329
330
};
330
331
331
- inline void kv_index ::get (const key_type& key, void * ret_val, void (*deserialize)(void *, const void *, std::size_t )) const {
332
+ inline void index_base ::get (const key_type& key, void * ret_val, void (*deserialize)(void *, const void *, std::size_t )) const {
332
333
uint32_t value_size;
333
334
uint32_t actual_data_size;
334
335
@@ -376,7 +377,7 @@ namespace kv_detail {
376
377
377
378
iterator_base () = default ;
378
379
379
- iterator_base (uint32_t itr, status itr_stat, const kv_index * index) : itr{itr}, itr_stat{itr_stat}, index{index } {}
380
+ iterator_base (uint32_t itr, status itr_stat, const index_base * index) : itr{itr}, itr_stat{itr_stat}, index{index } {}
380
381
381
382
iterator_base (iterator_base&& other) :
382
383
itr (std::exchange(other.itr, 0 )),
@@ -469,7 +470,7 @@ namespace kv_detail {
469
470
uint32_t itr;
470
471
status itr_stat;
471
472
472
- const kv_index * index;
473
+ const index_base * index;
473
474
474
475
int compare (const iterator_base& b) const {
475
476
bool a_is_end = !itr || itr_stat == status::iterator_end;
@@ -501,15 +502,15 @@ namespace kv_detail {
501
502
* @tparam T - the type of the data stored as the value of the table
502
503
*/
503
504
template <typename T>
504
- class kv_table : kv_detail::kv_table_base {
505
+ class table : internal::table_base {
505
506
public:
506
507
template <typename K>
507
508
class index ;
508
509
509
510
private:
510
- using kv_index = kv_detail::kv_index ;
511
+ using index_base = internal::index_base ;
511
512
512
- class base_iterator : public kv_detail ::iterator_base {
513
+ class base_iterator : public internal ::iterator_base {
513
514
public:
514
515
using iterator_base::iterator_base;
515
516
/* *
@@ -520,7 +521,7 @@ class kv_table : kv_detail::kv_table_base {
520
521
*/
521
522
T value () const {
522
523
T val;
523
- iterator_base::value (&val, &kv_table ::deserialize_fun);
524
+ iterator_base::value (&val, &table ::deserialize_fun);
524
525
return val;
525
526
}
526
527
};
@@ -538,7 +539,7 @@ class kv_table : kv_detail::kv_table_base {
538
539
539
540
iterator () = default ;
540
541
541
- iterator (uint32_t itr, status itr_stat, const kv_index * index) : base_iterator{itr, itr_stat, index } {}
542
+ iterator (uint32_t itr, status itr_stat, const index_base * index) : base_iterator{itr, itr_stat, index } {}
542
543
543
544
iterator (iterator&& other) : base_iterator{std::move (other)} {}
544
545
@@ -560,7 +561,7 @@ class kv_table : kv_detail::kv_table_base {
560
561
561
562
iterator& operator --() {
562
563
if (!itr) {
563
- itr = internal_use_do_not_use::kv_it_create (static_cast <kv_table *>(index ->tbl )->db_name , index ->contract_name .value , index ->prefix .data (), index ->prefix .size ());
564
+ itr = internal_use_do_not_use::kv_it_create (static_cast <table *>(index ->tbl )->db_name , index ->contract_name .value , index ->prefix .data (), index ->prefix .size ());
564
565
}
565
566
itr_stat = static_cast <status>(internal_use_do_not_use::kv_it_prev (itr));
566
567
eosio::check (itr_stat != status::iterator_end, " decremented past the beginning" );
@@ -602,7 +603,7 @@ class kv_table : kv_detail::kv_table_base {
602
603
603
604
reverse_iterator () = default ;
604
605
605
- reverse_iterator (uint32_t itr, status itr_stat, const kv_index * index) : base_iterator{itr, itr_stat, index } {}
606
+ reverse_iterator (uint32_t itr, status itr_stat, const index_base * index) : base_iterator{itr, itr_stat, index } {}
606
607
607
608
reverse_iterator (reverse_iterator&& other) : base_iterator{std::move (other)} {}
608
609
@@ -624,7 +625,7 @@ class kv_table : kv_detail::kv_table_base {
624
625
625
626
reverse_iterator& operator --() {
626
627
if (!itr) {
627
- itr = internal_use_do_not_use::kv_it_create (static_cast <kv_table *>(index ->tbl )->db_name , index ->contract_name .value , index ->prefix .data (), index ->prefix .size ());
628
+ itr = internal_use_do_not_use::kv_it_create (static_cast <table *>(index ->tbl )->db_name , index ->contract_name .value , index ->prefix .data (), index ->prefix .size ());
628
629
itr_stat = static_cast <status>(internal_use_do_not_use::kv_it_lower_bound (itr, " " , 0 ));
629
630
}
630
631
itr_stat = static_cast <status>(internal_use_do_not_use::kv_it_next (itr));
@@ -672,7 +673,7 @@ class kv_table : kv_detail::kv_table_base {
672
673
};
673
674
674
675
public:
675
- using iterator = kv_table ::iterator;
676
+ using iterator = table ::iterator;
676
677
using value_type = T;
677
678
678
679
/* *
@@ -686,18 +687,18 @@ class kv_table : kv_detail::kv_table_base {
686
687
*
687
688
* @tparam K - The type of the key used in the index.
688
689
*/
689
- template <typename K>
690
- class index : public kv_index {
690
+ template <typename K>
691
+ class index : public index_base {
691
692
public:
692
- using iterator = kv_table ::iterator;
693
- using kv_table <T>::kv_index ::tbl;
694
- using kv_table <T>::kv_index ::table_name;
695
- using kv_table <T>::kv_index ::contract_name;
696
- using kv_table <T>::kv_index ::index_name;
697
- using kv_table <T>::kv_index ::prefix;
693
+ using iterator = table ::iterator;
694
+ using table <T>::index_base ::tbl;
695
+ using table <T>::index_base ::table_name;
696
+ using table <T>::index_base ::contract_name;
697
+ using table <T>::index_base ::index_name;
698
+ using table <T>::index_base ::prefix;
698
699
699
700
template <typename KF>
700
- index (eosio::name name, KF&& kf) : kv_index {name, kf, (T*)nullptr } {
701
+ index (eosio::name name, KF&& kf) : index_base {name, kf, (T*)nullptr } {
701
702
static_assert (std::is_same_v<K, std::remove_cv_t <std::decay_t <decltype (std::invoke (kf, std::declval<const T*>()))>>>,
702
703
" Make sure the variable/function passed to the constructor returns the same type as the template parameter." );
703
704
}
@@ -712,7 +713,7 @@ class kv_table : kv_detail::kv_table_base {
712
713
iterator find (const K& key) const {
713
714
auto t_key = prefix + make_key (key);
714
715
715
- uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <kv_table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
716
+ uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
716
717
int32_t itr_stat = internal_use_do_not_use::kv_it_lower_bound (itr, t_key.data (), t_key.size ());
717
718
718
719
auto cmp = internal_use_do_not_use::kv_it_key_compare (itr, t_key.data (), t_key.size ());
@@ -736,7 +737,7 @@ class kv_table : kv_detail::kv_table_base {
736
737
uint32_t value_size;
737
738
auto t_key = prefix + make_key (key);
738
739
739
- return internal_use_do_not_use::kv_get (static_cast <kv_table *>(tbl)->db_name , contract_name.value , t_key.data (), t_key.size (), value_size);
740
+ return internal_use_do_not_use::kv_get (static_cast <table *>(tbl)->db_name , contract_name.value , t_key.data (), t_key.size (), value_size);
740
741
}
741
742
742
743
/* *
@@ -762,7 +763,7 @@ class kv_table : kv_detail::kv_table_base {
762
763
std::optional<T> get (const K& key) const {
763
764
std::optional<T> ret_val;
764
765
auto k = prefix + make_key (key);
765
- kv_index ::get (k, &ret_val, &deserialize_optional_fun);
766
+ index_base ::get (k, &ret_val, &deserialize_optional_fun);
766
767
return ret_val;
767
768
}
768
769
@@ -773,7 +774,7 @@ class kv_table : kv_detail::kv_table_base {
773
774
* @return An iterator to the object with the lowest key (by this index) in the table.
774
775
*/
775
776
iterator begin () const {
776
- uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <kv_table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
777
+ uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
777
778
int32_t itr_stat = internal_use_do_not_use::kv_it_lower_bound (itr, " " , 0 );
778
779
779
780
return {itr, static_cast <typename iterator::status>(itr_stat), this };
@@ -796,7 +797,7 @@ class kv_table : kv_detail::kv_table_base {
796
797
* @return A reverse iterator to the object with the highest key (by this index) in the table.
797
798
*/
798
799
reverse_iterator rbegin () const {
799
- uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <kv_table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
800
+ uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
800
801
int32_t itr_stat = internal_use_do_not_use::kv_it_prev (itr);
801
802
802
803
return {itr, static_cast <typename iterator::status>(itr_stat), this };
@@ -821,7 +822,7 @@ class kv_table : kv_detail::kv_table_base {
821
822
iterator lower_bound (const K& key) const {
822
823
auto t_key = prefix + make_key (key);
823
824
824
- uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <kv_table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
825
+ uint32_t itr = internal_use_do_not_use::kv_it_create (static_cast <table *>(tbl)->db_name , contract_name.value , prefix.data (), prefix.size ());
825
826
int32_t itr_stat = internal_use_do_not_use::kv_it_lower_bound (itr, t_key.data (), t_key.size ());
826
827
827
828
return {itr, static_cast <typename iterator::status>(itr_stat), this };
@@ -885,7 +886,7 @@ class kv_table : kv_detail::kv_table_base {
885
886
*/
886
887
void put (const T& value, eosio::name payer) {
887
888
T old_value;
888
- kv_table_base ::put (&value, &old_value, &get_size_fun, &deserialize_fun, &serialize_fun, payer);
889
+ table_base ::put (&value, &old_value, &get_size_fun, &deserialize_fun, &serialize_fun, payer);
889
890
}
890
891
891
892
/* @cond PRIVATE */
@@ -911,15 +912,15 @@ class kv_table : kv_detail::kv_table_base {
911
912
* @param key - The key of the value to be removed.
912
913
*/
913
914
void erase (const T& value) {
914
- kv_table_base ::erase (&value);
915
+ table_base ::erase (&value);
915
916
}
916
917
917
918
protected:
918
- kv_table () = default ;
919
+ table () = default ;
919
920
920
921
template <typename I>
921
922
void setup_indices (I& index) {
922
- kv_index * idx = &index ;
923
+ index_base * idx = &index ;
923
924
idx->contract_name = contract_name;
924
925
idx->table_name = table_name;
925
926
idx->tbl = this ;
@@ -955,8 +956,9 @@ class kv_table : kv_detail::kv_table_base {
955
956
956
957
template <typename Type>
957
958
constexpr void validate_types (Type& t) {
958
- constexpr bool is_kv_index = std::is_base_of_v<kv_index , std::decay_t <Type>>;
959
- static_assert (is_kv_index , " Incorrect type passed to init. Must be a reference to an index." );
959
+ constexpr bool is_index = std::is_base_of_v<index_base , std::decay_t <Type>>;
960
+ static_assert (is_index , " Incorrect type passed to init. Must be a reference to an index." );
960
961
}
961
962
};
962
- } // eosio
963
+ } // namespace kv
964
+ } // namespace eosio
0 commit comments