Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[leap5 -> main] in undo tests, create undo_index in CB memory segment and remove removed_nodes_tracker #42

Merged
merged 4 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions include/chainbase/undo_index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,41 +404,6 @@ namespace chainbase {
BOOST_THROW_EXCEPTION( std::logic_error{ "could not modify object, most likely a uniqueness constraint was violated" } );
}

// Allows testing whether a value has been removed from the undo_index.
//
// The lifetime of an object removed through a removed_nodes_tracker
// does not end before the removed_nodes_tracker is destroyed or invalidated.
//
// A removed_nodes_tracker is invalidated by the following members of undo_index:
// start_undo_session, commit, squash, and undo.
class removed_nodes_tracker {
public:
explicit removed_nodes_tracker(undo_index& idx) : _self(&idx) {}
~removed_nodes_tracker() {
_removed_values.clear_and_dispose([this](value_type* obj) { _self->dispose_node(*obj); });
}
removed_nodes_tracker(const removed_nodes_tracker&) = delete;
removed_nodes_tracker& operator=(const removed_nodes_tracker&) = delete;
bool is_removed(const value_type& obj) const {
return undo_index::get_removed_field(obj) == erased_flag;
}
// Must be used in place of undo_index::remove
void remove(const value_type& obj) {
_self->remove(obj, *this);
}
private:
friend class undo_index;
void save(value_type& obj) {
undo_index::set_removed_field(obj, erased_flag);
_removed_values.push_front(obj);
}
undo_index* _self;
list_base<node, index0_type> _removed_values;
};
auto track_removed() {
return removed_nodes_tracker(*this);
}

void remove( const value_type& obj ) noexcept {
auto& node_ref = const_cast<value_type&>(obj);
erase_impl(node_ref);
Expand All @@ -447,16 +412,6 @@ namespace chainbase {
}
}

private:

void remove( const value_type& obj, removed_nodes_tracker& tracker ) noexcept {
auto& node_ref = const_cast<value_type&>(obj);
erase_impl(node_ref);
if(on_remove(node_ref)) {
tracker.save(node_ref);
}
}

public:

template<typename CompatibleKey>
Expand Down
Loading
Loading