@@ -45,6 +45,19 @@ namespace CXXStateTree
4545 return name_;
4646 }
4747 }
48+
49+ std::string baseName () const
50+ {
51+ if (parent_ != nullptr )
52+ {
53+ std::string result = parent_->baseName () + " ." + name_;
54+ return result;
55+ }
56+ else
57+ {
58+ return " " ;
59+ }
60+ }
4861 const std::list<State> &substates () const { return substates_; }
4962 const std::unordered_map<std::string, Transition> &transitions () const { return transitions_; }
5063 const std::optional<std::string> &initial_substate () const { return initial_substate_; }
@@ -64,6 +77,45 @@ namespace CXXStateTree
6477 return nullptr ;
6578 }
6679
80+ void collect_transitions (std::vector<std::tuple<std::string, std::string, std::string>> &all_transitions, const std::string &full_name, const std::string &base_name) const
81+ {
82+ for (const auto &[event, t] : transitions_)
83+ {
84+ all_transitions.emplace_back (full_name, base_name != " " ? base_name + " ." + t.target : t.target , event);
85+ }
86+ for (const auto &sub : substates_)
87+ {
88+ std::string sub_full_name = full_name + " ." + sub.name ();
89+ std::string sub_base_name = full_name;
90+ ;
91+ sub.collect_transitions (all_transitions, sub_full_name, sub_base_name);
92+ }
93+ }
94+
95+ void collect_states (std::ostream &os, const std::string &prefix = " " ) const
96+ {
97+ std::string full_name = prefix.empty () ? name_ : prefix + " ." + name_;
98+
99+ if (!substates_.empty ())
100+ {
101+ os << " \t subgraph cluster_" << full_name << " {\n " ;
102+ os << " \t\t label = \" " << full_name << " \" ;\n " ;
103+ for (const auto &sub : substates_)
104+ {
105+ sub.collect_states (os, full_name);
106+ }
107+ // Add virtual entry/exit nodes for clusters
108+ os << " \t\" " << full_name << " _entry\" [label=\"\" , shape=point, style=invis];\n " ;
109+ os << " \t\" " << full_name << " _exit\" [label=\"\" , shape=point, style=invis];\n " ;
110+
111+ os << " \t }\n " ;
112+ }
113+ else
114+ {
115+ os << " \t\" " << full_name << " \" ;\n " ;
116+ }
117+ }
118+
67119 private:
68120 std::string name_;
69121 State *parent_ = nullptr ;
0 commit comments