Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Read your proposal, have the following comments:</p> <ol> <li><p>There's actually no keyword to declare and define an actual state machine! Do you assume a single global state machine (and thus a single global state)? How does that relate to <code>__active__</code> ?</p></li> <li><p>The closest comparable construct in C++ is actually the enum. Why not extend it?</p></li> <li><p>There seems to be some connection between defined events and states, but I fail to see how it's implemented. </p></li> <li><p>Why are threads and timers needed at all? Some use cases of state machines may benefit from them, but a good proposal should keep these seperate. Most importantly this should allow the use of standard C++0x threads.</p></li> </ol> <p>Personally, I would extend the enum syntax:</p> <pre><code>enum Foo { red, blue, green; /* Standard C++ so far - defines states. State list ends with a ; not a , */ Foo() { *this = red; } // Reuse ctor syntax, instead of __initial__ ~Foo() { } // reuse dtor syntax, instead of __onexit__ void Bar() {/**/} // Defines an event, no return value. Doesn't need keyword __event__ }; </code></pre> <p>It follows naturally that you can now declare your events in a header, and define them in a .cpp file. I don't even need to suggest the syntax here, any C++ programmer can guess that at this point. Add a bit of inheritance syntax for combined states:</p> <pre><code>enum DrawingObject : public Shape, public Color { /** } // allows (red &amp;&amp; circle) </code></pre> <p>and you're pretty much at the point where your proposal is, without any new keywords, all by reusing an already familiar syntax.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload