00001 #ifndef wali_wfa_DECORATOR_TRANS_GUARD 00002 #define wali_wfa_DECORATOR_TRANS_GUARD 1 00003 00004 /*! 00005 * @author Nicholas Kidd 00006 */ 00007 00008 #include <iostream> 00009 #include "wali/Common.hpp" 00010 #include "wali/Markable.hpp" 00011 #include "wali/Printable.hpp" 00012 #include "wali/SemElem.hpp" 00013 #include "wali/KeyContainer.hpp" 00014 #include "wali/wfa/ITrans.hpp" 00015 00016 namespace wali 00017 { 00018 namespace wfa 00019 { 00020 /*! 00021 * @class DecoratorTrans 00022 * 00023 * A DecoratorTrans assumes ownership of its delegate, and the destructor 00024 * deletes the delegate. 00025 * 00026 * Note, delegate transitions should 00027 * <b>NOT BE SHARED</b> by two or more decorators. 00028 * 00029 */ 00030 00031 class DecoratorTrans : public ITrans 00032 { 00033 public: 00034 DecoratorTrans( ITrans* it ) : delegate(it) { 00035 } 00036 00037 virtual ~DecoratorTrans() { 00038 delete delegate; 00039 } 00040 00041 virtual ITrans* copy() const = 0; 00042 virtual ITrans* copy(Key fromst, Key stk, Key tost) const = 0; 00043 00044 // 00045 // getters (const) 00046 // 00047 /*! @return const Key of from state */ 00048 virtual Key from() const throw() { 00049 return delegate->from(); 00050 } 00051 00052 /*! @return const Key of stack symbol */ 00053 virtual Key stack() const throw() { 00054 return delegate->stack(); 00055 } 00056 00057 /*! @return const Key of to state */ 00058 virtual Key to() const throw() { 00059 return delegate->to(); 00060 } 00061 00062 /*! @return const sem_elem_t of ITrans */ 00063 virtual const sem_elem_t weight() const throw() { 00064 return delegate->weight(); 00065 } 00066 00067 /*! 00068 * @return const sem_elem_t delta of ITrans 00069 * 00070 * delta is used in computing fixpoints 00071 */ 00072 virtual const sem_elem_t getDelta() const throw() { 00073 return delegate->getDelta(); 00074 } 00075 00076 // 00077 // getters (non const) 00078 // 00079 /*! @return Key of from state */ 00080 virtual Key from() throw() { 00081 return delegate->from(); 00082 } 00083 00084 /*! @return Key of stack symbol */ 00085 virtual Key stack() throw() { 00086 return delegate->stack(); 00087 } 00088 00089 /*! @return Key of to state */ 00090 virtual Key to() throw() { 00091 return delegate->to(); 00092 } 00093 00094 /*! @return sem_elem_t of ITrans */ 00095 virtual sem_elem_t weight() throw() { 00096 return delegate->weight(); 00097 } 00098 00099 /*! 00100 * @return sem_elem_t delta of ITrans 00101 * 00102 * delta is used in computing fixpoints 00103 */ 00104 virtual sem_elem_t getDelta() throw() { 00105 return delegate->getDelta(); 00106 } 00107 00108 // 00109 // setters 00110 // 00111 /*! 00112 * Set weight and delta of this ITrans 00113 * to be param [w]. 00114 * 00115 * @param sem_elem_t for new weight and delta 00116 * 00117 * @return void 00118 */ 00119 virtual void setWeight( sem_elem_t w ) { 00120 delegate->setWeight(w); 00121 } 00122 00123 /*! 00124 * Set the delta value for the ITrans. 00125 */ 00126 virtual void setDelta( const sem_elem_t w ) { 00127 delegate->setDelta( w ); 00128 } 00129 00130 /*! 00131 * Print the transition 00132 */ 00133 virtual std::ostream & print(std::ostream &o) const { 00134 return delegate->print( o ); 00135 } 00136 00137 /*! 00138 * When inserting a transition into an automaton, 00139 * the WFA will check to see if the transition 00140 * already exists. If so, let told be the existing transition 00141 * and tnew be the transition being inserted. Then 00142 * the WFA invokes: 00143 * <code> 00144 * told->combineTrans( tnew ) 00145 * </code> 00146 * 00147 * @param ITrans* the new ITrans to be "absorbed" 00148 */ 00149 virtual void combineTrans( ITrans* tp ) { 00150 delegate->combineTrans( tp ); 00151 } 00152 00153 00154 /*! 00155 * Return const referenct to this transitions KeyPair 00156 * 00157 * The KeyPair holds the from state and stack symbol. 00158 * 00159 * @see KeyPair 00160 * @return const KeyPair reference 00161 */ 00162 virtual const KeyPair& keypair() const throw() { 00163 return delegate->keypair(); 00164 } 00165 00166 /*! 00167 * @brief return true if the transition has been modified 00168 * 00169 * A ITrans is considered modified if when its weight changes. This 00170 * includes the initial creation of a ITrans object. This follows 00171 * from the fact that all ITrans can be considered (abstractly) 00172 * created with a weight of ZERO 00173 * 00174 * @return true if this transition has been modified 00175 */ 00176 virtual bool modified() const throw() { 00177 return delegate->modified(); 00178 } 00179 00180 /*! 00181 * @return A null pointer. 00182 */ 00183 virtual wpds::Config* getConfig() const throw() { 00184 return delegate->getConfig(); 00185 } 00186 00187 /*! 00188 * Set this ITrans's Config to c. 00189 * @return void 00190 */ 00191 virtual void setConfig( wpds::Config* c ) { 00192 delegate->setConfig( c ); 00193 } 00194 00195 /*! 00196 * This is used by (E)WPDS::poststar 00197 * during epsilon-transistion contraction. 00198 * The base case is: 00199 * this->weight()->extend(se) 00200 */ 00201 virtual sem_elem_t poststar_eps_closure( sem_elem_t se ) { 00202 return delegate->poststar_eps_closure(se); 00203 } 00204 00205 //******************** 00206 // Markable delegation 00207 virtual void mark() const throw() { 00208 delegate->mark(); 00209 } 00210 00211 virtual void unmark() const throw() { 00212 delegate->unmark(); 00213 } 00214 00215 virtual bool marked() const throw() { 00216 return delegate->marked(); 00217 } 00218 00219 protected: 00220 /*! @return pointer to the delegating ITrans */ 00221 ITrans* getDelegate() { 00222 return delegate; 00223 } 00224 00225 /*! @return const pointer to the delegating ITrans */ 00226 const ITrans* getDelegate() const { 00227 return delegate; 00228 } 00229 00230 protected: 00231 ITrans* delegate; //! < Decorator delegates all ITrans methods to the delegate 00232 00233 }; 00234 00235 } // namespace wfa 00236 00237 } // namespace wali 00238 00239 #endif // wali_wfa_DECORATOR_TRANS_GUARD 00240