Config.hpp

Go to the documentation of this file.
00001 #ifndef wali_wpds_CONFIG_GUARD
00002 #define wali_wpds_CONFIG_GUARD 1
00003 
00004 /*!
00005  * @author Nicholas Kidd
00006  */
00007 
00008 #include <list>
00009 #include <string>
00010 #include "wali/Common.hpp"
00011 #include "wali/Printable.hpp"
00012 #include "wali/KeyContainer.hpp"
00013 #include "wali/wpds/Rule.hpp"
00014 
00015 namespace wali
00016 {
00017 
00018   namespace wpds
00019   {
00020 
00021     namespace ewpds 
00022     {
00023       class ERule;
00024       class EWPDS;
00025     }
00026 
00027     class WPDS;
00028 
00029     /*! @class Config
00030      *
00031      * This class represents a Surface Configuration in the WPDS's
00032      * configuration space.  It only keeps track of the state and top
00033      * of stack symbol.  All of the wpds::Config's form a graph that
00034      * is connected forward and back by the list of Rules.
00035      *
00036      * @see KeyPair
00037      * @see Rule
00038      * @see WPDS
00039      */
00040     class Config : public Printable
00041     {
00042 
00043       public:
00044         friend class Rule;
00045         friend class ewpds::ERule;
00046         friend class WPDS;
00047         friend class ewpds::EWPDS;
00048 
00049         //
00050         // Config does not use iterators in the sense that list uses
00051         // them. It has 2 lists, one w/ rules going forward and 1 w/
00052         // lists going backwards. When iterating over backward rules,
00053         // we use a reverse_iterator in the hopes that the different
00054         // types will avoid some typos (because rbegin/rend look so
00055         // much like begin and end
00056         //
00057 
00058         // Forward iterators
00059         typedef std::list< rule_t >::const_iterator const_iterator;
00060         typedef std::list< rule_t >::iterator iterator;
00061         // Backward iterators
00062         typedef std::list< rule_t >::const_reverse_iterator const_reverse_iterator;
00063         typedef std::list< rule_t >::reverse_iterator reverse_iterator;
00064 
00065         static int numConfigs;
00066 
00067       public:
00068         /*! @brief Config constructor
00069         */
00070         Config( wali_key_t state, wali_key_t stack );
00071 
00072         virtual ~Config();
00073 
00074         bool operator ==(const Config &c2) const throw() {
00075           return (kp == c2.kp);
00076         }
00077 
00078         /*!
00079          * @return reference KeyPair for this Config
00080          *
00081          * @see KeyPair
00082          */
00083         const KeyPair & keypair() const throw() {
00084           return kp;
00085         }
00086 
00087         /*! @return the state key for this Config */
00088         wali_key_t state() const throw() {
00089           return kp.first;
00090         }
00091 
00092         /*! @return the stack key for this Config */
00093         wali_key_t stack() const throw() {
00094           return kp.second;
00095         }
00096 
00097         /*! @brief insert a rule into forwards list */
00098         void insert(  rule_t r ) throw() {
00099           { // BEGIN DEBUGGING
00100             assert( r->from_state() == state() );
00101             assert( r->from_stack() == stack() );
00102           } // END DEBUGGING
00103 
00104           fwrules.push_back(r);
00105         }
00106 
00107         /*! @brief insert a rule into backwards list */
00108         void rinsert(  rule_t r ) throw() {
00109           { // BEGIN DEBUGGING
00110             assert( r->to_state() == state() );
00111             assert( r->to_stack1() == stack() );
00112           } // END DEBUGGING
00113 
00114           bwrules.push_back(r);
00115         }
00116 
00117         /*!
00118          * @return const iterator to list of forward rules
00119          *
00120          * @see Rule
00121          * @see std::list
00122          */
00123         const_iterator begin() const throw() {
00124           return fwrules.begin();
00125         }
00126 
00127         /*!
00128          * @return an end iterator to list of forward rules
00129          *
00130          * @see Rule
00131          * @see std::list
00132          */
00133         const_iterator end() const throw() {
00134           return fwrules.end();
00135         }
00136 
00137         /*!
00138          * @return const iterator to list of backward rules
00139          *
00140          * @see Rule
00141          * @see std::list
00142          */
00143         const_reverse_iterator rbegin() const throw() {
00144           return bwrules.rbegin();
00145         }
00146 
00147         /*!
00148          * @return an end iterator to list of backward rules
00149          *
00150          * @see Rule
00151          * @see std::list
00152          */
00153         const_reverse_iterator rend() const throw() {
00154           return bwrules.rend();
00155         }
00156 
00157         /*!
00158          * @return a iterator to list of forward rules
00159          *
00160          * @see Rule
00161          * @see std::list
00162          */
00163         iterator begin() throw() {
00164           return fwrules.begin();
00165         }
00166 
00167         /*!
00168          * @return an end iterator to list of forward rules
00169          *
00170          * @see Rule
00171          * @see std::list
00172          */
00173         iterator end() throw() {
00174           return fwrules.end();
00175         }
00176 
00177         /*!
00178          * @return iterator to list of backward rules
00179          *
00180          * @see Rule
00181          * @see std::list
00182          */
00183         reverse_iterator rbegin() throw() {
00184           return bwrules.rbegin();
00185         }
00186 
00187         /*!
00188          * @return an end iterator to list of backward rules
00189          *
00190          * @see Rule
00191          * @see std::list
00192          */
00193         reverse_iterator rend() throw() {
00194           return bwrules.rend();
00195         }
00196 
00197         /*!
00198          * Implements Printable::print. Writes this Config
00199          * to the passed in ostream.
00200          *
00201          * @param o the std::ostream Config is written to
00202          * @return std::ostream Config was written to 
00203          *
00204          * @see Printable
00205          */
00206         virtual std::ostream & print( std::ostream & o ) const;
00207 
00208         /*!
00209          * @return std::string XML representation of this Config
00210          */
00211         std::ostream & marshall( std::ostream & o ) const;
00212 
00213       protected:
00214 
00215         KeyPair kp;                     //! < pair of state and stack symbol
00216         std::list< rule_t > fwrules;    //! < forward rules
00217         std::list< rule_t > bwrules;    //! < backward rules
00218     };
00219 
00220   } // namespace wpds
00221 
00222 } // namespace wali
00223 
00224 #endif  // wali_wpds_CONFIG_GUARD
00225