Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. State Machines?

State Machines?

Scheduled Pinned Locked Moved The Lounge
questionlearning
15 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jeff Patterson
    wrote on last edited by
    #1

    Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

    T L W J B 6 Replies Last reply
    0
    • J Jeff Patterson

      Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      Think of a state machine as a board game with spaces. Depending on what space you are on, you can only take certain action (transitions or edges) to other spaces (states or nodes). State machines also fall into the context sensitive designs. That is the 50 cent description. Tim Smith I'm going to patent thought. I have yet to see any prior art.

      1 Reply Last reply
      0
      • J Jeff Patterson

        Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Let us take one class class machine { machine() { m_frunning =false; m_fdisabled = true; } virtual ~machine() {} bool m_running; bool m_disabled; void enable() { m_disabled = false; } void disable() { m_enabled = true; } void start() { m_frunning = true; } void stop() { m_frunning = false; } }; Say, now you create an object of this class A state machine represents the different allowed states and what events causes transitions between these states. In this case, there are four possible states: 1) not running; disabled 2) running; disabled 3) not running; not disabled 4) running, not disabled Of these states, we can define state 2 as invalid. So we have three valid states. The state machine will enable you to understand valid signals and transitions, when the system is in a particluar state. In this case, we would change the start() as void start() { if (!m_fdisabled) m_frunning = true; } Summary: identify valid states of a system, define valid transitions, and make sure that your system never goes to an invalid state. I think, if you are designing systems of any kind, software or not, you do it everyday - the only thing is that you never did a state machine analysis in the conventional manner. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

        G J L 3 Replies Last reply
        0
        • L Lost User

          Let us take one class class machine { machine() { m_frunning =false; m_fdisabled = true; } virtual ~machine() {} bool m_running; bool m_disabled; void enable() { m_disabled = false; } void disable() { m_enabled = true; } void start() { m_frunning = true; } void stop() { m_frunning = false; } }; Say, now you create an object of this class A state machine represents the different allowed states and what events causes transitions between these states. In this case, there are four possible states: 1) not running; disabled 2) running; disabled 3) not running; not disabled 4) running, not disabled Of these states, we can define state 2 as invalid. So we have three valid states. The state machine will enable you to understand valid signals and transitions, when the system is in a particluar state. In this case, we would change the start() as void start() { if (!m_fdisabled) m_frunning = true; } Summary: identify valid states of a system, define valid transitions, and make sure that your system never goes to an invalid state. I think, if you are designing systems of any kind, software or not, you do it everyday - the only thing is that you never did a state machine analysis in the conventional manner. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

          G Offline
          G Offline
          Giles
          wrote on last edited by
          #4

          In a way, you probably do this automatically when builing user interfaces with say a dialog. I can see how its could be useful, so the UI does not end up doing things is should not e.g. like to radio buttons getting selected at the same time where you get to choose your favorite colour, but you can onyl have one favourite colour.

          1 Reply Last reply
          0
          • J Jeff Patterson

            Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

            W Offline
            W Offline
            wayward
            wrote on last edited by
            #5

            http://www.nist.gov/dads/HTML/finiteStateMachine.html[^] Gives a pretty good description... James.

            1 Reply Last reply
            0
            • L Lost User

              Let us take one class class machine { machine() { m_frunning =false; m_fdisabled = true; } virtual ~machine() {} bool m_running; bool m_disabled; void enable() { m_disabled = false; } void disable() { m_enabled = true; } void start() { m_frunning = true; } void stop() { m_frunning = false; } }; Say, now you create an object of this class A state machine represents the different allowed states and what events causes transitions between these states. In this case, there are four possible states: 1) not running; disabled 2) running; disabled 3) not running; not disabled 4) running, not disabled Of these states, we can define state 2 as invalid. So we have three valid states. The state machine will enable you to understand valid signals and transitions, when the system is in a particluar state. In this case, we would change the start() as void start() { if (!m_fdisabled) m_frunning = true; } Summary: identify valid states of a system, define valid transitions, and make sure that your system never goes to an invalid state. I think, if you are designing systems of any kind, software or not, you do it everyday - the only thing is that you never did a state machine analysis in the conventional manner. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

              J Offline
              J Offline
              Jeff Patterson
              wrote on last edited by
              #6

              So, is this a method of identifying all posible invalid states and trying to prevent them from occuring? Or is it a way to make an OOP program flow in a more procedural manor? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

              L 1 Reply Last reply
              0
              • L Lost User

                Let us take one class class machine { machine() { m_frunning =false; m_fdisabled = true; } virtual ~machine() {} bool m_running; bool m_disabled; void enable() { m_disabled = false; } void disable() { m_enabled = true; } void start() { m_frunning = true; } void stop() { m_frunning = false; } }; Say, now you create an object of this class A state machine represents the different allowed states and what events causes transitions between these states. In this case, there are four possible states: 1) not running; disabled 2) running; disabled 3) not running; not disabled 4) running, not disabled Of these states, we can define state 2 as invalid. So we have three valid states. The state machine will enable you to understand valid signals and transitions, when the system is in a particluar state. In this case, we would change the start() as void start() { if (!m_fdisabled) m_frunning = true; } Summary: identify valid states of a system, define valid transitions, and make sure that your system never goes to an invalid state. I think, if you are designing systems of any kind, software or not, you do it everyday - the only thing is that you never did a state machine analysis in the conventional manner. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

                L Offline
                L Offline
                L G
                wrote on last edited by
                #7

                Now, this is programming. I don't want to read about programming when I'm getting drunk and visiting the Lounge on CP... please! ;) cheers! :beer: / L-G --- $> cd /pub $> more beer

                L 1 Reply Last reply
                0
                • J Jeff Patterson

                  So, is this a method of identifying all posible invalid states and trying to prevent them from occuring? Or is it a way to make an OOP program flow in a more procedural manor? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  State machines are used to analyze any system that has states and transition between them based on external/internal events. It enables the designer to make sure that the system does not go into an invalid state. It is a kind of checking, and aids in logical design of systems. It is most widely used in digital circuit design. Say, like Intel making the complex processors would have systems that analyze state-machines for their designs. I use it extensively in designing my classes. This way, the states of the objects are always defined, if the implementation correctly follows the state machine. Helps in identifying design issues very clearly. My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

                  1 Reply Last reply
                  0
                  • L L G

                    Now, this is programming. I don't want to read about programming when I'm getting drunk and visiting the Lounge on CP... please! ;) cheers! :beer: / L-G --- $> cd /pub $> more beer

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    i just wanted to give him an example. IMO, He asked a perfectly non-programming question, although the answer had some code in it. :-D My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

                    1 Reply Last reply
                    0
                    • J Jeff Patterson

                      Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                      J Offline
                      J Offline
                      Jorgen Sigvardsson
                      wrote on last edited by
                      #10

                      The abstract view of a state machine are three sets:

                      • A set of states
                      • A set of events
                      • A set of "valid event possibilities"

                      The set of "valid event possibilities" is a set of triplets. Each triplet comprises two states and one event. One state is a start state, the other state is an end state. The event is what connects the start state with the end state. Another way of looking at a state machine is a connected directed graph, where each node in the graph is a state, and each edge is an event. -- This space for rent.

                      1 Reply Last reply
                      0
                      • J Jeff Patterson

                        Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                        J Offline
                        J Offline
                        Jorgen Sigvardsson
                        wrote on last edited by
                        #11

                        I had a generic templated C++ state machine implementation lying around some time ago. Maybe I'll submit an article on sunday :) -- This space for rent.

                        L J 2 Replies Last reply
                        0
                        • J Jorgen Sigvardsson

                          I had a generic templated C++ state machine implementation lying around some time ago. Maybe I'll submit an article on sunday :) -- This space for rent.

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #12

                          you mean we can check state machines using that. That would be cool :-) My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

                          J 1 Reply Last reply
                          0
                          • L Lost User

                            you mean we can check state machines using that. That would be cool :-) My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

                            J Offline
                            J Offline
                            Jorgen Sigvardsson
                            wrote on last edited by
                            #13

                            Well, sort of. The statemachine could be tested easily. In fact, you could easily setup a state machine "driver" to verify its correctness. The statemachine implements a callback scheme which allows one to specify actions to perform during the state transitions. I guess I could rewrite it to use http://www.codeproject.com/tips/cpp_delegates.asp[^] as callbacks. -- This space for rent.

                            1 Reply Last reply
                            0
                            • J Jorgen Sigvardsson

                              I had a generic templated C++ state machine implementation lying around some time ago. Maybe I'll submit an article on sunday :) -- This space for rent.

                              J Offline
                              J Offline
                              Jeff Patterson
                              wrote on last edited by
                              #14

                              That would be great. I will keep an eye out for it. Thanks to all of you. You have made this clearer and I appreciate the response. Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                              1 Reply Last reply
                              0
                              • J Jeff Patterson

                                Just what exactly is meant as a State Machine? CMP is shamelessly plugging a book about state machines and all of there software mags are full of atricles about this topic and have been for some time. But, I really feel foolish because somewhere I missed the boat on what a state machine is. Can anyone enlighten me? Jeff Patterson Programmers speak in Code. http://www.anti-dmca.org[^]

                                B Offline
                                B Offline
                                Burt Harris
                                wrote on last edited by
                                #15

                                I've got some background with state machines. I've made it through about half Miro Samek's "Practical Statecharts in C/C++" and it's very good. I highly reccomended it. The term "state machine" comes from the realm of digital logic design. Design techniques for logic fall into two sub-categories, combinational logic (where the outputs at any instant in time depend only on the current inputs), and sequential logic (where some memory is involved, i.e. outputs depend on the history of inputs.) State Machines are a design abstraction applied to sequential circuits. When I was in school (before some of you were born) we used State Transition Diagrams (STDs), and there were two somewhat different design patterns, Mealy and Moore machines, that we'd design with and crank down to implementation in hardware... In software, that design abstraction of state machines turns out to be a very useful design tool, and one that few programmers without an EE, communications protocol, or language parsing background know much about. Even those who apply in state machines in one context forget to apply them when writing other aspects of our software, but the advantages are it provides a structured way to think about the changes in behavior of an object over time. Software designed with state machines tends to avoid the growing collection of flags that collect stateful object built from the bottom up. The Unified Modeling Language (UML) has included newer form of state machine design notation, David Harrel's Statecharts, that superset the Mealy and Moore approaches, and add a hierarchical state abstraction that is similar, but orthogonal to, the object-oriented notion of inheritance. Douglas Powell has written some pieces on statechart design, but Miro Samek's "Practical Statecharts in C/C++" (CMP books) is a tour-de-force of state-machine design. He covers design and tours a various of state machine implementation techniques before laying out a powerful new (at least to me) state machine implementation technique that's very compelling. While the examples in this book are typically Win32 GUI programs, the implementation techniques shown in this book are extremely efficient, suitable for use in real-time systems. Coupled with this advantage, the drawback is the implementation closely tied to C/C++ features not available in other languages. I for one have become nearly addicted to C#, and while it's a wonderful language for C/C++ folk, it doesn't include either pointer-to-member functions, or macros, used

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups