gmlTcl_WrapperParser.h

00001 /*
00002  * gml/tcl/wrapper/wrapper/gmlTcl_WrapperParser.h --
00003  *
00004  *    See "gmlTclWrapperParser.cc".
00005  *
00006  *  Copyright (c) 1996-2002 CLIPS-IMAG
00007  *
00008  *  See the file "gml_LicenseTerms.txt" for information on usage and redistribution
00009  *  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00010  *
00011  *  Created on September 3, 2002 (FB).
00012  */
00013 
00014 #ifndef __GMLTCLWRAPPERPARSER__
00015 #define __GMLTCLWRAPPERPARSER__
00016   #if defined(__cplusplus)
00017     extern "C" {
00018   #endif
00019 
00020 // required for "offsetof"
00021 #include <stddef.h>
00022 
00023 #include "gml/base/gml_Types.h"
00024 
00025 #include "tcl.h"
00026 
00027 
00028 #define gmlTcl_kMaxOptionNameLength       39
00029 #define gmlTcl_kMaxDescrLength            79
00030 
00031 
00032 
00033 /*
00034  * gmlTcl_TWrapParseProc --
00035  *
00036  *  Prototype of functions that convert Tcl_Objs to C/C++ data.
00037  *    <interp>    can be used to store an error message if the conversion is not possible.
00038  *    <arg>       is the Tcl_Obj to convert.
00039  *    <storage>   must be allocated by the caller, it must be big enough to contain the
00040  *                  C/C++ data.
00041  */
00042 
00043 typedef int (gmlTcl_TWrapParseProc) (Tcl_Interp* interp, Tcl_Obj* arg, void* storage);
00044 
00045 
00046 /*
00047  * gmlTcl_gWrapParseInt --
00048  * gmlTcl_gWrapParseIntList --
00049  * gmlTcl_gWrapParseUInt8 --
00050  * gmlTcl_gWrapParseUInt8List --
00051  * gmlTcl_gWrapParseUInt16 --
00052  * gmlTcl_gWrapParseUInt16List --
00053  * gmlTcl_gWrapParseUInt32 --
00054  * gmlTcl_gWrapParseUInt32List --
00055  * gmlTcl_gWrapParseDouble --
00056  * gmlTcl_gWrapParseDoubleList --
00057  * gmlTcl_gWrapParseBoolean --
00058  * gmlTcl_gWrapParseBooleanList --
00059  *
00060  *  Standard parsers.
00061  *  In the case of a scalar value, a pointer to the converted value is stored in <*storage>,
00062  *    followed immediately by the converted value.
00063  *  In the case of a list, a pointer to an array of values is stored in <*storage>,
00064  *    followed by the number of elements in the array (an int). The memory for the array
00065  *    is allocated by "gml_Malloc", it is the responsability of the caller to free it with
00066  *    "gml_Free".
00067  */
00068 
00069 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseInt;
00070 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseIntList;
00071 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseUInt8;
00072 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseUInt8List;
00073 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseUInt16;
00074 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseUInt16List;
00075 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseUInt32;
00076 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseUInt32List;
00077 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseDouble;
00078 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseDoubleList;
00079 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseFloat;
00080 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseFloatList;
00081 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseBoolean;
00082 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseBooleanList;
00083 
00084 
00085 
00086 /*
00087  * gmlTcl_gWrapParseTclObj --
00088  *
00089  *  Don't parse, just return the Tcl_Obj*.
00090  */
00091 
00092 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseTclObj;
00093 
00094 
00095 
00096 /*
00097  * gmlTcl_gWrapParseString --
00098  *
00099  *  A pointer to the string is stored in <storage>. The memory is
00100  *  managed by Tcl (and thus should not be freed by the caller), 
00101  *  it will exist as long as the Tcl_Object that produced the string.
00102  */
00103 
00104 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseString;
00105 
00106 
00107 /*
00108  * gmlTcl_gWrapParseStringList --
00109  *
00110  *  A pointer to an array of strings is stored in <storage>, followed by
00111  *  an <int>.
00112  *  It is the caller's responsability to free the array, but not the 
00113  *  individual strings (which are managed by Tcl).
00114  */
00115 
00116 extern gmlTcl_TWrapParseProc* gmlTcl_gWrapParseStringList;
00117 
00118 
00119 
00120 
00121 
00122 /*
00123  * gmlTcl_TParamDescr --
00124  *
00125  *  <fName>       is the name of the option. It typically starts with "-" such as "-color".
00126  *                  Set to empty "" if this is a required parameter. Required parameters
00127  *                  must be first in the array of gmlTcl_TParamDescr when passed to
00128  *                  <gmlTcl_WrapParse> (see below).
00129  *  <fDescr>      is a description of the parameter. It is used to generate an error message
00130  *                  that explain the form and semantic of parameters.
00131  *  <fParseProc>  is the parse function for this type of parameter.
00132  *  <fResOffset>  is the offset in the result buffer, in byte, where to store the converted data.
00133  */
00134 
00135 typedef struct gmlTcl_TParamDescr {
00136 
00137   char                      fName[gmlTcl_kMaxOptionNameLength+1];
00138   char                      fDescr[gmlTcl_kMaxDescrLength+1];
00139   gmlTcl_TWrapParseProc*    fParseProc;
00140   gml_TBlockSize            fResOffset;
00141 
00142 } gmlTcl_TParamDescr;
00143 
00144 
00145 // Optional macro-constructors for gmlTcl_TParamDescr's
00146 
00147 #define GMLTCL_DECLARE_PARAM(FLAG,DESCRIPTION,PARSER,PROCNAME,FIELD)  
00148   {                                                                   
00149     FLAG, DESCRIPTION, gmlTcl_gWrapParse ## PARSER,                   
00150     offsetof (gmlTcl_ ## PROCNAME ## _params, FIELD)                  
00151   }
00152   
00153 #define GMLTCL_END_PARAM_LIST 
00154   {"", "", (gmlTcl_TWrapParseProc*)NULL, 0 }
00155 
00156 
00157 /*
00158  * gmlTcl_WrapParse --
00159  *
00160  *  Parse Tcl word parameters into C/C++ data.
00161  *    <interp>        is used to store error message when necessary.
00162  *    <paramDescrs>   is the array of possible (accepted) parameters.
00163  *    <objc>, <objv>  are the Tcl words.
00164  *    <argStart>      is the index in the <objv> array where to start the parsing.
00165  *                      <gmlTcl_WrapParse> requires the entire Tcl command line in <objv> even
00166  *                      though parameter parsing typically doesn't start on the first words. The
00167  *                      first words are necessary to build the error message.
00168  *    
00169  *    <parseRes>      is a pointer to the result buffer. The buffer is not initialized to zero.
00170  *                      Only the field corresponding to options in <objv> will be modified by
00171  *                      "gmlTcl_WrapParse".
00172  */
00173 
00174 int gmlTcl_WrapParse (Tcl_Interp*             interp,
00175                       gmlTcl_TParamDescr*     paramDescrs,
00176                       int                     objc,
00177                       Tcl_Obj*                objv[],
00178                       int                     argStart,
00179                       void*                   parseRes);
00180 
00181 
00182 
00183   #if defined(__cplusplus)
00184     }
00185   #endif
00186 #endif
Generated on Tue Jun 12 14:03:27 2007 for gml by Doxygen 1.5.2.