Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
StateNode.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_StateNode_h_ 00003 #define INCLUDED_StateNode_h_ 00004 00005 #include "Transition.h" 00006 #include "Behaviors/BehaviorBase.h" 00007 #include <vector> 00008 #include <string> 00009 00010 //! Recursive data structure - both a state machine controller as well as a node within a state machine itself 00011 /*! Override setup() to setup your own Transition and StateNode network.*/ 00012 class StateNode : public BehaviorBase { 00013 public: 00014 //! deprecated, behavior constructors should take a name argument (which by default should be the name of the type of the class) 00015 StateNode() __attribute__((deprecated)); 00016 00017 //!constructor, pass a name to use and the parent node if applicable (usually 'this' within setup()) 00018 StateNode(const std::string& name, StateNode* p=NULL) : BehaviorBase("StateNode",name), parent(p), transitions(), issetup(false), retain(true), nodes() {} 00019 00020 //!destructor, removes references to its outgoing transitions (be careful of incoming ones - they're still around!), and calls RemoveReference() on subnodes 00021 virtual ~StateNode(); 00022 00023 //!Adds the specified StateTransition to the transition table 00024 virtual void addTransition(Transition* trans); 00025 00026 //!Returns the std::vector of transitions so you can modify them yourself if need be 00027 std::vector<Transition*>& getTransitions() { return transitions; } 00028 00029 //!Adds a StateNode to #nodes so it can be automatically dereferenced later, returns what it's passed (for convenience), calls AddReference() on @a node. Also sets the node's parent to #this if it is null. 00030 virtual StateNode* addNode(StateNode* node); 00031 00032 //!Returns the std::vector of nodes so you can modify them yourself if need be 00033 std::vector<StateNode*>& getNodes() { return nodes; } 00034 00035 //!Sets the retain flag - if not retained, will RemoveReference() subnodes upon DoStop() and recreate them on DoStart (by calling setup()) - may be too expensive to be worth saving memory... 00036 void setRetain(bool f) { retain=f; } 00037 00038 //!Transitions should call this when you are entering the state, so it can enable its transitions 00039 virtual void DoStart(); 00040 00041 //!This is called by DoStart() when you should setup the network of subnodes 00042 virtual void setup() {issetup=true;} 00043 00044 //!Transitions should call this when you are leaving the state, so it can disable its transitions 00045 virtual void DoStop(); 00046 00047 //!This is called by DoStop() when you should destruct subnodes 00048 virtual void teardown() { issetup=false; /*std::cout << "Teardown!!!!!!!!" << std::endl;*/ } 00049 00050 protected: 00051 //!constructor, pass a name to use and the parent node if applicable (usually 'this' within setup()) 00052 StateNode(const std::string& classname, const std::string& name, StateNode* p=NULL) : BehaviorBase(classname,name), parent(p), transitions(), issetup(false), retain(true), nodes() {} 00053 00054 //!called by a subnode when it is being DoStart()'ed 00055 virtual void transitionTo(StateNode* n); 00056 00057 //!called by a subnode when it is being DoStop()'ed 00058 virtual void transitionFrom(StateNode* n); 00059 00060 //Node Stuff: 00061 //! pointer to the machine that contains this node 00062 StateNode* parent; 00063 //! a vector of outgoing transitions 00064 std::vector<Transition*> transitions; 00065 00066 //Machine Stuff: 00067 //! this is set to true if the network has been setup but not destroyed (i.e. don't need to call setupSubNodes again) 00068 bool issetup; 00069 //! this is set to true if the network should be retained between activations. Otherwise it's dereferenced upon DoStop(). (or at least RemoveReference() is called on subnodes) 00070 bool retain; 00071 //! vector of StateNodes, just so they can be dereferenced again on DoStop() (unless retained) or ~StateNode() 00072 std::vector<StateNode*> nodes; 00073 00074 private: 00075 StateNode(const StateNode& node); //!< don't call this 00076 StateNode operator=(const StateNode& node); //!< don't call this 00077 }; 00078 00079 /*! @file 00080 * @brief Describes StateNode, which is both a state machine controller as well as a node within a state machine itself 00081 * @author ejt (Creator) 00082 * 00083 * $Author: ejt $ 00084 * $Name: tekkotsu-2_2_1 $ 00085 * $Revision: 1.13 $ 00086 * $State: Exp $ 00087 * $Date: 2004/11/15 22:46:19 $ 00088 */ 00089 00090 #endif |
Tekkotsu v2.2.1 |
Generated Tue Nov 23 16:36:40 2004 by Doxygen 1.3.9.1 |