How to show function calls on a C++ class member variable on a UML sequence diagram?

68 views Asked by At

I am trying to figure out how to depict the following function on a UML sequence diagram:

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());
  }
}

Specifically the calls like graph_events_.erase(), graph_cv_.notify_all() or node_gc.trigger(). If I add separate lifelines for such member variables, how can I show that their lifelines are related/bound to the NodeGraph class instance lifeline, and ensure the right ordering of actions on the time axis?

1

There are 1 answers

1
Christophe On

A sequence diagram does not represent on its own the full system. It's just one possible scenario of interactions. The class diagram will show the structural relationships.

There is an easy way to highlight the relationship however: name the lifelines, e,g. a:NodeGraph, a.graph_events_:Xyz etc...