Scorum
comment_vote.cpp
Go to the documentation of this file.
3 
5 
6 #include <tuple>
7 
8 using namespace scorum::protocol;
9 
10 namespace scorum {
11 namespace chain {
12 
13 dbs_comment_vote::dbs_comment_vote(database& db)
14  : base_service_type(db)
15 {
16 }
17 
18 const comment_vote_object& dbs_comment_vote::get(const comment_id_type& comment_id,
19  const account_id_type& voter_id) const
20 {
21  try
22  {
23  return db_impl().get<comment_vote_object, by_comment_voter>(boost::make_tuple(comment_id, voter_id));
24  }
25  FC_CAPTURE_AND_RETHROW((comment_id)(voter_id))
26 }
27 
29 {
31 
32  const auto& vote_idx = db_impl().get_index<comment_vote_index>().indices().get<by_comment_voter>();
33  auto vote_itr = vote_idx.lower_bound(comment_id);
34  while (vote_itr != vote_idx.end() && vote_itr->comment == comment_id)
35  {
36  ret.push_back(std::cref(*(vote_itr++)));
37  }
38 
39  return ret;
40 }
41 
44 {
46 
47  const auto& vote_idx = db_impl().get_index<comment_vote_index>().indices().get<by_comment_weight_voter>();
48  auto vote_itr = vote_idx.lower_bound(comment_id);
49  while (vote_itr != vote_idx.end() && vote_itr->comment == comment_id)
50  {
51  ret.push_back(std::cref(*(vote_itr++)));
52  }
53 
54  return ret;
55 }
56 
57 bool dbs_comment_vote::is_exists(const comment_id_type& comment_id, const account_id_type& voter_id) const
58 {
59  return nullptr != db_impl().find<comment_vote_object, by_comment_voter>(std::make_tuple(comment_id, voter_id));
60 }
61 
63 {
64  const auto& vote_idx = db_impl().get_index<comment_vote_index>().indices().get<by_comment_voter>();
65 
66  auto vote_itr = vote_idx.lower_bound(comment_id_type(comment_id));
67  while (vote_itr != vote_idx.end() && vote_itr->comment == comment_id)
68  {
69  const auto& cur_vote = *vote_itr;
70  ++vote_itr;
71  remove(cur_vote);
72  }
73 }
74 
75 } // namespace chain
76 } // namespace scorum
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
dba::db_index & db_impl()
Definition: dbs_base.cpp:22
comment_vote_refs_type get_by_comment_weight_voter(const comment_id_type &comment_id) const override
comment_vote_refs_type get_by_comment(const comment_id_type &comment_id) const override
void remove_by_comment(const comment_id_type &comment_id) override
virtual const object_type & get() const override
oid< comment_object > comment_id_type
Definition: asset.cpp:15
std::vector< std::reference_wrapper< const comment_vote_object > > comment_vote_refs_type