00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef __INCLUDED_sla_hh__
00037 #define __INCLUDED_sla_hh__
00038
00039
00040
00041
00042 #ifdef __cplusplus
00043 #include <vector>
00044 #include <string>
00045 #endif
00046
00047 #ifndef ARGVCONST
00048 #define ARGVCONST
00049 #endif
00050
00051 void sla_set_debug( int d );
00052
00053 #if 1
00054 #ifdef __cplusplus
00055 #define sla_str sla
00056 #define sla_none sla
00057 #define sla_float sla
00058 #define sla_double sla
00059 #define sla_int sla
00060 #define sla_short sla
00061 #define sla_long sla
00062 #define sla_uint sla
00063 #define sla_ushort sla
00064 #define sla_ulong sla
00065 #define sla_char sla
00066 #endif
00067 #endif
00068
00069 #ifdef __cplusplus
00070 int sla_none( std::vector<std::string> &argv, const std::string& flind, const std::string& assop, const std::string& pname, int argd=0 );
00071 #else
00072 int sla_none( int *argc, ARGVCONST char **argv, const char *flind, const char *assop, const char *pname, int argd );
00073 #endif
00074
00075
00076 #ifndef SLA_FCN_PROTO
00077 #ifdef __cplusplus
00078 #define SLA_FCN_PROTO(N,T) \
00079 int N( std::vector<std::string>& argv \
00080 , const std::string& flind \
00081 , const std::string& assop \
00082 , const std::string& pname \
00083 , T *value \
00084 , int argd = 0 \
00085 )
00086 #else
00087 #define SLA_FCN_PROTO(N,T) \
00088 int N( int *argc \
00089 , ARGVCONST char **argv \
00090 , const char *flind \
00091 , const char *assop \
00092 , const char *pname \
00093 , T *value \
00094 , int argd \
00095 )
00096 #endif
00097 #endif
00098
00099
00100 #ifndef SLA_FCN_BEGIN
00101 #ifdef __cplusplus
00102 #define SLA_FCN_BEGIN(N,T) \
00103 int N( std::vector<std::string>& argv \
00104 , const std::string& flind \
00105 , const std::string& assop \
00106 , const std::string& pname \
00107 , T *value \
00108 , int argd \
00109 )
00110 #else
00111 #define SLA_FCN_BEGIN(N,T) SLA_FCN_PROTO(N,T)
00112 #endif
00113 #endif
00114
00115
00116 #include <stdlib.h>
00117
00118
00119 #ifndef SLA_MOD
00120 #ifdef __cplusplus
00121 #define SLA_MOD(M) \
00122 std::vector<std::string> rr(argv.size()); \
00123 int i, nvalue; \
00124 std::string ppname = pname; \
00125 if ( !pname.empty() && pname[0] != '*' ) { \
00126 ppname = "*" + ppname; \
00127 } \
00128 nvalue = sla_str( argv, flind, assop, ppname, rr, argd ); \
00129 if ( nvalue > 0 && value != NULL ) { \
00130 if ( !pname.empty() && pname[0] == '*' ) { \
00131 for ( i=0; i<nvalue; i++ ) M( value+i, rr[i] ); \
00132 } \
00133 else { \
00134 for ( i=0; i<nvalue; i++ ) M( value , rr[i] ); \
00135 } \
00136 } \
00137 return nvalue;
00138 #else
00139 #define SLA_MOD(M) \
00140 ARGVCONST char **rr, eol='\0'; \
00141 int i, nvalue; \
00142 rr = (ARGVCONST char**)malloc( (*argc)*sizeof(ARGVCONST char*) ); \
00143 for ( i=0; i<*argc; i++ ) rr[i] = &eol; \
00144 nvalue = sla_str( argc, argv, flind, assop, pname, rr, argd ); \
00145 if ( nvalue > 0 && value != NULL ) { \
00146 if ( *pname == '*' ) { \
00147 for ( i=0; i<nvalue; i++ ) M( value+i, rr[i] ); \
00148 } \
00149 else { \
00150 for ( i=0; i<nvalue; i++ ) M( value , rr[i] ); \
00151 } \
00152 } \
00153 free(rr); \
00154 return nvalue;
00155 #endif
00156 #endif
00157
00158
00159 #ifndef SLA_CNV
00160 #ifdef __cplusplus
00161 #define SLA_CNV(C) \
00162 std::vector<std::string> rr(argv.size()); \
00163 int i, nvalue; \
00164 std::string ppname = pname; \
00165 if ( pname.empty() || pname[0] != '*' ) { \
00166 ppname = "*" + ppname; \
00167 } \
00168 nvalue = sla_str( argv, flind, assop, ppname, &rr[0], argd ); \
00169 if ( nvalue > 0 && value != NULL ) { \
00170 if ( !pname.empty() && pname[0] == '*' ) { \
00171 for ( i=0; i<nvalue; i++ ) value[i] = C(rr[i].c_str()); \
00172 } \
00173 else { \
00174 for ( i=0; i<nvalue; i++ ) value[0] = C(rr[i].c_str()); \
00175 } \
00176 } \
00177 return nvalue;
00178 #else
00179 #define SLA_CNV(C) \
00180 ARGVCONST char **rr, eol='\0'; \
00181 int i, nvalue; \
00182 rr = (ARGVCONST char**)malloc( (*argc)*sizeof(ARGVCONST char*) ); \
00183 for ( i=0; i<*argc; i++ ) rr[i] = &eol; \
00184 nvalue = sla_str( argc, argv, flind, assop, pname, rr, argd ); \
00185 if ( nvalue > 0 && value != NULL ) { \
00186 if ( *pname == '*' ) { \
00187 for ( i=0; i<nvalue; i++ ) value[i] = C(rr[i]); \
00188 } \
00189 else { \
00190 for ( i=0; i<nvalue; i++ ) value[0] = C(rr[i]); \
00191 } \
00192 } \
00193 free(rr); \
00194 return nvalue;
00195 #endif
00196 #endif
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 #ifdef __cplusplus
00208 SLA_FCN_PROTO( sla_str, std::string );
00209 #else
00210 SLA_FCN_PROTO( sla_str, ARGVCONST char * );
00211 #endif
00212 SLA_FCN_PROTO( sla_float, float );
00213 SLA_FCN_PROTO( sla_double, double );
00214 SLA_FCN_PROTO( sla_int, int );
00215 SLA_FCN_PROTO( sla_short, short );
00216 SLA_FCN_PROTO( sla_long, long );
00217 SLA_FCN_PROTO( sla_uint, unsigned int );
00218 SLA_FCN_PROTO( sla_ushort, unsigned short );
00219 SLA_FCN_PROTO( sla_ulong, unsigned long );
00220 SLA_FCN_PROTO( sla_char, char );
00221
00222
00223
00224
00225 #endif