NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkCommandLineParser.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkCommandLineParser_h
16 #define niftkCommandLineParser_h
17 
18 #include <NifTKConfigure.h>
20 
21 #include <ostream>
22 #include <stdio.h>
23 #include <string>
24 
25 namespace niftk
26 {
27 
28 
29 /* For use in flag argument of printhelp() */
30 #define HLP_BRIEF 0x0000
31 #define HLP_VERBOSE 0x0001
32 
33 
68  int type;
69  const char *key;
70  const char *parm;
71  const char *helpmsg;
72 };
73 
74 /* type field takes the following arguments. */
75 
76 #define OPT_TYPEMASK 0x00ff /* Mask type of opt. */
77 
78 
85 
86 #define OPT_SWITCH 0x0000
87 #define OPT_INT 0x0001
88 #define OPT_FLOAT 0x0002
89 #define OPT_STRING 0x0003
90 #define OPT_VARIANT 0x0004
91 #define OPT_MULT 0x0005
92 #define OPT_DOUBLE 0x0006
93 #define OPT_LONG 0x0007
94 #define OPT_INTx2 0x0008
95 #define OPT_INTx3 0x0009
96 #define OPT_INTx4 0x000a
97 #define OPT_FLOATx2 0x000b
98 #define OPT_FLOATx3 0x000c
99 #define OPT_FLOATx4 0x000d
100 #define OPT_DOUBLEx2 0x000e
101 #define OPT_DOUBLEx3 0x000f
102 #define OPT_DOUBLEx4 0x0010
103 #define OPT_DONE (~0)
104 
105 
106 
112 
113 #define OPT_CHARBCK 0x0800
114 #define OPT_UNIQUE 0x1000
115 #define OPT_LONELY 0x2000
116 #define OPT_REQ 0x4000
117 #define OPT_NIN 0x8000
118 #define OPT_MORETYPE 0x0011
119 
120 
123 #define OPT_MORE (OPT_MORETYPE | OPT_LONELY)
124 
125 
126 
132 
133 union ad {
134  long along;
135  double afloat;
136  char *astr;
137  int *mult;
138  int *pint;
139  float *pfloat;
140  double *pdouble;
141 };
142 
143 struct ml {
144  struct ml *next;
146  int num;
147  union ad data;
148 };
150 
151 #define ML_END (~0)
152 
170 
171 public:
172 
175  CommandLineParser(int argc, char *argv[],
177  struct CommandLineArgumentDescription *clArgList, bool flgVerbose);
178 
180  ~CommandLineParser();
181 
184 
186  void PrintUsage(void) {PrintHelp(m_OptionList->opt, HLP_VERBOSE);}
188 
191  int GetArgument(int, void *);
192 
194  int GetArgument(int, bool &value);
196  int GetArgument(int, unsigned int &value);
198  int GetArgument(int, int &value);
200  int GetArgument(int, int *&value);
202  int GetArgument(int, float &value);
204  int GetArgument(int, float *&value);
206  int GetArgument(int, double &value);
208  int GetArgument(int, double *&value);
210  int GetArgument(int, char *&value);
212  int GetArgument(int, std::string &value);
214  int GetArgument(int, long int &value);
215 
216 private:
217 
219  int m_Argc;
221  char **m_Argv;
222 
224  char *m_ProgramName;
225 
227  struct ml *m_OptionList;
228 
230  int m_flgVerbose;
231 
233  void PrintHelp(struct CommandLineArgumentDescription *clArgList, int flag);
234 
236  struct ml *ParseArguments(int argc, char *argv[],
237  struct CommandLineArgumentDescription *clArgList);
238 
240  void FreeArguments(struct ml *mlist);
241 
242  int MakeOption(char *str, struct CommandLineArgumentDescription *opt, int *delayed);
243  void ParseStandardArguments(char *key, struct CommandLineArgumentDescription *optlist);
244  void ReadParameter(char *argv[], int arg, int type, struct ml *ml);
245 
246  struct ml *allocmlist(struct CommandLineArgumentDescription *);
247  struct ml *locateml(struct ml *, struct CommandLineArgumentDescription *);
248  struct ml *createml(struct ml *, struct CommandLineArgumentDescription *);
249  int incarg(int, int);
250  void chknotopt(char *argv[], int arg);
251  int *get_intx2(char *str);
252  int *get_intx3(char *str);
253  int *get_intx4(char *str);
254  float *get_floatx2(char *str);
255  float *get_floatx3(char *str);
256  float *get_floatx4(char *str);
257  double *get_doublex2(char *str);
258  double *get_doublex3(char *str);
259  double *get_doublex4(char *str);
260  void errmsg(const char *s, ...);
261  void DumpInfoMessage(struct ml *mlptr, const char *argDesc, std::string value);
262  void dumpmlist(void);
263  void dumpmlptr(struct ml *mlptr);
264 };
265 
266 } // end namespace niftk
267 
268 #endif
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1237
const char * helpmsg
The help messages.
Definition: niftkCommandLineParser.h:71
struct CommandLineArgumentDescription * opt
Definition: niftkCommandLineParser.h:145
int type
Type of option.
Definition: niftkCommandLineParser.h:68
int * mult
Definition: niftkCommandLineParser.h:137
int num
Definition: niftkCommandLineParser.h:146
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1363
struct ml * next
Definition: niftkCommandLineParser.h:144
Definition: niftkCommandLineParser.h:67
Definition: niftkCommandLineParser.h:133
#define NIFTKCOMMON_WINEXPORT
Definition: niftkCommonWin32ExportHeader.h:28
GLsizei const GLfloat * value
Definition: glew.h:1833
Definition: niftkCommandLineParser.h:143
const char * key
option key, eg. "a" will give "-a".
Definition: niftkCommandLineParser.h:69
int * pint
Definition: niftkCommandLineParser.h:138
long along
Definition: niftkCommandLineParser.h:134
Parser for extracting program arguments from the command line.
Definition: niftkCommandLineParser.h:169
double afloat
Definition: niftkCommandLineParser.h:135
void PrintUsage(void)
Printing member function for CommandLineParser.
Definition: niftkCommandLineParser.h:186
const char * parm
The parameters the option takes.
Definition: niftkCommandLineParser.h:70
double * pdouble
Definition: niftkCommandLineParser.h:140
#define HLP_VERBOSE
Definition: niftkCommandLineParser.h:31
float * pfloat
Definition: niftkCommandLineParser.h:139
GLdouble s
Definition: glew.h:1374
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
GLsizei GLsizei GLchar * source
Definition: glew.h:1816
char * astr
Definition: niftkCommandLineParser.h:136
struct niftk::CommandLineArgumentDescription clArgList[]
Definition: niftk2DImagesTo3DVolume.cxx:24