Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
Transition.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_Transition_h_ 00003 #define INCLUDED_Transition_h_ 00004 00005 #include "BehaviorBase.h" 00006 #include "Wireless/Socket.h" 00007 #include <vector> 00008 00009 class StateNode; 00010 00011 //! Represents a transition between StateNodes. 00012 /*! This is an abstract class - you'll want to subclass it to put 00013 * conditions on the transitions. Transitions are "smart" - they are 00014 * behaviors in and of themselves and can listen for events and use 00015 * the standard DoStart/DoStop interface. Based on the events they 00016 * receive, they can fire() themselves and cause a state 00017 * transition. 00018 * 00019 * DoStart() will be called when this transition is 'active' - it 00020 * should listen/monitor for the transition it represents until 00021 * DoStop() is called. 00022 * 00023 * If the conditions are satisified for a transition, you should call 00024 * fire() to do the appropriate notifications. 00025 * 00026 * Also note that a transition can have multiple sources and 00027 * destinations. See fire(). 00028 * 00029 * When setting up, the flow of additions follows the flow of 00030 * control. In other words, you add a transition to a source, and 00031 * you add a destination to a transition. This makes the code 00032 * simpler because it doesn't have to worry about recursive looping 00033 * depending whether the source was added to the transition or the 00034 * transition was added to the source. Confusing? Exactly. 00035 */ 00036 class Transition : public BehaviorBase { 00037 friend class StateNode; 00038 public: 00039 //!constructor 00040 Transition() : BehaviorBase(), srcs(), dsts(), sound() {} 00041 //!constructor, specify destination StateNode (ignores NULL) 00042 Transition(StateNode* destination) : BehaviorBase(), srcs(), dsts(), sound() { 00043 addDestination(destination); 00044 } 00045 //!copy constructor, just in case you need it 00046 Transition(const Transition& t) : BehaviorBase(t), srcs(t.srcs), dsts(t.dsts), sound(t.sound) {} 00047 00048 //!assignment operator (only does shallow copy) 00049 Transition& operator=(const Transition& t) { BehaviorBase::operator=(t); srcs=t.srcs; dsts=t.dsts; sound=t.sound; return *this; } 00050 00051 //!destructor 00052 virtual ~Transition() {} 00053 00054 //!call this when the transition should be made, base class version simply calls StateNode::DoStop() on each active of #srcs and StateNode::DoStart() on each inactive of #dsts, but you can override. 00055 virtual void fire(); 00056 00057 //!deprecated: use #fire() instead 00058 virtual void activate() { 00059 serr->printf("Transition::activate() is deprecated. Use Transition::fire() instead.\n"); 00060 fire(); 00061 } 00062 00063 virtual std::vector<StateNode*>& getSources() { return srcs; } //!< returns a user-modifiable reference to the current source list 00064 virtual const std::vector<StateNode*>& getSources() const { return srcs; } //!< returns a const reference to the current source list 00065 00066 virtual void addDestination(StateNode* destination) { if(destination!=NULL) dsts.push_back(destination); } //!< if @a destination is non-null, add it to the destination list 00067 virtual std::vector<StateNode*>& getDestinations() { return dsts; } //!< returns a user-modifiable reference to the current destination list 00068 virtual const std::vector<StateNode*>& getDestinations() const { return dsts; } //!< returns a const reference to the current destination list 00069 00070 virtual void setSound(const std::string& snd) { sound=snd; } //!< set a sound file to be played upon activation; you might want to preload this in the parent node; empty string to turn off 00071 virtual std::string getSound() { return sound; } //!< returns the current sound file 00072 00073 protected: 00074 //! if @a source is non-null, add it to the source list 00075 /*! Only StateNodes should be calling this - you add a transition to a source, not a source to a transition. 00076 * @see StateNode::addTransition() */ 00077 virtual void addSource(StateNode* source) { if(source!=NULL) srcs.push_back(source); } 00078 00079 std::vector<StateNode*> srcs; //!< the node being transitioned from 00080 std::vector<StateNode*> dsts; //!< the node being transitioned to 00081 std::string sound; //!< sound to play on transitioning 00082 }; 00083 00084 /*! @file 00085 * @brief Describes Transition, represents a transition between StateNodes. 00086 * @author ejt (Creator) 00087 * 00088 * $Author: dst $ 00089 * $Name: tekkotsu-2_2 $ 00090 * $Revision: 1.5 $ 00091 * $State: Exp $ 00092 * $Date: 2004/10/04 22:59:57 $ 00093 */ 00094 00095 #endif |
Tekkotsu v2.2 |
Generated Tue Oct 19 14:19:16 2004 by Doxygen 1.3.9.1 |