| 691 | // --------------------------------------------------------------------------- |
| 692 | |
| 693 | PJ::Status DerivedEngine::removeNode(PJ::NodeId id) { |
| 694 | auto it = impl_->nodes.find(id); |
| 695 | if (it == impl_->nodes.end()) { |
| 696 | return PJ::unexpected(fmt::format("remove_node: node {} not found", id)); |
| 697 | } |
| 698 | |
| 699 | const DerivedNode& node = it->second; |
| 700 | |
| 701 | // Remove from topic_to_nodes |
| 702 | for (PJ::TopicId in_tid : node.all_input_topic_ids) { |
| 703 | auto& v = impl_->topic_to_nodes[in_tid]; |
| 704 | v.erase(std::remove(v.begin(), v.end(), id), v.end()); |
| 705 | } |
| 706 | |
| 707 | // Remove from output_topic_to_node and registered_output_names |
| 708 | for (PJ::TopicId out_tid : node.output_topic_ids) { |
| 709 | impl_->output_topic_to_node.erase(out_tid); |
| 710 | // Remove from registered_output_names (scan for the value) |
| 711 | for (auto sit = impl_->registered_output_names.begin(); sit != impl_->registered_output_names.end(); ++sit) { |
| 712 | if (sit->second == out_tid) { |
| 713 | impl_->registered_output_names.erase(sit); |
| 714 | break; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | // Remove from downstream_of |
| 720 | impl_->downstream_of.erase(id); |
| 721 | for (auto dit = impl_->downstream_of.begin(); dit != impl_->downstream_of.end(); ++dit) { |
| 722 | auto& list = dit.value(); |
| 723 | list.erase(std::remove(list.begin(), list.end(), id), list.end()); |
| 724 | } |
| 725 | |
| 726 | impl_->nodes.erase(it); |
| 727 | return PJ::okStatus(); |
| 728 | } |
| 729 | |
| 730 | bool DerivedEngine::hasNode(PJ::NodeId id) const noexcept { |
| 731 | return impl_->nodes.contains(id); |
no test coverage detected