View Single Post
  #5   Spotlight this post!  
Unread 09-12-2008, 12:26
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,647
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
Re: Simple C++ State Machine

I suspect the motivation is to help compartmentalize and organize the code. If you're doing any sort of complicated state machine, a switch statement can get out of hand rather quickly, unless you're building up separate functions for each case. Which makes the switch statement largely similar to this StateMachine Class, except that adding a new state requires adding a new case to your switch statement, etc. etc. Adding a new state to this state machine looks a bit easier. Also, since it's dynamically allocated, you can change the state callbacks at runtime. If, for instance, you wanted to run a different set of states depending on your alliance or robot position. Instead of having two switches, or a bunch of conditionals, or whatever else.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter