ParseArgv.hpp

Go to the documentation of this file.
00001 #ifndef wali_util_PARSE_ARG_V_GUARD
00002 #define wali_util_PARSE_ARG_V_GUARD 1
00003 
00004 #include <iostream>
00005 #include <map>
00006 #include <string>
00007 
00008 namespace wali
00009 {
00010   namespace util
00011   {
00012 
00013     /**
00014      *  Takes command line arguments and splits each one on a non escaped
00015      *  equal sign ('=').  ie. key=value
00016      *  Inserts the pair (key,val) into a map.  If no equal sign is present
00017      *  inserts (key,"") into the map.
00018      * 
00019      *  - get* methods do not side effect their second parameter if the key
00020      *       does not exist
00021      */ 
00022     class ParseArgv
00023     {
00024 
00025       public:
00026         ParseArgv( int argc,char **argv );
00027         virtual ~ParseArgv();
00028 
00029         virtual bool get(
00030             const std::string &key,
00031             std::string &value ) const;
00032 
00033         virtual bool geti( const std::string &key, int &i ) const;
00034 
00035         virtual bool exists( const std::string &key ) const;
00036 
00037 
00038       protected:
00039         typedef std::map< std::string, std::string > pamap_t;
00040         virtual void parse();
00041 
00042       protected:
00043         int argc;
00044         char ** argv;
00045         pamap_t m;
00046 
00047     }; // class ParseArgv
00048 
00049   } // namespace util
00050 
00051 } // namespace wali
00052 
00053 #endif  // wali_util_PARSE_ARG_V_GUARD
00054