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 00018 StateNode(const std::string& name) : BehaviorBase("StateNode",name), parent(NULL), 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 Transition* 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 //!Returns the const std::vector of transitions so you can read through them if need be 00030 const std::vector<Transition*>& getTransitions() const { return transitions; } 00031 00032 //!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. 00033 virtual StateNode* addNode(StateNode* node); 00034 00035 //!Returns the std::vector of sub-nodes so you can modify them yourself if need be 00036 std::vector<StateNode*>& getNodes() { return nodes; } 00037 00038 //!Returns the const std::vector of sub-nodes so you can read through them if need be 00039 const std::vector<StateNode*>& getNodes() const { return nodes; } 00040 00041 //!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... 00042 void setRetain(bool f) { retain=f; } 00043 00044 //!Transitions should call this when you are entering the state, so it can enable its transitions 00045 virtual void DoStart(); 00046 00047 //!This is called by DoStart() when you should setup the network of subnodes 00048 virtual void setup() {issetup=true;} 00049 00050 //!Transitions should call this when you are leaving the state, so it can disable its transitions 00051 virtual void DoStop(); 00052 00053 //!This is called by DoStop() when you should destruct subnodes 00054 virtual void teardown() { issetup=false; /*std::cout << "Teardown!!!!!!!!" << std::endl;*/ } 00055 00056 //!returns #parent 00057 virtual StateNode* getParent() const { return parent; } 00058 00059 protected: 00060 //!constructor, pass the class name and instance name to use 00061 StateNode(const std::string& classname, const std::string& name) : BehaviorBase(classname,name), parent(NULL), transitions(), issetup(false), retain(true), nodes() {} 00062 00063 //!called by a subnode when it is being DoStart()'ed 00064 virtual void transitionTo(StateNode* n); 00065 00066 //!called by a subnode when it is being DoStop()'ed 00067 virtual void transitionFrom(StateNode* n); 00068 00069 //Node Stuff: 00070 //! pointer to the machine that contains this node 00071 StateNode* parent; 00072 //! a vector of outgoing transitions 00073 std::vector<Transition*> transitions; 00074 00075 //Machine Stuff: 00076 //! this is set to true if the network has been setup but not destroyed (i.e. don't need to call setupSubNodes again) 00077 bool issetup; 00078 //! 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) 00079 bool retain; 00080 //! vector of StateNodes, just so they can be dereferenced again on DoStop() (unless retained) or ~StateNode() 00081 std::vector<StateNode*> nodes; 00082 00083 private: 00084 StateNode(const StateNode& node); //!< don't call this 00085 StateNode operator=(const StateNode& node); //!< don't call this 00086 }; 00087 00088 /*! @file 00089 * @brief Describes StateNode, which is both a state machine controller as well as a node within a state machine itself 00090 * @author ejt (Creator) 00091 * 00092 * $Author: ejt $ 00093 * $Name: tekkotsu-2_2_2 $ 00094 * $Revision: 1.16 $ 00095 * $State: Exp $ 00096 * $Date: 2004/12/17 05:50:56 $ 00097 */ 00098 00099 #endif |
Tekkotsu v2.2.2 |
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0 |