Main Page | Alphabetical List | Class List | File List | Class Members

Argument_helper.h

00001 /*
00002 *
00003 * Argument Helper
00004 *
00005 * Daniel Russel drussel@alumni.princeton.edu
00006 * Stanford University
00007 *
00008 *
00009 * This software is not subject to copyright protection and is in the
00010 * public domain. Neither Stanford nor the author assume any
00011 * responsibility whatsoever for its use by other parties, and makes no
00012 * guarantees, expressed or implied, about its quality, reliability, or
00013 * any other characteristic.
00014 *
00015 */
00016 
00017 #ifndef _DSR_ARGS_H_
00018 #define _DSR_ARGS_H_
00019 #include <vector>
00020 #include <map>
00021 #include <list>
00022 #include <string>
00023 
00024 
00083 namespace dsr{
00084   extern bool verbose, VERBOSE;
00085 
00087 
00090   class Argument_helper{
00091   private:
00092     class Argument_target;
00093 
00094  
00095     class FlagTarget;
00096     class DoubleTarget;
00097     class IntTarget;
00098     class UIntTarget;
00099     class StringTarget;
00100     class CharTarget;
00101     class StringVectorTarget;
00102 
00103   public:
00104     Argument_helper();
00106     void new_flag(char key, const char *long_name, const char *description,bool &dest);
00107 
00109     void new_string( const char *arg_description, const char *description, std::string &dest);
00111     void new_named_string(char key, const char *long_name,
00112                           const char *arg_description,
00113                           const char *description,  std::string &dest);
00115     void new_optional_string( const char *arg_description, const char *description, std::string &dest);
00116 
00118     void new_int( const char *arg_description, const char *description, int &dest);
00120     void new_named_int(char key, const char *long_name,const char *value_name,
00121                        const char *description,
00122                        int &dest);
00124     void new_optional_int(const char *value_name,
00125                           const char *description,
00126                           int &dest);
00127 
00129     void new_double(const char *value_name,
00130                     const char *description,
00131                     double &dest);
00132 
00134     void new_named_double(char key, const char *long_name,const char *value_name,
00135                           const char *description,
00136                           double &dest);
00138     void new_optional_double(const char *value_name,
00139                              const char *description,
00140                              double &dest);
00141 
00143     void new_char(const char *value_name,
00144                                 const char *description,
00145                                 char &dest);
00147     void new_named_char(char key, const char *long_name,const char *value_name,
00148                            const char *description,
00149                            char &dest);
00151     void new_optional_char(const char *value_name,
00152                            const char *description,
00153                            char &dest);
00154 
00156     void new_unsigned_int(const char *value_name, const char *description,
00157                           unsigned int &dest);
00159     void new_optional_unsigned_int(const char *value_name, const char *description,
00160                                 unsigned int &dest);
00162     void new_named_unsigned_int(char key, const char *long_name,
00163                                    const char *value_name, const char *description,
00164                                    unsigned int &dest);
00165 
00166 
00168 
00171     void new_named_string_vector(char key, const char *long_name,
00172                                  const char *value_name, const char *description,
00173                                  std::vector<std::string> &dest);
00174 
00176 
00180     void set_string_vector(const char *arg_description, const char *description, std::vector<std::string> &dest);
00181 
00183     void set_author(const char *author);
00184 
00186     void set_description(const char *descr);
00187 
00189     void set_version(float v);
00190     void set_version(const char *str);
00191 
00193     void set_name(const char *name);
00194 
00196     void set_build_date(const char *date);
00197 
00199 
00202     void process(int argc, const char **argv);
00203     void process(int argc, char **argv){
00204       process(argc, const_cast<const char **>(argv));
00205     }
00207     void write_usage(std::ostream &out) const;
00209     void write_values(std::ostream &out) const;
00210     
00211     ~Argument_helper();
00212   protected:
00213     typedef std::map<char, Argument_target*> SMap;
00214     typedef std::map<std::string, Argument_target*> LMap;
00215     typedef std::vector<Argument_target*> UVect;
00216     // A map from short names to arguments.
00217     SMap short_names_;
00218     // A map from long names to arguments.
00219     LMap long_names_;
00220     std::string author_;
00221     std::string name_;
00222     std::string description_;
00223     std::string date_;
00224     float version_;
00225     bool seen_end_named_;
00226     // List of unnamed arguments
00227     std::vector<Argument_target*> unnamed_arguments_;
00228     std::vector<Argument_target*> optional_unnamed_arguments_;
00229     std::vector<Argument_target*> all_arguments_;
00230     std::string extra_arguments_descr_;
00231     std::string extra_arguments_arg_descr_;
00232     std::vector<std::string> *extra_arguments_;
00233     std::vector<Argument_target*>::iterator current_unnamed_;
00234     std::vector<Argument_target*>::iterator current_optional_unnamed_;
00235     void new_argument_target(Argument_target*);
00236     void handle_error() const;
00237   private:
00238     Argument_helper(const Argument_helper &){};
00239     const Argument_helper& operator=(const Argument_helper &){return *this;}
00240   };
00241   
00242 }
00244 
00247 #define ARGUMENT_HELPER_BASICS(ah) ah.set_author("Daniel Russel, drussel@stanford.edu");\
00248 ah.set_version(VERSION);\
00249 ah.set_build_date(__DATE__);
00250 
00251 #endif

Generated on Thu Oct 21 17:29:54 2004 for Argument_helper by doxygen 1.3.6