提交 077fd0f0 编写于 作者: A arhag

Rename update to modify and remove to erase.

Also bring back overloads of modify and erase that take a reference to
the object.
上级 9988c71e
......@@ -184,7 +184,7 @@ namespace eosiosystem {
});
}
else {
del_index.update( itr, del.from, [&]( auto& dbo ){
del_index.modify( itr, del.from, [&]( auto& dbo ){
dbo.net_weight = del.stake_net_quantity;
dbo.cpu_weight = del.stake_cpu_quantity;
});
......@@ -198,7 +198,7 @@ namespace eosiosystem {
tot.total_cpu_weight += del.stake_cpu_quantity;
});
} else {
total_index.update( tot_itr, 0, [&]( auto& tot ) {
total_index.modify( tot_itr, 0, [&]( auto& tot ) {
tot.total_net_weight += del.stake_net_quantity;
tot.total_cpu_weight += del.stake_cpu_quantity;
});
......@@ -229,14 +229,14 @@ namespace eosiosystem {
eosio_assert( dbw.net_weight >= del.unstake_net_quantity, "insufficient staked net bandwidth" );
eosio_assert( dbw.cpu_weight >= del.unstake_cpu_quantity, "insufficient staked cpu bandwidth" );
del_index.update( del_index.iterator_to(dbw), del.from, [&]( auto& dbo ){
del_index.modify( dbw, del.from, [&]( auto& dbo ){
dbo.net_weight -= del.unstake_net_quantity;
dbo.cpu_weight -= del.unstake_cpu_quantity;
});
const auto& totals = total_index.get( del.receiver );
total_index.update( total_index.iterator_to(totals), 0, [&]( auto& tot ) {
total_index.modify( totals, 0, [&]( auto& tot ) {
tot.total_net_weight -= del.unstake_net_quantity;
tot.total_cpu_weight -= del.unstake_cpu_quantity;
});
......@@ -308,13 +308,13 @@ namespace eosiosystem {
producer_votes_index_type votes( SystemAccount, SystemAccount );
for( auto p : acv->producers ) {
votes.update( votes.find( p ), 0, [&]( auto& v ) {
votes.modify( votes.get( p ), 0, [&]( auto& v ) {
v.total_votes -= old_weight;
v.total_votes += new_weight;
});
}
avotes.update( acv, 0, [&]( auto av ) {
avotes.modify( acv, 0, [&]( auto av ) {
av.last_update = now();
av.staked += sv.amount;
});
......@@ -361,14 +361,14 @@ namespace eosiosystem {
for( const auto& delta : producer_vote_changes ) {
if( delta.second.first != delta.second.second ) {
const auto& provote = votes.get( delta.first );
votes.update( votes.iterator_to(provote), 0, [&]( auto& pv ){
votes.modify( provote, 0, [&]( auto& pv ){
pv.total_votes -= delta.second.first;
pv.total_votes += delta.second.second;
});
}
}
avotes.update( avotes.iterator_to(existing), 0, [&]( auto& av ) {
avotes.modify( existing, 0, [&]( auto& av ) {
av.proxy = vp.proxy;
av.last_update = now();
av.producers = vp.producers;
......
......@@ -96,7 +96,7 @@ namespace eosio {
};
auto itr = t.find( symbol );
if( itr != t.end() ) {
t.update( itr, update_bill_to, f);
t.modify( itr, update_bill_to, f);
} else {
t.emplace( create_bill_to, f);
}
......@@ -108,7 +108,7 @@ namespace eosio {
stats t( code, code );
auto itr = t.find( symbol );
if( itr != t.end() ) {
t.update(itr, 0, [&](currency_stats& s) { s.supply += act.quantity; });
t.modify(itr, 0, [&](currency_stats& s) { s.supply += act.quantity; });
} else {
t.emplace(code, [&](currency_stats& s) { s.supply = act.quantity; });
}
......
......@@ -322,19 +322,19 @@ class multi_index
}
template<typename Lambda>
void update( const_iterator itr, uint64_t payer, Lambda&& updater ) {
eosio_assert( itr != end(), "cannot pass end iterator to update" );
void modify( const_iterator itr, uint64_t payer, Lambda&& updater ) {
eosio_assert( itr != end(), "cannot pass end iterator to modify" );
_multidx.update(_multidx.iterator_to(*itr), payer, std::forward<Lambda&&>(updater));
_multidx.modify( *itr, payer, std::forward<Lambda&&>(updater) );
}
const_iterator remove( const_iterator itr ) {
eosio_assert( itr != end(), "cannot pass end iterator to remove" );
const_iterator erase( const_iterator itr ) {
eosio_assert( itr != end(), "cannot pass end iterator to erase" );
auto pk_itr = _multidx.iterator_to(*itr);
const auto& obj = *itr;
++itr;
_multidx.remove(pk_itr);
_multidx.erase(obj);
return itr;
}
......@@ -626,10 +626,14 @@ class multi_index
}
template<typename Lambda>
void update( const_iterator itr, uint64_t payer, Lambda&& updater ) {
void modify( const_iterator itr, uint64_t payer, Lambda&& updater ) {
eosio_assert( itr != end(), "cannot pass end iterator to update" );
const auto& obj = *itr;
modify( *itr, payer, std::forward<Lambda&&>(updater) );
}
template<typename Lambda>
void modify( const T& obj, uint64_t payer, Lambda&& updater ) {
const auto& objitem = static_cast<const item&>(obj);
auto& mutableitem = const_cast<item&>(objitem);
......@@ -688,15 +692,22 @@ class multi_index
return iterator_to(static_cast<const T&>(i));
}
const_iterator remove( const_iterator itr ) {
eosio_assert( itr != end(), "cannot pass end iterator to remove" );
const_iterator erase( const_iterator itr ) {
eosio_assert( itr != end(), "cannot pass end iterator to erase" );
const auto& obj = *itr;
++itr;
erase(obj);
const auto& objitem = static_cast<const item&>(*itr);
return itr;
}
void erase( const T& obj ) {
const auto& objitem = static_cast<const item&>(obj);
//auto& mutableitem = const_cast<item&>(objitem);
// eosio_assert( &objitem.__idx == this, "invalid object" );
++itr;
db_remove_i64( objitem.__primary_itr );
boost::hana::for_each( _indices, [&]( auto& idx ) {
......@@ -715,8 +726,6 @@ class multi_index
if( cacheitr != _items_index.end() ) {
_items_index.erase(cacheitr);
}
return itr;
}
};
......
......@@ -57,7 +57,7 @@ namespace eosio {
table t( Code, scope );
auto itr = t.find( pk_value );
if( itr != t.end() ) {
t.update(itr, b, [&](row& r) { r.value = value; });
t.modify(itr, b, [&](row& r) { r.value = value; });
} else {
t.emplace(b, [&](row& r) { r.value = value; });
}
......@@ -67,7 +67,7 @@ namespace eosio {
table t( Code, scope );
auto itr = t.find( pk_value );
if( itr != t.end() ) {
t.remove(itr);
t.erase(itr);
}
}
};
......
......@@ -109,13 +109,13 @@ class exchange {
switch( d.amount.symbol ) {
case base_token_type::symbol:
BaseCurrency::inline_transfer( d.from, ExchangeAccount, base_token_type(d.amount.amount) );
_accounts.update( owner, 0, [&]( auto& a ) {
_accounts.modify( owner, 0, [&]( auto& a ) {
a.base_balance += base_token_type(d.amount);
});
break;
case quote_token_type::symbol:
QuoteCurrency::inline_transfer( d.from, ExchangeAccount, quote_token_type(d.amount.amount) );
_accounts.update( owner, 0, [&]( auto& a ) {
_accounts.modify( owner, 0, [&]( auto& a ) {
a.quote_balance += quote_token_type(d.amount);
});
break;
......@@ -141,7 +141,7 @@ class exchange {
case base_token_type::symbol:
eosio_assert( owner->base_balance >= base_token_type(w.amount), "insufficient balance" );
_accounts.update( owner, 0, [&]( auto& a ) {
_accounts.modify( owner, 0, [&]( auto& a ) {
a.base_balance -= base_token_type(w.amount);
});
......@@ -150,7 +150,7 @@ class exchange {
case quote_token_type::symbol:
eosio_assert( owner->quote_balance >= quote_token_type(w.amount), "insufficient balance" );
_accounts.update( owner, 0, [&]( auto& a ) {
_accounts.modify( owner, 0, [&]( auto& a ) {
a.quote_balance -= quote_token_type(w.amount);
});
......@@ -210,7 +210,7 @@ class exchange {
auto idx = _base_quote_orders.template get_index<N(ownerid)>();
auto itr = idx.find( limit_base_quote::get_owner_id( order.owner, order.id ) );
if( itr != idx.end() ) {
idx.remove(itr);
idx.erase(itr);
}
}
......
......@@ -191,7 +191,7 @@ namespace identity {
}
} else if (DeployToAccount == current_receiver()){
//the certifier is no longer trusted, need to unset the flag
idx.update(itr, 0, [&](certrow& r) {
idx.modify(itr, 0, [&](certrow& r) {
r.trusted = 0;
});
} else {
......@@ -216,7 +216,7 @@ namespace identity {
if (ident == get_claimed_identity(account) && is_trusted(itr->certifier)) {
if (DeployToAccount == current_receiver()) {
// the certifier became trusted and we have permissions to update the flag
idx.update(itr, 0, [&](certrow& r) {
idx.modify(itr, 0, [&](certrow& r) {
r.trusted = 1;
});
}
......@@ -272,7 +272,7 @@ namespace identity {
row.account = t.trusting;
});
} else if( itr != table.end() && t.trust == 0 ) {
table.remove(itr);
table.erase(itr);
}
}
......@@ -307,7 +307,7 @@ namespace identity {
auto itr = idx.lower_bound( certrow::key(value.property, trusted, cert.certifier) );
if (itr != idx.end() && itr->property == value.property && itr->trusted == trusted && itr->certifier == cert.certifier) {
idx.update(itr, 0, [&](certrow& row) {
idx.modify(itr, 0, [&](certrow& row) {
row.confidence = value.confidence;
row.type = value.type;
row.data = value.data;
......@@ -327,7 +327,7 @@ namespace identity {
auto itr_old = idx.lower_bound( certrow::key(value.property, !trusted, cert.certifier) );
if (itr_old != idx.end() && itr_old->property == value.property && itr_old->trusted == !trusted && itr_old->certifier == cert.certifier) {
idx.remove(itr_old);
idx.erase(itr_old);
}
//special handling for owner
......@@ -342,13 +342,13 @@ namespace identity {
bool removed = false;
auto itr = idx.lower_bound( certrow::key(value.property, trusted, cert.certifier) );
if (itr != idx.end() && itr->property == value.property && itr->trusted == trusted && itr->certifier == cert.certifier) {
idx.remove(itr);
idx.erase(itr);
} else {
removed = true;
}
itr = idx.lower_bound( certrow::key(value.property, !trusted, cert.certifier) );
if (itr != idx.end() && itr->property == value.property && itr->trusted == !trusted && itr->certifier == cert.certifier) {
idx.remove(itr);
idx.erase(itr);
} else {
removed = true;
}
......
......@@ -80,8 +80,8 @@ struct limit_order {
print(" ID=", item.id, ", expiration=", item.expiration, ", owner=", name(item.owner), "\n");
}
print("Updating expiration of order with ID=2 to 400.\n");
orders.update( order2, payer, [&]( auto& o ) {
print("Modifying expiration of order with ID=2 to 400.\n");
orders.modify( order2, payer, [&]( auto& o ) {
o.expiration = 400;
});
......@@ -148,7 +148,7 @@ struct limit_order {
print("First entry with a val greater than 42 has ID=", upper->id, ".\n");
print("Removed entry with ID=", lower1->id, ".\n");
validx.remove( lower1 );
validx.erase( lower1 );
print("Items sorted by primary key:\n");
for( const auto& item : testtable ) {
......
......@@ -144,7 +144,7 @@ namespace _test_multi_index {
}
}
// update and remove
// modify and erase
{
const uint64_t ssn = 421;
const auto& new_person = table.emplace( payer, [&]( auto& r ) {
......@@ -152,16 +152,16 @@ namespace _test_multi_index {
r.sec = N(bob);
});
table.update(new_person, payer, [&]( auto& r ) {
table.modify(new_person, payer, [&]( auto& r ) {
r.sec = N(billy);
});
auto itr1 = table.find(ssn);
eosio_assert(itr1 != table.end() && itr1->sec == N(billy), "idx64_general - table.update()");
eosio_assert(itr1 != table.end() && itr1->sec == N(billy), "idx64_general - table.modify()");
table.remove(itr1);
table.erase(itr1);
auto itr2 = table.find(ssn);
eosio_assert( itr2 == table.end(), "idx64_general - table.remove()");
eosio_assert( itr2 == table.end(), "idx64_general - table.erase()");
}
}
......@@ -214,11 +214,11 @@ void test_multi_index::idx128_autoincrement_test()
auto itr = table.find(3);
eosio_assert( itr != table.end(), "idx128_autoincrement_test - could not find object with primary key of 3" );
table.update(itr, payer, [&]( auto& r ) {
table.modify(itr, payer, [&]( auto& r ) {
r.id = 100;
});
eosio_assert( table.available_primary_key() == 101, "idx128_autoincrement_test - next_primary_key was not correct after record update" );
eosio_assert( table.available_primary_key() == 101, "idx128_autoincrement_test - next_primary_key was not correct after record modify" );
}
void test_multi_index::idx128_autoincrement_test_part1()
......@@ -242,7 +242,7 @@ void test_multi_index::idx128_autoincrement_test_part1()
});
}
table.remove(table.find(0));
table.erase(table.get(0));
uint64_t expected_key = 2;
for( const auto& r : table.get_index<N(bysecondary)>() )
......@@ -300,7 +300,7 @@ void test_multi_index::idx128_autoincrement_test_part2()
auto itr = table.find(3);
eosio_assert( itr != table.end(), "idx128_autoincrement_test_part2 - could not find object with primary key of 3" );
table.update(itr, payer, [&]( auto& r ) {
table.modify(itr, payer, [&]( auto& r ) {
r.id = 100;
});
......@@ -396,7 +396,7 @@ void test_multi_index::idx256_general()
eosio_assert( upper->id == 2, "idx256_general - upper_bound" );
print("Removed entry with ID=", lower1->id, ".\n");
secidx.remove( lower1 );
secidx.erase( lower1 );
print("Items reverse sorted by primary key:\n");
for( const auto& item : boost::make_iterator_range(table.rbegin(), table.rend()) ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册