我正在尝试弄清楚如何在 UML 序列图上描述以下函数:
void NodeGraph::notify_graph_change()
{
{
std::lock_guard<std::mutex> graph_changed_lock(graph_mutex_);
bool bad_ptr_encountered = false;
for (auto & event_wptr : graph_events_) {
auto event_ptr = event_wptr.lock();
if (event_ptr) {
event_ptr->set();
} else {
bad_ptr_encountered = true;
}
}
if (bad_ptr_encountered) {
graph_events_.erase(
std::remove_if(graph_events_.begin(), graph_events_.end(),
[](const rclcpp::Event::WeakPtr & wptr) {
return wptr.expired();
}), graph_events_.end());
graph_users_count_.store(graph_events_.size());
}
}
graph_cv_.notify_all();
auto & node_gc = node_base_->get_notify_guard_condition();
try {
node_gc.trigger();
} catch (const rclcpp::exceptions::RCLError & ex) {
throw std::runtime_error(
std::string("failed to notify wait set on graph change: ") + ex.what());
}
}
具体来说,诸如 graph_events_.erase()、graph_cv_.notify_all() 或 node_gc.trigger() 之类的调用。如果我为此类成员变量添加单独的生命线,如何显示它们的生命线与 NodeGraph 类实例生命线相关/绑定,并确保时间轴上的操作顺序正确?
序列图本身并不代表完整的系统。这只是交互的一种可能场景。类图将显示结构关系。
有一个简单的方法可以突出这种关系:命名生命线,例如:
a:NodeGraph
、a.graph_events_:Xyz
等等...