Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Macros
drwnCommandLine.h File Reference

Command line processing macros. Applications should use these macros to present a consistent interface. More...

Go to the source code of this file.

Macros

#define DRWN_STANDARD_OPTIONS_USAGE
 
#define DRWN_PROCESS_STANDARD_OPTIONS(ARGS, ARGC)
 
#define DRWN_BEGIN_CMDLINE_PROCESSING(ARGC, ARGV)
 
#define DRWN_CMDLINE_STR_OPTION(OPTSTR, VAR)
 
#define DRWN_CMDLINE_INT_OPTION(OPTSTR, VAR)
 
#define DRWN_CMDLINE_REAL_OPTION(OPTSTR, VAR)
 
#define DRWN_CMDLINE_BOOL_OPTION(OPTSTR, VAR)   else if (!strcmp(*_drwn_args, OPTSTR)) { VAR = true; }
 
#define DRWN_CMDLINE_BOOL_TOGGLE_OPTION(OPTSTR, VAR)   else if (!strcmp(*_drwn_args, OPTSTR)) { VAR = !VAR; }
 
#define DRWN_CMDLINE_VEC_OPTION(OPTSTR, VAR)
 
#define DRWN_CMDLINE_OPTION_BEGIN(OPTSTR, PTR)
 
#define DRWN_CMDLINE_OPTION_END(N)   _drwn_args += (N); _drwn_argc -= (N); }
 
#define DRWN_CMDLINE_FLAG_BEGIN(OPTSTR)   else if (!strcmp(*_drwn_args, OPTSTR)) {
 
#define DRWN_CMDLINE_FLAG_END   }
 
#define DRWN_END_CMDLINE_PROCESSING(USAGE)
 
#define DRWN_CMDLINE_ARGV   _drwn_args
 
#define DRWN_CMDLINE_ARGC   _drwn_argc
 

Detailed Description

Command line processing macros. Applications should use these macros to present a consistent interface.

The following is an example usage

int main(int argc, char* argv[])
{
int integerVariable = 0;
const char *stringVariable = NULL;
DRWN_BEGIN_CMDLINE_PROCESSING(argc, argv)
DRWN_CMDLINE_INT_OPTION("-intgerOption", integerVariable)
DRWN_CMDLINE_STR_OPTION("-stringOption", stringVariable)
DRWN_CMDLINE_OPTION_BEGIN("-longOption", p)
cerr << p[0] << "\n";
cerr << p[1] << "\n";
DRWN_CMDLINE_OPTION_END(2)
DRWN_END_CMDLINE_PROCESSING();
return 0;
}
See Also
Command Line Processing

Macro Definition Documentation

#define DRWN_BEGIN_CMDLINE_PROCESSING (   ARGC,
  ARGV 
)
Value:
char **_drwn_args = ARGV + 1; \
int _drwn_argc = ARGC; \
while (--_drwn_argc > 0) { \
DRWN_LOG_DEBUG("processing cmdline arg " << *_drwn_args << " (" << _drwn_argc << ")"); \
DRWN_PROCESS_STANDARD_OPTIONS(_drwn_args, _drwn_argc) \
static void cacheCommandLine(int argc, char **argv)
save the command line string (will be logged when the log file is opened)
Definition: drwnLogger.cpp:96
#define DRWN_CMDLINE_INT_OPTION (   OPTSTR,
  VAR 
)
Value:
else if (!strcmp(*_drwn_args, OPTSTR)) { \
VAR = atoi(*(++_drwn_args)); _drwn_argc -= 1; }
#define DRWN_CMDLINE_OPTION_BEGIN (   OPTSTR,
  PTR 
)
Value:
else if (!strcmp(*_drwn_args, OPTSTR)) { \
const char **PTR = (const char **)(_drwn_args + 1);
#define DRWN_CMDLINE_REAL_OPTION (   OPTSTR,
  VAR 
)
Value:
else if (!strcmp(*_drwn_args, OPTSTR)) { \
VAR = atof(*(++_drwn_args)); _drwn_argc -= 1; }
#define DRWN_CMDLINE_STR_OPTION (   OPTSTR,
  VAR 
)
Value:
else if (!strcmp(*_drwn_args, OPTSTR)) { \
VAR = *(++_drwn_args); _drwn_argc -= 1; }
#define DRWN_CMDLINE_VEC_OPTION (   OPTSTR,
  VAR 
)
Value:
else if (!strcmp(*_drwn_args, OPTSTR)) { \
VAR.push_back(*(++_drwn_args)); _drwn_argc -= 1; }
#define DRWN_END_CMDLINE_PROCESSING (   USAGE)
Value:
else if (!strcmp(*_drwn_args, "-help")) { \
USAGE; \
return 0; \
} else if ((*_drwn_args)[0] == '-') { \
USAGE; \
DRWN_LOG_ERROR("unrecognized option " << *_drwn_args); \
return -1; \
} else { \
DRWN_LOG_DEBUG(_drwn_argc << " commandline arguments remaining"); \
break; \
} \
_drwn_args++; \
}
#define DRWN_STANDARD_OPTIONS_USAGE
Value:
" -help :: display application usage\n" \
" -config <xml> :: configure Darwin from XML file\n" \
" -set <m> <n> <v> :: set (configuration) <m>::<n> to value <v>\n" \
" -profile :: profile code\n" \
" -quiet :: only show warnings and errors\n" \
" -verbose :: show verbose messages\n" \
" -debug :: show debug messages\n" \
" -log <filename> :: log filename\n" \
" -threads <max> :: set maximum number of threads\n" \
" -randseed <n> :: seed random number generators rand and drand48\n"