KeySpace.hpp

Go to the documentation of this file.
00001 #ifndef wali_KEY_FACTORY_GUARD
00002 #define wali_KEY_FACTORY_GUARD 1
00003 
00004 /**
00005  * @author Nicholas Kidd
00006  */
00007 
00008 #include "wali/Common.hpp"
00009 #include "wali/HashMap.hpp"
00010 #include "wali/KeySource.hpp"   //! defines hm_hash<wali::KeySource*>
00011 #include <vector>
00012 
00013 namespace wali
00014 {
00015   /**
00016    * @class KeySpace
00017    */
00018   class KeySpace
00019   {
00020   public:
00021     KeySpace();
00022     
00023     ~KeySpace();
00024     
00025     /**
00026      * get_key returns the unique wali::Key associated with the
00027      * key_src_t ks. If no such key exists, a new wali::Key will be
00028      * generated.
00029      *
00030      * @see KeySource
00031      * @see wali::Key
00032      *
00033      * @param key_src_t ks for which a key is sought
00034      * @return wali::Key associated with parameter KeySource
00035      */
00036     wali::Key getKey( key_src_t ks );
00037     
00038     /**
00039      * Wrapper method for createing a StringSource and
00040      * inserting it into the KeySpace
00041      */
00042     wali::Key getKey( const std::string& s );
00043 
00044     /**
00045      * Wrapper method for createing a StringSource and
00046      * inserting it into the KeySpace
00047      */
00048     wali::Key getKey( const char* s );
00049 
00050     /**
00051      * Wrapper method for createing a IntSource and
00052      * inserting it into the KeySpace
00053      */
00054     wali::Key getKey( int i );
00055 
00056     /**
00057      * Wrapper method for createing a KeyPairSource and
00058      * inserting it into the KeySpace
00059      */
00060     wali::Key getKey( wali::Key k1, wali::Key k2 );
00061 
00062     /**
00063      * getKeySource retrieves the key_src_t associated to the
00064      * wali::Key key. If no such KeySource exists, then a NULL
00065      * pointer (0) is returned.
00066      *
00067      * @see KeySource
00068      * @see wali::Key
00069      *
00070      * @param key whose correpsonding key_src_t is desired
00071      * @return key_src_t associated with parameter key
00072      */
00073     key_src_t getKeySource( wali::Key key );
00074 
00075     /**
00076      * Reset the KeySpace. Clears all keys and deletes
00077      * all KeySources
00078      */
00079     void clear();
00080 
00081     /**
00082      * Return the number of allocated keys
00083      */
00084     size_t size();
00085 
00086     // @author Amanda Burton
00087     /** 
00088      * Wrapper method for creating a KeySetSource and
00089      * inserting it into the KeySpace
00090      */
00091     wali::Key getKey( std::set<wali::Key> kys );
00092 
00093     /**
00094      * Helper method that looks up the key and calls KeySource::print
00095      *
00096      * If abbreviate is true and the string representation of the
00097      * key being printed is greater than 20 characters, then the
00098      * actual numeric key is printed instead.
00099      *
00100      * @see KeySource
00101      */
00102     std::ostream& printKey( std::ostream& o, wali::Key key, bool abbreviate=false );
00103 
00104     /**
00105      * Return std::string rep of KeySource. Looks up the key and calls
00106      * KeySource::to_string(). 
00107      *
00108      * @see KeySource
00109      */
00110     std::string key2str( wali::Key key );
00111 
00112   protected:
00113     typedef wali::HashMap< key_src_t, wali::Key > ks_hash_map_t;
00114     typedef std::vector< key_src_t > ks_vector_t;
00115 
00116     /** 
00117      * keymap maps key_src_t to wali::Key. The wali::Key is
00118      * an index into the vector values
00119      */
00120     ks_hash_map_t keymap;
00121 
00122     /**
00123      * wali::Key's are guaranteed to be unique w.r.t. this KeySpace
00124      * because they are indexes into the vector values. KeySource's
00125      * are retrieved by a lookup into values
00126      */
00127     ks_vector_t values;
00128 
00129   }; // class KeySpace
00130 
00131 } // namespace wali
00132 
00133 #endif  // wali_KEY_FACTORY_GUARD
00134