LocARNA-2.0.0
options.hh
Go to the documentation of this file.
1 #ifndef LOCARNA_OPTIONS_HH
2 #define LOCARNA_OPTIONS_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 /*------------------------------------------------------------
9 
10  Copyright (C) 1999 by Sebastian Will.
11 
12  ------------------------------------------------------------*/
13 
26 #include <getopt.h>
27 #include <string>
28 
29 namespace LocARNA {
30 
31 #ifndef FALSE
32 #define FALSE 0
33 #endif
34 
35 #ifndef TRUE
36 #define TRUE 1
37 #endif
38 
39 /* argument types */
40 #define O_NO_ARG 0
41 #define O_ARG_STRING 1
42 #define O_ARG_INT 2
43 #define O_ARG_FLOAT 3
44 #define O_ARG_DOUBLE 4
45 #define O_ARG_BOOL 5
46 #define O_TEXT 10
47 #define O_SECTION -1
48 #define O_SECTION_HIDE -2
49 
50 #define O_NODEFAULT std::string("__")
51 
55  typedef struct {
56  std::string longname;
57  char shortname;
58  bool *flag;
59  int arg_type;
60  void *argument;
62  std::string deflt;
64  std::string
66  std::string description;
67  } option_def;
68 
69  /* longname==0 and shortname==0 and arg_type<=O_SECTION is not allowed for
70  * regular options definition */
71 
72  /*
73  Example for option_def array
74 
75  bool help;
76  .
77  .
78  .
79  int optVal_size;
80  int default_size=1000;
81 
82  struct option_def my_options[] = {
83  {"help",'h',&help,O_NO_ARG,0,O_NODEFAULT,0,"This help"},
84  {"num",'n',&opt_num,O_ARG_INT,&optVal_num,O_NODEFAULT,0,"Some arbitrary
85  number"},
86  {"output",'o',0,O_ARG_STRING,&outputfile,O_NODEFAULT,
87  "output-file", "File for output"}, // mandatory
88  {"size",'s',0,O_ARG_INT,&optVal_size,"100","size","Size of problem"},
89  {0,0,0,O_ARG_STRING,&inputfile,O_NODEFAULT,"input-file","File for input"},
90  {0,0,0,0,0,0,0,0}
91  };
92 
93  the last entry shows how to define non-option command line
94  arguments. If there is more than one such definition, the order of
95  those argument definitions is important. This is different to the
96  option argument definitions.
97 
98  */
99 
100  /* ***********************************************************/
101  /* error message */
102  extern std::string O_error_msg;
103 
104  /* ***********************************************************/
105  /* prototypes */
106 
108  bool
109  process_options(int argc, char *argv[], option_def options[]);
110 
111  /* print a usage string */
112  void
113  print_usage(char *progname, option_def options[], bool terse = true);
114 
115  /* print a longer help */
116  void
117  print_help(char *progname, option_def options[]);
118 
119  const char *
120  convert_arg_type(int arg_type);
121 
128  void
129  print_galaxy_xml(char *progname, option_def options[]);
130 
136  void
137  print_options(option_def options[]);
138 
139 } // end namespace LocARNA
140 
141 #endif
Definition: aligner.cc:15
void print_help(char *progname, option_def options[])
Definition: options.cc:682
void print_usage(char *progname, option_def options[], bool terse)
Definition: options.cc:419
void print_galaxy_xml(char *progname, option_def options[])
prints a galaxy wrapper in xml format
Definition: options.cc:446
bool process_options(int argc, char *argv[], option_def *options)
process options
Definition: options.cc:126
void print_options(option_def options[])
Definition: options.cc:327
std::string O_error_msg
string holding for error message
Definition: options.cc:47
Definition structure of an option.
Definition: options.hh:55
void * argument
Definition: options.hh:60
std::string longname
long option name
Definition: options.hh:56
int arg_type
type of argument
Definition: options.hh:59
std::string deflt
Definition: options.hh:62
bool * flag
pointer to flag that indicates if option given
Definition: options.hh:58
std::string description
optional description (shown in help)
Definition: options.hh:66
std::string argname
optional name for an argument (shown in usage string)
Definition: options.hh:65
char shortname
short option char
Definition: options.hh:57