State.hpp

Go to the documentation of this file.
00001 #ifndef wali_wfa_STATE_GUARD
00002 #define wali_wfa_STATE_GUARD 1
00003 
00004 /*!
00005  * @author Nicholas Kidd
00006  */
00007 
00008 #include "wali/Common.hpp"
00009 #include "wali/Printable.hpp"
00010 #include "wali/Markable.hpp"
00011 #include "wali/Countable.hpp"
00012 #include "wali/SemElem.hpp"
00013 #include "wali/wfa/TransSet.hpp"
00014 #include <list>
00015 
00016 namespace wali
00017 {
00018   namespace wpds
00019   {
00020     class WPDS;
00021     class DebugWPDS;
00022     namespace ewpds 
00023     {
00024       class EWPDS;
00025     }
00026   }
00027 
00028   namespace wfa
00029   {
00030     class CA;
00031     class State;
00032     //typedef State* state_t;
00033     //typedef ref_ptr<State> state_t;
00034 
00035     /*!
00036      * @class State
00037      *
00038      * This class represents a state in a CA. It extends
00039      * Markable so States can be in a Worklist for querying
00040      * a WFA.
00041      *
00042      * @see WFA
00043      * @see SemElem
00044      */
00045     class State : public Printable, public Markable, public Countable
00046     {
00047       public: // friends
00048         friend class WFA;
00049         friend class wali::wpds::WPDS;
00050         friend class wali::wpds::DebugWPDS;
00051         friend class wali::wpds::ewpds::EWPDS;
00052 
00053       public: // typedefs
00054         typedef TransSet::iterator iterator;
00055         typedef TransSet::const_iterator const_iterator;
00056 
00057       public: // static vars
00058         static int numStates;
00059         static const std::string XMLTag;
00060         static const std::string XMLInitialTag;
00061         static const std::string XMLFinalTag;
00062         static const std::string XMLNameTag;
00063 
00064       public:
00065 
00066         State();
00067 
00068         State( Key name, sem_elem_t W );
00069 
00070         State( const State& st );
00071 
00072         virtual ~State();
00073 
00074         /*!
00075          * overrides (implements) Printable::print method
00076          *
00077          * @param o the std::ostream this is written to
00078          * @return std::ostream passed in
00079          *
00080          * @see Printable
00081          */
00082         virtual std::ostream & print( std::ostream & o ) const;
00083 
00084         /*!
00085          * Add ITrans* t to the set of transitions that lead into this
00086          * State.
00087          */
00088         void addTrans( ITrans* t );
00089 
00090         /*!
00091          * Return a reference to the State's weight
00092          */
00093         sem_elem_t& weight() {
00094           return se;
00095         }
00096 
00097         const sem_elem_t& weight() const {
00098           return se;
00099         }
00100 
00101         /*!
00102          * Return reference to the State's delta
00103          */
00104         sem_elem_t& delta() {
00105           return delta_se;
00106         }
00107 
00108         /*!
00109          * Return the key associated with this State
00110          */
00111         Key name() const {
00112           return key;
00113         }
00114 
00115         iterator begin()
00116         {
00117           return transSet.begin();
00118         }
00119 
00120         iterator end()
00121         {
00122           return transSet.end();
00123         }
00124 
00125         const_iterator begin() const
00126         {
00127           return transSet.begin();
00128         }
00129 
00130         const_iterator end() const
00131         {
00132           return transSet.end();
00133         }
00134 
00135         bool eraseTrans(
00136             Key from,
00137             Key stack,
00138             Key to );
00139 
00140         bool eraseTrans( ITrans* t );
00141 
00142         void clearTransSet();
00143 
00144         /*!
00145          * @brief Used for placing States in STL containers
00146          */
00147         bool operator()( const State* a, const State* b ) const;
00148 
00149         TransSet& getTransSet()
00150         {
00151           return transSet;
00152         }
00153 
00154         const TransSet& getTransSet() const
00155         {
00156           return transSet;
00157         }
00158 
00159       protected:
00160         Key key;
00161         sem_elem_t se;
00162         sem_elem_t delta_se;
00163         sem_elem_t quasi;
00164         TransSet transSet;
00165         //!< Used by WFA::prune
00166         int tag;            
00167 
00168     }; //class State
00169 
00170   } // namespace wfa
00171 
00172 } // namespace wali
00173 
00174 #endif  // wali_wfa_STATE_GUARD
00175