TransFunctor.hpp

Go to the documentation of this file.
00001 #ifndef wali_wfa_TRANS_FUNCTOR_GUARD
00002 #define wali_wfa_TRANS_FUNCTOR_GUARD 1
00003 #pragma once
00004 
00005 /*!
00006  * @author Nicholas Kidd
00007  */
00008 
00009 #include <iostream>
00010 #include <map>
00011 #include "wali/HashMap.hpp"
00012 #include "wali/wfa/TransSet.hpp"
00013 
00014 namespace wali
00015 {
00016   namespace wfa
00017   {
00018     class Trans;    //! < Needed by all (Const)TransFunctors
00019     class WFA;      //! < Needed by TransCopier
00020 
00021     /*!
00022      * @class TransFunctor
00023      *
00024      * Pure virtual class exporting the interface used
00025      * by wali::wfa::WFA::for_each. This class allows
00026      * for modification of the WFA's Trans objects in place.
00027      *
00028      * @see Trans
00029      * @see WFA
00030      */
00031     class TransFunctor
00032     {
00033       public:
00034         virtual ~TransFunctor() {}
00035 
00036         virtual void operator()( ITrans* t ) = 0;
00037     }; // class TransFunctor
00038 
00039     /*!
00040      * @class ConstTransFunctor
00041      *
00042      * Pure virtual class exporting the interface used by
00043      * wali::wfa::WFA::for_each. This class DOES NOT ALLOW for
00044      * modification of the WFA's Trans objects.
00045      *
00046      * @see Trans
00047      * @see WFA
00048      */
00049     class ConstTransFunctor
00050     {
00051       public:
00052         virtual ~ConstTransFunctor() {}
00053 
00054         virtual void operator()( const ITrans* t ) = 0;
00055     }; // class ConstTransFunctor
00056 
00057     /** 
00058      *
00059      */
00060     class TransCounter : public wali::wfa::ConstTransFunctor
00061     {
00062       int numTrans;
00063     public:
00064       TransCounter( ) : numTrans(0) {}
00065       virtual ~TransCounter() {}
00066 
00067       virtual void operator()( const ITrans* t )
00068       {
00069         (void) t;
00070         numTrans++;
00071       }
00072 
00073       int getNumTrans( )
00074       {
00075         return numTrans;
00076       }
00077     };
00078 
00079     /*!
00080      * @class TransPrinter
00081      *
00082      * Writes Transes to its std::ostream member var. Used
00083      * by wali::wfa::WFA::print. Calls Trans::print( std::ostream& ).
00084      *
00085      * @see ConstTransFunctor
00086      * @see Trans
00087      * @see WFA
00088      */
00089     class TransPrinter : public ConstTransFunctor
00090     {
00091       std::ostream& o;
00092       public:
00093       TransPrinter( std::ostream & o_ ) : o(o_) {}
00094 
00095       virtual ~TransPrinter() {}
00096 
00097       virtual void operator()( const ITrans* t );
00098     }; // class TransPrinter
00099 
00100     /*!
00101      * @class TransCopier
00102      *
00103      * Inserts a copy of the passed in Trans into its member
00104      * var WFA. Used by WFA copy constructor and operator=.
00105      *
00106      * @see ConstTransFunctor
00107      * @see Trans
00108      * @see WFA
00109      */
00110     class TransCopier : public ConstTransFunctor
00111     {
00112       WFA & fa;
00113       public:
00114       TransCopier( WFA & fa_ ) : fa(fa_) {}
00115 
00116       virtual ~TransCopier() {}
00117 
00118       virtual void operator()( const ITrans* t );
00119     }; // class TransCopier
00120 
00121     /*!
00122      * @class TransDuplicator
00123      *
00124      * Used by WFA::duplicateStates
00125      * Changes transition states
00126      *
00127      * @see ConstTransFunctor
00128      * @see Trans
00129      * @see WFA
00130      */
00131     class TransDuplicator : public ConstTransFunctor
00132     {
00133       WFA & fa;
00134       std::map< Key, Key > &dup;
00135       public:
00136       TransDuplicator( WFA & fa_, std::map< Key, Key > &dup_ ) : fa(fa_), dup(dup_) {}
00137 
00138       virtual ~TransDuplicator() {}
00139 
00140       virtual void operator()( const ITrans* t );
00141     }; // class TransDuplicator
00142 
00143 
00144     /*!
00145      * @class TransDeleter
00146      *
00147      * Calls delete on each ITrans* object passed to it.
00148      *
00149      * @see TransFunctor
00150      */
00151     class TransDeleter : public TransFunctor
00152     {
00153       public:
00154         virtual ~TransDeleter() {}
00155 
00156         virtual void operator()( ITrans* t );
00157     }; // class TransDeleter
00158 
00159 
00160     /*!
00161      * @class TransZeroWeight
00162      *
00163      * Accumulates the set of transitions with zero weight
00164      *
00165      * @see TransFunctor
00166      */
00167     class TransZeroWeight : public TransFunctor
00168     {
00169       public:
00170         TransSet zeroWeightTrans;
00171         virtual ~TransZeroWeight() {}
00172 
00173         virtual void operator()( ITrans* t );
00174     }; // class TransZeroWeight
00175 
00176     /*!
00177      * @class TransDotty
00178      * Prints each Trans to std::ostream in dotty format.
00179      */
00180     class TransDotty : public ConstTransFunctor
00181     {
00182       public:
00183         std::ostream& o;
00184         bool print_weights;
00185 
00186         TransDotty( std::ostream& o, bool print_weights );
00187 
00188         virtual ~TransDotty() {}
00189 
00190         virtual void operator()( const ITrans* t );
00191     }; // class TransDotty
00192 
00193     /*!
00194      * @class TransMarshaller
00195      * Writes a Trans in xml format
00196      */
00197     class TransMarshaller : public ConstTransFunctor
00198     {
00199       public:
00200         std::ostream& o;
00201 
00202         TransMarshaller( std::ostream& o );
00203 
00204         virtual ~TransMarshaller() {}
00205 
00206         virtual void operator()( const ITrans* t );
00207     }; // class TransMarshaller
00208 
00209     /*!
00210      * @class StackHasher
00211      * Hashes the transitions on their stack symbol.
00212      * Used by WFA::intersect
00213      */
00214 
00215     class StackHasher : public TransFunctor
00216     {
00217       public:
00218         typedef wali::HashMap< Key , TransSet > stackmap_t;
00219         typedef stackmap_t::iterator iterator;
00220         stackmap_t stackmap;
00221 
00222         virtual ~StackHasher() {}
00223 
00224         virtual void operator()( ITrans* t );
00225 
00226         iterator begin();
00227         iterator end();
00228         iterator find( Key k );
00229 
00230     }; // class StackHasher
00231 
00232   } // namespace wfa
00233 
00234 } // namespace wali
00235 
00236 #endif  // wali_wfa_TRANS_FUNCTOR_GUARD
00237