• API Main Page
  • Documentation
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

src/optarg.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008/2009 by Matthias Ihrke                                  *
00003  *   mihrke@uni-goettingen.de                                              *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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      - Optional Arguments
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

Generated on Fri Jun 25 2010 14:10:20 for libeegtools by  doxygen 1.7.0