sla.h

Go to the documentation of this file.
00001 /*
00002 
00003 String list assignment (sla) functions to process assignment instructions and flags.
00004 Copyright (C) 1998,1999 Brian T. N. Gunney
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Library General Public
00008 License as published by the Free Software Foundation; either
00009 version 2 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Library General Public License for more details.
00015 
00016 You should have received a copy of the GNU Library General Public
00017 License along with this library; if not, write to the
00018 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019 Boston, MA  02111-1307, USA.
00020 
00021 Brian T. N. Gunney, brlynn@minn.net
00022 
00023 $Id: sla.h,v 1.3 2008/01/08 02:56:44 dquinlan Exp $
00024 
00025 */
00026 
00027 /*
00028  *
00029  * Jeremiah J. Willcock, 10-16-2007
00030  * Changed the C++ version of this code to use std::strings rather than char*
00031  * to allow better integration with the string version of ROSE command line
00032  * processing.
00033  *
00034  */
00035 
00036 #ifndef __INCLUDED_sla_hh__
00037 #define __INCLUDED_sla_hh__
00038 /*
00039 $Header: /nfs/casc/overture/ROSE/ROSE2_Repository/ROSE/src/util/commandlineProcessing/sla.h,v 1.3 2008/01/08 02:56:44 dquinlan Exp $
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 /*** generates code for sla prototypes ***/
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 /* default argument */      \
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 /* no default argument */ \
00095      )
00096 #endif
00097 #endif
00098 
00099 /*** generates code for sla function headers ***/
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 /*** For allocating and deleting memory ***/
00116 #include <stdlib.h>
00117 
00118 /*** Sla for type T (automatically uses function M to modify). ***/
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 /*** Sla for type T (automatically uses function C to convert). ***/
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   Generate additional sla for various primitive types.
00201   The use of the SLA macro makes it
00202   difficult to see the prototypes of the functions created.
00203   To find the prototypes, try this:
00204   > CC -P sla.cc
00205   > pgrep 's/^(int sla\s*\([^\{]*).*$/$1;/' sla.i -s
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

Generated on Sat May 19 00:53:07 2012 for ROSE by  doxygen 1.4.7