Quote:Original post by ManaStone
Here is a clicky to the diagram.
That looks interesting. It would look even better if your language had support for tail recursion:
let rec decision1 () = if cond1 () then func2 () ; func3 () ; decision2 () else func7 ()and decision2 = if cond2 () then func4 () ; func5 () ; decision3 () else func6 () ; func1 () ; decision1 ()and decision3 = if cond3 () then func3 () ; decision2 () else func7 ()let run = func1 (); decision1 ()
With something as abstract as this, however, I would probably go for this automaton representation instead:
branch branches[] = { { cond1, 6 }, // 0 { cond2, 5 }, // 1 { cond3, 6 } // 2};step steps[] = { { func1, 0, 1 }, // 0 { func2, -1, 2 }, // 1 { func3, 1, 3 }, // 2 { func4, -1, 4 }, // 3 { func5, 2, 2 }, // 4 { func6, -1, 0 }, // 5 { func7, -1, -1 } // 6};// The required definitions: struct step { boost::function0<void> execute; int branch; int next;};struct branch { boost::function0<bool> condition, int alternative;};int id = 0;while (id != -1){ int next_id = steps[id].next; steps[id].execute(); if (steps[id].branch != -1) if (branches[steps[id].branch].condition()) next_id = branches[steps[id].branch].alternative; id = next_id;}