c++ state machine pattern