3 #include <chainbase/database_index.hpp>
4 #include <chainbase/segment_manager.hpp>
9 #include <scorum/utils/function_view.hpp>
10 #include <scorum/utils/any_range.hpp>
11 #include <scorum/utils/algorithm/foreach_mut.hpp>
19 template <
typename TObject>
using modifier_type = utils::function_view<void(TObject&)>;
20 template <
typename TObject>
using predicate_type = utils::function_view<bool(
const TObject&)>;
21 template <
typename TObject>
using cref_type = std::reference_wrapper<const TObject>;
27 return db_idx.get_index<
typename chainbase::get_index_type<TObject>::type, by_id>().
size();
32 return db_idx.template create<TObject>([&](TObject& o) { modifier(o); });
39 return db_idx.template get<TObject>();
41 FC_CAPTURE_AND_RETHROW()
46 db_idx.modify(o, [&](TObject& o) { modifier(o); });
52 const auto& o = get_single<TObject>(db_idx);
53 db_idx.modify(o, [&](TObject& o) { modifier(o); });
62 template <
typename TObject>
void remove_all(
db_index& db_idx, utils::bidir_range<const TObject> items)
64 utils::foreach_mut(items, [&](
const TObject& o) {
71 db_idx.remove(get_single<TObject>(db_idx));
76 return nullptr == db_idx.template find<TObject>();
79 template <
typename TObject,
typename IndexBy,
typename Key>
const TObject&
get_by(
db_index& db_idx,
const Key& arg)
83 return db_idx.template get<TObject, IndexBy>(arg);
85 FC_CAPTURE_AND_RETHROW()
88 template <
typename TObject,
typename IndexBy,
typename Key>
const TObject*
find_by(
db_index& db_idx,
const Key& arg)
92 return db_idx.template find<TObject, IndexBy>(arg);
94 FC_CAPTURE_AND_RETHROW()
97 template <
typename TObject,
typename IndexBy,
typename Key>
bool is_exists_by(
db_index& db_idx,
const Key& arg)
101 return nullptr != db_idx.template find<TObject, IndexBy>(arg);
103 FC_CAPTURE_AND_RETHROW()
106 template <
typename TObject,
typename IndexBy,
typename TKey>
109 const auto& idx = db_idx.get_index<
typename chainbase::get_index_type<TObject>::type, IndexBy>();
110 return idx.equal_range(key);
113 template <
typename TObject,
typename IndexBy,
typename TKey>
116 const auto& idx = db_idx.get_index<
typename chainbase::get_index_type<TObject>::type, IndexBy>();
117 return idx.equal_range(key);
123 template <
typename TObject,
typename IndexBy,
typename TKeyLhs,
typename TKeyRhs = TKeyLhs>
124 utils::bidir_range<const TObject>
127 const auto& idx = db_idx.get_index<
typename chainbase::get_index_type<TObject>::type, IndexBy>();
135 template <
typename TObject,
typename IndexBy> utils::bidir_range<const TObject>
get_all_by(
db_index& db_idx)
137 const auto& idx = db_idx.get_index<
typename chainbase::get_index_type<TObject>::type, IndexBy>();
139 return { idx.begin(), idx.end() };
155 FC_ASSERT(
false,
"Not implemented.");
172 FC_ASSERT(
false,
"Not implemented.");
193 return detail::size<TObject>(_db_idx);
203 return detail::update_single<TObject>(_db_idx, modifier);
213 detail::remove_single<TObject>(_db_idx);
228 return detail::is_empty<TObject>(_db_idx);
233 return detail::get_single<TObject>(_db_idx);
238 return detail::get_by<TObject, IndexBy, Key>(_db_idx, arg);
243 return detail::find_by<TObject, IndexBy, Key>(_db_idx, arg);
246 template <
class IndexBy,
class Key>
bool is_exists_by(
const Key& arg)
const
248 return detail::is_exists_by<TObject, IndexBy, Key>(_db_idx, arg);
254 template <
typename IndexBy,
typename TKey> utils::bidir_range<const object_type>
get_range_by(
const TKey& key)
const
256 return detail::get_range_by<TObject, IndexBy, TKey>(_db_idx, key <=
_x,
_x <= key);
259 template <
typename IndexBy,
typename TKeyLhs,
typename TKeyRhs = TKeyLhs>
263 return detail::get_range_by<TObject, IndexBy, TKeyLhs, TKeyRhs>(_db_idx, lower, upper);
266 template <
typename IndexBy,
typename TKey>
270 return detail::get_range_by<TObject, IndexBy, TKey, TKey>(_db_idx, lower, upper);
273 template <
typename IndexBy,
typename TKey>
277 return detail::get_range_by<TObject, IndexBy, TKey, TKey>(_db_idx, lower, upper);
280 template <
typename IndexBy,
typename TKey = index_key_type<TObject, IndexBy>>
283 return detail::get_range_by<TObject, IndexBy, TKey, TKey>(_db_idx, lower, upper);
286 template <
typename IndexBy> utils::bidir_range<const object_type>
get_all_by()
const
288 return detail::get_all_by<TObject, IndexBy>(_db_idx);
utils::bidir_range< const object_type > get_range_by(const detail::bound< TKeyLhs > &lower, const detail::bound< TKeyRhs > &upper) const
const object_type & create(modifier_type modifier)
const object_type & get_by(const Key &arg) const
utils::bidir_range< const object_type > get_range_by(const TKey &key) const
const object_type * find_by(const Key &arg) const
bool is_exists_by(const Key &arg) const
void remove_all(utils::bidir_range< const object_type > items)
void remove(const object_type &o)
utils::bidir_range< const object_type > get_all_by() const
utils::bidir_range< const object_type > get_range_by(const detail::bound< TKey > &lower, unbounded_placeholder upper) const
utils::bidir_range< const object_type > get_range_by(unbounded_placeholder lower, unbounded_placeholder upper) const
const object_type & update(const object_type &o, modifier_type modifier)
utils::function_view< void(object_type &)> modifier_type
utils::function_view< bool(const object_type &)> predicate_type
db_accessor(db_index &db_idx)
const object_type & update(modifier_type modifier)
const object_type & get() const
std::reference_wrapper< const TObject > object_cref_type
utils::bidir_range< const object_type > get_range_by(unbounded_placeholder lower, const detail::bound< TKey > &upper) const
utils::bidir_range< const TObject > get_all_by(db_index &db_idx)
bool is_exists_by(db_index &db_idx, const Key &arg)
const TObject & update_single(db_index &db_idx, modifier_type< TObject > modifier)
utils::forward_range< const TObject > hashed_get_range_by(db_index &db_idx, const TKey &key)
const TObject * find_by(db_index &db_idx, const Key &arg)
bool is_empty(db_index &db_idx)
void remove_all(db_index &db_idx, utils::bidir_range< const TObject > items)
utils::bidir_range< const TObject > get_range_by(db_index &db_idx, const detail::bound< TKeyLhs > &lower, const detail::bound< TKeyRhs > &upper)
utils::bidir_range< const TObject > ordered_get_range_by(db_index &db_idx, const TKey &key)
const TObject & get_by(db_index &db_idx, const Key &arg)
auto get_lower_bound(TIdx &idx, const detail::bound< TKey > &bound)
size_t size(db_index &db_idx)
const TObject & create(db_index &db_idx, modifier_type< TObject > modifier)
const TObject & update(db_index &db_idx, const TObject &o, modifier_type< TObject > modifier)
auto get_upper_bound(TIdx &idx, const detail::bound< TKey > &bound)
const TObject & get_single(db_index &db_idx)
void remove_single(db_index &db_idx)
void remove(db_index &db_idx, const TObject &o)
utils::function_view< bool(const TObject &)> predicate_type
utils::function_view< void(TObject &)> modifier_type
const param_placeholder _x
std::reference_wrapper< const TObject > cref_type
boost::optional< const T & > value