include/it/parser.h

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2008 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library 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 GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   Parser for Parameter files and command line arguments
00022   Copyright (C) 2005 Herve Jegou
00023 */
00024 
00025 #ifndef __it_parser_h
00026 #define __it_parser_h
00027 
00028 #include <it/vec.h>
00029 #include <it/mat.h>
00030 #include <it/cplx.h>
00031 
00032 
00033 typedef char *parser_t;
00034 
00035 /*---------------------------------------------------------------------------*/
00036 /*! \defgroup parser Parser                                                  */
00037 /* @{                                                                        */
00038 /*---------------------------------------------------------------------------*/
00039 
00040 /* Creation and initialisation of a parser. This initialization requires 
00041    3 arguments, from the one which has the higher priority to the one 
00042    of the lower priority :
00043    1) The first is the command line. The variable set there 
00044    have the higher priority. 
00045    2) The second is the name of the file from which some variables 
00046    must be read. 
00047    3) The third is a const char * which allows to have default values 
00048    for arguments
00049 
00050    Any of these arguments may be NULL (or 0 for argc). 
00051 */
00052 parser_t *parser_init (int argc, char **argv,
00053            const char *filename, char *cmdline);
00054 
00055 
00056 /* The following functions add another source of data 
00057    to an existing parser                                                */
00058 parser_t *_parser_add_file (parser_t * p, const char *filename);
00059 parser_t *_parser_add_params (parser_t * p, int argc, char **argv);
00060 parser_t *_parser_add_string (parser_t * p, char *s);
00061 
00062 #define parser_add_file( p, filename )     do { p = _parser_add_file( p, filename );}   while(0)
00063 #define parser_add_params( p, argc, argv ) do { p = _parser_add_params( p, argc, argv );} while(0)
00064 #define parser_add_string( p, s )          do { p = _parser_add_string( p, s );} while(0)
00065 
00066 /* Free the memory allocated for a parser                               */
00067 void parser_delete (parser_t * p);
00068 
00069 /* Print the content of the parser                                      */
00070 void parser_print (parser_t * p);
00071 
00072 /*----------------------------------------------------------------------*/
00073 
00074 /* Retrieve the variable whose name is given by varname                 */
00075 int  parser_get_int (const parser_t * p, const char *varname);
00076 double parser_get_double (const parser_t * p, const char *varname);
00077 byte parser_get_byte (const parser_t * p, const char *varname);
00078 char *parser_get_string (const parser_t * p, const char *varname);
00079 cplx parser_get_cplx (const parser_t * p, const char *varname);
00080 
00081 /* Retrieve the vectors whose name is given by varname                  */
00082 vec  parser_get_vec (const parser_t * p, const char *varname);
00083 ivec parser_get_ivec (const parser_t * p, const char *varname);
00084 bvec parser_get_bvec (const parser_t * p, const char *varname);
00085 cvec parser_get_cvec (const parser_t * p, const char *varname);
00086 
00087 /* Retrieve the matrices whose name is given by varname                 */
00088 mat  parser_get_mat (const parser_t * p, const char *varname);
00089 imat parser_get_imat (const parser_t * p, const char *varname);
00090 bmat parser_get_bmat (const parser_t * p, const char *varname);
00091 cmat parser_get_cmat (const parser_t * p, const char *varname);
00092 
00093 /* Return 1 if the string has been found as a valid identifier, 0 otherwise */
00094 int  parser_exists (const parser_t * p, const char *varname);
00095 
00096 /*----------------------------------------------------------------------*/
00097 /* Same function, but specify the echo of variable (verbose mode)       */
00098 
00099 /* Retrieve the variable whose name is given by varname                 */
00100 int  parser_get_int_verbose (const parser_t * p, const char *varname,
00101            int verbose);
00102 double parser_get_double_verbose (const parser_t * p, const char *varname,
00103           int verbose);
00104 byte parser_get_byte_verbose (const parser_t * p, const char *varname,
00105             int verbose);
00106 char *parser_get_string_verbose (const parser_t * p, const char *varname,
00107          int verbose);
00108 cplx parser_get_cplx_verbose (const parser_t * p, const char *varname,
00109             int verbose);
00110 
00111 /* Retrieve the vectors whose name is given by varname                  */
00112 vec  parser_get_vec_verbose (const parser_t * p, const char *varname,
00113            int verbose);
00114 ivec parser_get_ivec_verbose (const parser_t * p, const char *varname,
00115             int verbose);
00116 bvec parser_get_bvec_verbose (const parser_t * p, const char *varname,
00117             int verbose);
00118 cvec parser_get_cvec_verbose (const parser_t * p, const char *varname,
00119             int verbose);
00120 
00121 /* Retrieve the matrices whose name is given by varname                 */
00122 mat  parser_get_mat_verbose (const parser_t * p, const char *varname,
00123            int verbose);
00124 imat parser_get_imat_verbose (const parser_t * p, const char *varname,
00125             int verbose);
00126 bmat parser_get_bmat_verbose (const parser_t * p, const char *varname,
00127             int verbose);
00128 cmat parser_get_cmat_verbose (const parser_t * p, const char *varname,
00129             int verbose);
00130 
00131 /* Return 1 if the string has been found as a valid identifier, 0 otherwise */
00132 int  parser_exists (const parser_t * p, const char *varname);
00133 
00134 /* @} */
00135 
00136 #endif

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau