Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00089 #ifndef OPTARG_H
00090 # define OPTARG_H
00091
00092 #include "definitions.h"
00093 #include "slist.h"
00094 #include <stdarg.h>
00095
00096 #define NO_OPTARGS NULL
00097
00098 #ifdef __cplusplus
00099 extern "C" {
00100 #endif
00101
00102
00103
00105 typedef struct {
00106 char key[MAX_LABEL_LENGTH];
00107 bool scalar;
00108 char type[MAX_LABEL_LENGTH];
00109 void *data_ptr;
00110 double data_scalar;
00111 } OptArg;
00112
00114 typedef struct {
00115 int nargs;
00116 OptArg *args;
00117 } OptArgList;
00118
00128 #define optarg_PARSE_SCALAR( opts, label, var, type, tmp ) \
00129 if( optarglist_has_key( (opts), (label) ) ){ \
00130 (tmp) = optarglist_scalar_by_key( (opts), (label) ); \
00131 if( !isnan( (tmp) ) ) (var)=(type)(tmp); \
00132 }
00133
00143 #define optarg_PARSE_PTR( opts, label, var, type, tmp ) \
00144 if( optarglist_has_key( (opts), (label) ) ){ \
00145 (tmp) = optarglist_ptr_by_key( (opts), (label) ); \
00146 if( (tmp) ) (var)=(type)(tmp); \
00147 }
00148
00149 OptArgList* optarglist( char *format, ... );
00150 OptArgList* optarglisttmp( char *format, ... );
00151
00152 bool optarglist_has_key( OptArgList *list, const char *key );
00153
00154 double optarglist_scalar_by_key( OptArgList *list, const char *key );
00155 void* optarglist_ptr_by_key ( OptArgList *list, const char *key );
00156 OptArg* optarglist_optarg_by_key( OptArgList *list, const char *key );
00157
00158 OptArgList* optarglist_append_arg ( OptArgList *list, OptArg *arg );
00159 OptArgList* optarglist_delete_arg ( OptArgList *list, OptArg *arg );
00160
00161 void optarglist_print( OptArgList *list, FILE *out );
00162 void optarglist_free( OptArgList *list );
00163
00164 OptArgList* optarglist_remove_freeflag( OptArgList *list, bool *removedflag );
00165
00166 OptArg* optarg_scalar( const char *key, double scalar );
00167 OptArg* optarg_ptr ( const char *key, void *ptr );
00168
00169 #ifdef __cplusplus
00170 }
00171 #endif
00172
00173
00174 #endif