LocARNA-1.9.2
src/LocARNA/options.hh
Go to the documentation of this file.
00001 #ifndef LOCARNA_OPTIONS_HH
00002 #define LOCARNA_OPTIONS_HH
00003 
00004 #ifdef HAVE_CONFIG_H
00005 #include <config.h>
00006 #endif
00007 
00008 /*------------------------------------------------------------
00009 
00010   Copyright (C) 1999 by Sebastian Will.
00011 
00012   ------------------------------------------------------------*/
00013 
00026 #include <getopt.h>
00027 #include <string>
00028 
00029 namespace LocARNA {
00030 
00031 #ifndef FALSE
00032 #define FALSE 0
00033 #endif
00034 
00035 #ifndef TRUE
00036 #define TRUE 1
00037 #endif
00038 
00039 /* argument types */
00040 #define O_NO_ARG 0
00041 #define O_ARG_STRING 1
00042 #define O_ARG_INT 2
00043 #define O_ARG_FLOAT 3
00044 #define O_ARG_DOUBLE 4
00045 #define O_ARG_BOOL 5
00046 #define O_TEXT 10
00047 #define O_SECTION -1
00048 #define O_SECTION_HIDE -2
00049 
00050 #define O_NODEFAULT std::string("__")
00051 
00055     typedef struct {
00056         std::string longname; 
00057         char shortname;       
00058         bool *flag;     
00059         int arg_type;   
00060         void *argument; 
00061 
00062         std::string deflt; 
00063 
00064         std::string
00065             argname; 
00066         std::string description; 
00067     } option_def;
00068 
00069     /* longname==0 and shortname==0 and arg_type<=O_SECTION is not allowed for
00070      * regular options definition */
00071 
00072     /*
00073       Example for option_def array
00074 
00075       bool help;
00076       .
00077       .
00078       .
00079       int optVal_size;
00080       int default_size=1000;
00081 
00082       struct option_def my_options[] = {
00083       {"help",'h',&help,O_NO_ARG,0,O_NODEFAULT,0,"This help"},
00084       {"num",'n',&opt_num,O_ARG_INT,&optVal_num,O_NODEFAULT,0,"Some arbitrary
00085       number"},
00086       {"output",'o',0,O_ARG_STRING,&outputfile,O_NODEFAULT,
00087       "output-file", "File for output"}, // mandatory
00088       {"size",'s',0,O_ARG_INT,&optVal_size,"100","size","Size of problem"},
00089       {0,0,0,O_ARG_STRING,&inputfile,O_NODEFAULT,"input-file","File for input"},
00090       {0,0,0,0,0,0,0,0}
00091       };
00092 
00093       the last entry shows how to define non-option command line
00094       arguments. If there is more than one such definition, the order of
00095       those argument definitions is important. This is different to the
00096       option argument definitions.
00097 
00098     */
00099 
00100     /* ***********************************************************/
00101     /* error message */
00102     extern std::string O_error_msg;
00103 
00104     /* ***********************************************************/
00105     /* prototypes */
00106 
00108     bool
00109     process_options(int argc, char *argv[], option_def options[]);
00110 
00111     /* print a usage string */
00112     void
00113     print_usage(char *progname, option_def options[], bool terse = true);
00114 
00115     /* print a longer help */
00116     void
00117     print_help(char *progname, option_def options[]);
00118 
00119     const char *
00120     convert_arg_type(int arg_type);
00121 
00128     void
00129     print_galaxy_xml(char *progname, option_def options[]);
00130 
00136     void
00137     print_options(option_def options[]);
00138 
00139 } // end namespace LocARNA
00140 
00141 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends