GDCM_NAME_SPACE::ArgMgr Class Reference

class designed for command line arguments management (to make programmer's live easier) NOT Dicom dependant (could be used for any kind of 'command line program') More...

#include <gdcmArgMgr.h>

List of all members.

Public Member Functions

 ArgMgr (int argc, char **argv)
 constructor
 ~ArgMgr ()
 canonical destructor
int ArgMgrDefined (const char *param)
 checks if a parameter exists in the command line
char * ArgMgrValue (const char *param)
 Gets the parameter value, read on the command line.
const char * ArgMgrUnused (void)
 Search for the first not yet used label.
int ArgMgrSave (const char *)
 Forget it, right now ... Saves a char. array in a parameter file whose name is given on command line by : PARAMOUT=??? or, as a default, by ARG_DEFAULT_PARAMOUT.
int ArgMgrUsage (const char **usage)
 Prints program usage.
int ArgMgrPrintUnusedLabels (void)
 Prints unused labels, if any.
int ArgMgrGetInt (const char *param, int)
 Gets an int value passed as an argument to a program (use default value if not found) EXAMPLE: int dimx = ArgMgrGetInt ( "DIMX", 256 );.
float ArgMgrGetFloat (const char *param, float)
 Gets a float value passed as an argument to a program (use default value if not found) EXAMPLE: float scale = ArgMgrGetFloat ( "SCALE", 0.33 );.
const char * ArgMgrGetString (const char *param, const char *ext=0)
 Gets a 'string' value passed as an argument to a program (use default value if not found) EXAMPLE : char *imageName = ArgMgrGetString( "NAME", "test.dcm" );.
int ArgMgrGetLabel (const char *param, const char *, int)
 Gets a value amongst a set of values (use default value if not found) EXAMPLE: int nlab = ArgMgrGetLabel("CONFIRM","NO\\YES", 0);.
int ArgMgrWantInt (const char *param, const char **usage)
 Demands an int value passed as an argument to a program If not found usage is displayed and the prog aborted EXAMPLE: int dimx = ArgMgrWantInt ( "DIMX", usage );.
float ArgMgrWantFloat (const char *param, const char **usage)
 Demands a float value passed as an argument to a program If not found usage is displayed and the prog aborted EXAMPLE: float scale = ArgMgrWantFloat ( "SCALE", usage );.
char * ArgMgrWantString (const char *param, const char **usage)
 Demands a 'string' value passed as an argument to a program If not found usage is displayed and the prog aborted EXAMPLE: char *code = ArgMgrWantString ( "CODE", usage );.
int ArgMgrWantLabel (const char *param, char *, const char **usage)
 Demands a value amongst a set of values (abort if not found) EXaMPLE: int nlab = ArgMgrWantLabel("CONFIRM","NO\\YES", usage);.
int * ArgMgrGetListOfInt (const char *param, int *)
 decodes and returns an array of 'INT' EXAMPLE: int *points = ArgMgrGetListOfInt ( "POINTS", &nbOfPoints );
float * ArgMgrGetListOfFloat (const char *param, int *)
 decodes and returns an array of 'FLOAT'
char ** ArgMgrGetListOfString (const char *param, int *)
 decodes and returns an array of 'STRING' EXAMPLE: char **codes = ArgMgrGetListOfString ( "CODES", &nbOfCodes );
int * ArgMgrGetIntEnum (const char *param, int *)
 decodes and returns an array of 'INT pairs', passed in decimal
uint16_t * ArgMgrGetXInt16Enum (const char *param, int *)
 decodes and returns an array of 'INT16 pairs', passed in hexadecimal
float * ArgMgrGetFloatEnum (const char *param, int *)
 decodes and returns an array of 'FLOAT pairs'

Private Member Functions

int FiltreLong (const char *)
const char * LoadedParam (const char *, FILE *)
int ArgLoadFromFile (const char *)
void ArgStdArgs (void)
char * maj (char *)
char * Majuscule (const char *)
int IdStrCountChar (char *chaine, int caract)
 Counts the nb of occurrences of a given charact within a 'string'.
int * IdStrIntEnum (char *value, int *number)
 returns an array of 'INT pairs'
uint16_t * IdStrXInt16Enum (char *value, int *number)
 returns an array of set of 'INT16 pairs', passed in Hexadecimal
float * IdStrFloatEnum (char *value, int *number)
 returns an array of 'FLOAT pairs'

Private Attributes

const char * ArgParamOut
char * ArgUsed
char * ArgLab [ARGMAXCOUNT]
char * ArgStr [ARGMAXCOUNT]
int ArgCount
char * Appel


Detailed Description

class designed for command line arguments management (to make programmer's live easier) NOT Dicom dependant (could be used for any kind of 'command line program')

Definition at line 51 of file gdcmArgMgr.h.


Constructor & Destructor Documentation

GDCM_NAME_SPACE::ArgMgr::ArgMgr int  argc,
char **  argv
 

constructor

Parameters:
argc arguments count, as passed to main()
argv pointers array on the arguments passed to main()

Definition at line 45 of file gdcmArgMgr.cxx.

References Appel, ARG_LONG_MAX, ArgCount, ArgUsed, and FiltreLong().

00046  {
00047    int i;
00048    int nblettre;
00049    ArgUsed = NULL;
00050    Appel   = NULL;
00051   
00052    /* Read the parameters of the command line *************************/
00053    for ( ArgCount=0, nblettre=1 , i=0; i<argc; i++) 
00054    {
00055       if ( FiltreLong(argv[i]) ) 
00056       { 
00057           std::cout << "Argument too long ( > "
00058                     << ARG_LONG_MAX << ")" << std::endl;
00059           return;
00060       }
00061       if ( argv[i][0] == '@' )
00062       {                       
00063          nblettre  += ArgLoadFromFile ( &argv[i][1] );   
00064       }
00065       else
00066       {                                         
00067          ArgLab [ArgCount] = strcpy ( (char *)malloc(strlen(argv[i])+1), argv[i] ) ;
00068          nblettre  += 1 + strlen(ArgLab[ArgCount]);     
00069          ArgCount++;                               
00070       }
00071       if (ArgCount >= ARGMAXCOUNT )      
00072       {
00073           std::cout << "Too many Arguments ( more than "
00074                     << ARGMAXCOUNT << ")" << std::endl; 
00075           return;
00076       }
00077    }
00078 
00079    /* Fills an array with the already used parameters ****/
00080    ArgUsed = (char *)calloc (1, ArgCount );
00081 
00082    /* Builds the full string with all the parameters  **************/
00083    Appel = (char *) calloc (1, nblettre );
00084 
00085    for ( *Appel = '\0', i=0; i<ArgCount; i++)
00086    {
00087       strcat ( Appel, ArgLab [i] ) ;
00088       strcat ( Appel, " " ) ;
00089    }
00090 
00091    /* Splitting label from label value *************************************/
00092    for ( i=0; i<ArgCount; i++) 
00093    {
00094       char * egaloufin = ArgLab[i] ;
00095       while ( (*egaloufin != '\0') && (*egaloufin != '=') ) 
00096          egaloufin ++ ;
00097       if ( *egaloufin ) *(egaloufin++) = '\0';
00098       ArgStr[i]= egaloufin;
00099    }
00100 
00101    /* Set labels to upper-case (labels are not case sensitive ) *********/
00102    //char *secu;
00103    for ( i=0; i<ArgCount; i++)
00104    {
00105       //secu = ArgLab[i];
00106       ArgLab[i] = Majuscule ( ArgLab[i] ) ;
00107       //free (secu); //we still need it in the caller pgm.
00108    }
00109 
00110   /* Standard arguments are managed by ArgStdArgs **********************/
00111    ArgStdArgs(); 
00112  }

GDCM_NAME_SPACE::ArgMgr::~ArgMgr  ) 
 

canonical destructor

Definition at line 117 of file gdcmArgMgr.cxx.

References Appel, ArgLab, and ArgUsed.

00118 {
00119    for(int i=0;i<ArgCount;i++)
00120       if ( ArgLab[i] )
00121          free(ArgLab[i]);
00122    if ( ArgUsed )
00123       free(ArgUsed);
00124    if ( Appel )
00125       free(Appel);
00126 }


Member Function Documentation

int GDCM_NAME_SPACE::ArgMgr::ArgLoadFromFile const char *   )  [private]
 

Definition at line 842 of file gdcmArgMgr.cxx.

References ARG_LONG_MAX, ArgCount, ArgLab, ARGMAXCOUNT, ID_RFILE_TEXT, and LoadedParam().

00843 {
00844   int   nbl = 0;
00845   char  param[ARG_LONG_MAX+1];
00846   FILE  *fch;
00847 
00848   fch = fopen ( filename, ID_RFILE_TEXT );
00849   while ( LoadedParam (param, fch ) )
00850   {
00851     int n = strlen(param);
00852     if ( param[0]=='@' )
00853     {
00854       nbl  += ArgLoadFromFile ( &param[1] );
00855     }
00856     else
00857     {
00858       ArgLab [ArgCount] = strcpy ((char *) malloc(n+1), param ) ;
00859       nbl += n + 1 ;
00860       ArgCount++;
00861       if ( ArgCount >= ARGMAXCOUNT ) 
00862          break;
00863     }
00864   }
00865   fclose ( fch );
00866   return nbl;
00867 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrDefined const char *  param  ) 
 

checks if a parameter exists in the command line

Parameters:
param label name
Returns:
0 if label is not found else, returns the number of the spot it was found last time.

Definition at line 134 of file gdcmArgMgr.cxx.

References ArgLab, ArgUsed, and Majuscule().

Referenced by ArgMgrGetFloat(), ArgMgrGetInt(), ArgMgrGetString(), ArgMgrUnused(), ArgMgrValue(), ArgMgrWantFloat(), ArgMgrWantInt(), and ArgMgrWantString().

00135 {
00136   int i;
00137   bool trouve;
00138   char *temp;
00139   temp = Majuscule ( param ) ;
00140   for ( i = ArgCount-1; i>0; i-- )
00141   { 
00142     trouve = ( strcmp( ArgLab[i], temp )==0 ) ;
00143     if ( trouve )
00144     {
00145       free (temp);
00146       ArgUsed[i] = true ;           
00147       for ( int j=1; j<i; j++)
00148       {                     
00149          if ( (!ArgUsed[j])&&(!strcmp(ArgLab[i],ArgLab[j])) )
00150             ArgUsed[j] = i ;
00151       }
00152       return i ;
00153     }   
00154   }
00155   free (temp);
00156   return 0 ;
00157 }

float GDCM_NAME_SPACE::ArgMgr::ArgMgrGetFloat const char *  param,
float  defaultVal
 

Gets a float value passed as an argument to a program (use default value if not found) EXAMPLE: float scale = ArgMgrGetFloat ( "SCALE", 0.33 );.

Parameters:
param label name
defaultVal default value
Returns:
parameter value

Definition at line 278 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgMgrValue().

00279 {
00280    return     ( (ArgMgrDefined(param))
00281                ? ((float)atof(ArgMgrValue(param)))
00282                : (defaultVal) );
00283 }

float * GDCM_NAME_SPACE::ArgMgr::ArgMgrGetFloatEnum const char *  param,
int *  number
 

decodes and returns an array of 'FLOAT pairs'

Parameters:
param label name
number nb of found pairs
Returns:
pointer to the array of 'FLOAT pairs'; NULL if fail

Definition at line 567 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrFloatEnum().

00568 {
00569    char  *value = ArgMgrValue(param);
00570    float *liste;
00571    if (!value) 
00572    {
00573       *number = 0; 
00574       return 0;
00575    }
00576    liste = IdStrFloatEnum(value, number);
00577    return liste;
00578 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrGetInt const char *  label,
int  defaultVal
 

Gets an int value passed as an argument to a program (use default value if not found) EXAMPLE: int dimx = ArgMgrGetInt ( "DIMX", 256 );.

Parameters:
label label name
defaultVal default value
Returns:
parameter value

Definition at line 263 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgMgrValue().

00264 {
00265    return ( (ArgMgrDefined(label))
00266             ? (atoi(ArgMgrValue(label)))
00267             : (defaultVal) );
00268 }

int * GDCM_NAME_SPACE::ArgMgr::ArgMgrGetIntEnum const char *  param,
int *  number
 

decodes and returns an array of 'INT pairs', passed in decimal

Parameters:
param label name
number nb of found pairs
Returns:
pointer to the array of 'INT pairs'; NULL if fail

Definition at line 529 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrIntEnum().

00530 {
00531    char *value = ArgMgrValue(param);
00532    int *liste;
00533    if (!value) 
00534    {
00535       *number = 0; 
00536       return 0;
00537    }
00538    liste = IdStrIntEnum(value, number);
00539    return liste;
00540 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrGetLabel const char *  param,
const char *  liste,
int  val
 

Gets a value amongst a set of values (use default value if not found) EXAMPLE: int nlab = ArgMgrGetLabel("CONFIRM","NO\\YES", 0);.

Parameters:
param label name
liste character Chain describing the various values. Value are separated by '\'. Not case sensitive.
val number of default value
Returns:
int : range of value amongst the values list

Definition at line 311 of file gdcmArgMgr.cxx.

References ArgMgrGetString().

00312 {
00313   char *lab;
00314   const char *vallab;
00315   int i = 1;
00316   char *tmp;
00317   tmp = (char *) malloc(strlen(liste)+1);
00318   strcpy(tmp,liste);
00319 
00320   if ( (vallab = ArgMgrGetString(param,(const char *)NULL)) != 0 ) 
00321   { 
00322      for ( lab = strtok (tmp,"\\"); 
00323            lab != 0; 
00324            lab = strtok(0L,"\\"), i++ )
00325      { 
00326         // strcmp ignoring case
00327         if( strcasecmp(lab, vallab) == 0)
00328            return i;
00329      } 
00330      val=0;
00331    }
00332    free(tmp);
00333    return val;
00334 }

float * GDCM_NAME_SPACE::ArgMgr::ArgMgrGetListOfFloat const char *  label,
int *  number
 

decodes and returns an array of 'FLOAT'

Parameters:
label label name
number number of found FLOATs
Returns:
Pointer to the FLOAT array; NULL if error

Definition at line 489 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrCountChar().

00490 {
00491   char *value = ArgMgrValue(label);
00492   float *liste;
00493   float *elem;
00494   int taille;
00495   if (!value)
00496     return 0;
00497   *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00498   taille= *number;
00499   liste = (float *) calloc (1,sizeof(float)*taille );
00500   if ( !liste )
00501   {
00502      *number = 0;
00503      return 0;
00504   }
00505   elem = liste;
00506   //*number = 1;
00507 
00508   while ( taille>0 ) 
00509   {
00510     *(elem++) = (float) strtod ( value, &value );      
00511     if ( *value == '\0' )
00512        return liste;
00513     if ( *(value++) != ',' )
00514     {
00515       free (liste);
00516       return 0;
00517     }
00518     taille --;
00519   }
00520 return liste;
00521 }

int * GDCM_NAME_SPACE::ArgMgr::ArgMgrGetListOfInt const char *  label,
int *  number
 

decodes and returns an array of 'INT' EXAMPLE: int *points = ArgMgrGetListOfInt ( "POINTS", &nbOfPoints );

Parameters:
label label name
number nb of found INT
Returns:
Pointer to the INT array; NULL if error

Definition at line 449 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrCountChar().

00450 {
00451   char *value = ArgMgrValue(label);
00452   int *liste;
00453   int *elem;
00454   int taille;
00455   if (!value)
00456   {
00457      *number = 0;
00458      return 0;
00459   }          
00460   *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */ 
00461   taille= *number;
00462   liste = (int *) calloc (1,sizeof(int)*taille );
00463   if ( !liste )
00464      return 0;
00465   elem = liste;
00466   //*number = 1;
00467 
00468   while ( taille>0 ) 
00469   {
00470     *(elem++) = (int) strtol ( value, &value, 10 );      
00471     if ( *value == '\0' )
00472        return liste;
00473     if ( *(value++) != ',' ) 
00474     {
00475       free (liste);
00476       return 0;
00477     }
00478     taille --;
00479   }
00480 return liste;
00481 }

char ** GDCM_NAME_SPACE::ArgMgr::ArgMgrGetListOfString const char *  label,
int *  number
 

decodes and returns an array of 'STRING' EXAMPLE: char **codes = ArgMgrGetListOfString ( "CODES", &nbOfCodes );

Parameters:
label label name
number nb of found 'STRINGs'
Returns:
Pointer to the 'STRING' array; NULL if error

Definition at line 415 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrCountChar().

00416 {
00417   int taille;
00418   char  *value = ArgMgrValue(label);
00419   char **liste;
00420   char **elem;
00421   char  *chainecur; 
00422   if (!value)
00423   {
00424      *number = 0;
00425      return 0;
00426   }
00427   *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00428   taille = *number;
00429   liste = (char **) malloc (sizeof(char*) * taille + strlen(value)+1);
00430   if ( !liste )
00431      return 0;
00432   value = strcpy( ((char*)liste)+sizeof(char*) * taille, value );
00433   for ( elem = liste, chainecur = strtok(value,", ");
00434         taille>0;
00435         taille--, chainecur = (chainecur) ? strtok ( 0, ", " ) : 0 )
00436   {
00437     *(elem++) = chainecur;
00438   }
00439   return liste;
00440 }

const char * GDCM_NAME_SPACE::ArgMgr::ArgMgrGetString const char *  param,
const char *  defaultVal = 0
 

Gets a 'string' value passed as an argument to a program (use default value if not found) EXAMPLE : char *imageName = ArgMgrGetString( "NAME", "test.dcm" );.

Parameters:
param label name
defaultVal default value
Returns:
parameter value

Definition at line 293 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgMgrValue().

Referenced by ArgMgrGetLabel(), and ArgMgrWantLabel().

00294 {
00295    return    ( (ArgMgrDefined(param)) 
00296               ? (ArgMgrValue(param))
00297               : (defaultVal) );
00298 }

uint16_t * GDCM_NAME_SPACE::ArgMgr::ArgMgrGetXInt16Enum const char *  param,
int *  number
 

decodes and returns an array of 'INT16 pairs', passed in hexadecimal

Parameters:
param label name
number nb of found pairs
Returns:
pointer to the array of 'INT16 pairs'; NULL if fail

Definition at line 548 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrXInt16Enum().

00549 {
00550    char *value = ArgMgrValue(param);
00551    uint16_t *liste;
00552    if (!value) 
00553    {
00554       *number = 0; 
00555       return 0;
00556    }
00557    liste = IdStrXInt16Enum(value, number);
00558    return liste;
00559 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrPrintUnusedLabels void   ) 
 

Prints unused labels, if any.

Returns:
number of unused labels

Definition at line 196 of file gdcmArgMgr.cxx.

References ArgMgrUnused(), and ArgMgrValue().

00197 {
00198    const char *label;
00199    int i=0;
00200    while ( (label=ArgMgrUnused())!=0 )
00201    {
00202       if (i==0)
00203          std::cout << "\n Unused Labels:" << std::endl
00204                    << "=============="    << std::endl;
00205       std::cout << "Label : " << label << " = " 
00206                 << ArgMgrValue(label) << std::endl;
00207       i++;
00208    }
00209    return i;
00210 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrSave const char *  param  ) 
 

Forget it, right now ... Saves a char. array in a parameter file whose name is given on command line by : PARAMOUT=??? or, as a default, by ARG_DEFAULT_PARAMOUT.

Parameters:
param char. array that defines the parameter
Returns:
Entier correspondant au rang dans la liste de labels

Definition at line 233 of file gdcmArgMgr.cxx.

References ArgParamOut.

00234 {
00235    static int   deja = 0;
00236    FILE         *fd;
00237    if ( *ArgParamOut == '\0' )
00238       return 0;
00239    if ( deja ) 
00240    {
00241       fd = fopen ( ArgParamOut, "a+" );
00242    }
00243    else
00244    {
00245       deja = 1;
00246       fd = fopen ( ArgParamOut, "w" );
00247    } 
00248    if ( !fd ) 
00249       return 0;
00250    fprintf ( fd, "%s\n", param );
00251    fclose  ( fd );
00252    return 1;
00253 }

const char * GDCM_NAME_SPACE::ArgMgr::ArgMgrUnused void   ) 
 

Search for the first not yet used label.

Returns:
Pointer to the char array holding the first non used label

Definition at line 178 of file gdcmArgMgr.cxx.

References ArgLab, ArgMgrDefined(), and ArgUsed.

Referenced by ArgMgrPrintUnusedLabels().

00179 {
00180    int i ;
00181    for ( i=ArgCount-1; i>0; i-- )
00182    {
00183       if ( ! ArgUsed[i] )
00184       {
00185          ArgMgrDefined(ArgLab[i]);
00186          return ArgLab[i] ;
00187       }
00188   }
00189   return NULL ;
00190 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrUsage const char **  usage  ) 
 

Prints program usage.

Parameters:
usage array of pointers to the documentation lines of the program.
Returns:
exception code

Definition at line 217 of file gdcmArgMgr.cxx.

Referenced by ArgMgrWantFloat(), ArgMgrWantInt(), ArgMgrWantLabel(), and ArgMgrWantString().

00218 {
00219    while ( *usage ) 
00220       std::cout << std::endl << *(usage++);
00221    std::cout << std::endl; 
00222    return (0);
00223 }

char * GDCM_NAME_SPACE::ArgMgr::ArgMgrValue const char *  param  ) 
 

Gets the parameter value, read on the command line.

Parameters:
param name of the searched parameter label
Returns:
Value, as a char array, of the parameter whose label is given.

Definition at line 165 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgStr.

Referenced by ArgMgrGetFloat(), ArgMgrGetFloatEnum(), ArgMgrGetInt(), ArgMgrGetIntEnum(), ArgMgrGetListOfFloat(), ArgMgrGetListOfInt(), ArgMgrGetListOfString(), ArgMgrGetString(), ArgMgrGetXInt16Enum(), ArgMgrPrintUnusedLabels(), ArgMgrWantFloat(), ArgMgrWantInt(), ArgMgrWantString(), and ArgStdArgs().

00166 {
00167    int trouve ;
00168    if ( (trouve = ArgMgrDefined ( param )) != false )
00169       return ArgStr[trouve] ;
00170    else
00171       return NULL ;
00172 }

float GDCM_NAME_SPACE::ArgMgr::ArgMgrWantFloat const char *  label,
const char **  usage
 

Demands a float value passed as an argument to a program If not found usage is displayed and the prog aborted EXAMPLE: float scale = ArgMgrWantFloat ( "SCALE", usage );.

Parameters:
label label name
usage Usage program (displayed if label not found)
Returns:
parameter value

Definition at line 386 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), ArgMgrUsage(), and ArgMgrValue().

00387 {
00388    return       ( (ArgMgrDefined(label) ) 
00389                 ? ((float)atof(ArgMgrValue(label) ) ) 
00390                 : (ArgMgrUsage(usage),(float)1.0) );
00391 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrWantInt const char *  label,
const char **  usage
 

Demands an int value passed as an argument to a program If not found usage is displayed and the prog aborted EXAMPLE: int dimx = ArgMgrWantInt ( "DIMX", usage );.

Parameters:
label label name
usage Usage program (displayed if label not found)
Returns:
parameter value

Definition at line 371 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), ArgMgrUsage(), and ArgMgrValue().

00372 {
00373    return        ( (ArgMgrDefined(label) ) 
00374                  ? (atoi(ArgMgrValue(label) ) ) 
00375                  : (ArgMgrUsage(usage),1) );
00376 }

int GDCM_NAME_SPACE::ArgMgr::ArgMgrWantLabel const char *  param,
char *  liste,
const char **  usage
 

Demands a value amongst a set of values (abort if not found) EXaMPLE: int nlab = ArgMgrWantLabel("CONFIRM","NO\\YES", usage);.

Parameters:
param label name
liste character Chain describing the various values. Labels are separated by '\'. No case sensitive. WARNING this will be changed (not const)
usage Usage program (displayed if label not found)
Returns:
int : range of value amongst the values list

Definition at line 347 of file gdcmArgMgr.cxx.

References ArgMgrGetString(), and ArgMgrUsage().

00348 {
00349    char *lab;
00350    const char *vallab;
00351    int i = 1;
00352    if ( (vallab = ArgMgrGetString(param,0)) != 0 ) 
00353    {
00354       for ( lab = strtok (liste,"\\"); lab != 0; lab = strtok(0L,"\\"), i++ )
00355         if ( strcasecmp(lab,vallab)==0) 
00356            return i;
00357       return 0;
00358    }
00359    ArgMgrUsage(usage);
00360    return 0;
00361 }

char * GDCM_NAME_SPACE::ArgMgr::ArgMgrWantString const char *  label,
const char **  usage
 

Demands a 'string' value passed as an argument to a program If not found usage is displayed and the prog aborted EXAMPLE: char *code = ArgMgrWantString ( "CODE", usage );.

Parameters:
label Parameter label
usage Usage program (displayed if label not found)
Returns:
parameter value

Definition at line 401 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), ArgMgrUsage(), and ArgMgrValue().

00402 {
00403    return      ( (ArgMgrDefined(label) ) 
00404                ? (ArgMgrValue(label) ) 
00405                : (ArgMgrUsage(usage),(char*)0) );
00406 }

void GDCM_NAME_SPACE::ArgMgr::ArgStdArgs void   )  [private]
 

Definition at line 874 of file gdcmArgMgr.cxx.

References Appel, ARG_DEFAULT_LOGFILE, ARG_DEFAULT_PARAMOUT, ARG_LABEL_LOGFILE, ARG_LABEL_PARAMOUT, ArgMgrValue(), and ArgParamOut.

00875 {
00876   char *logfile;
00877   FILE *fd;
00878 
00879   if ( (ArgParamOut=ArgMgrValue((char*)ARG_LABEL_PARAMOUT))==0 )
00880     ArgParamOut = ARG_DEFAULT_PARAMOUT;
00881   if ( (logfile = ArgMgrValue((char*)ARG_LABEL_LOGFILE))!=0) 
00882   {
00883     if ( *logfile == '\0' )
00884        logfile = (char *)ARG_DEFAULT_LOGFILE;
00885     fd = fopen ( logfile, "a+" );
00886     if ( fd ) 
00887     {
00888       fprintf ( fd, "%s\n", Appel );
00889       fclose  ( fd );
00890     }
00891   }
00892 }

int GDCM_NAME_SPACE::ArgMgr::FiltreLong const char *   )  [private]
 

Definition at line 779 of file gdcmArgMgr.cxx.

References ARG_LONG_MAX.

Referenced by ArgMgr().

00780 {
00781   int  n = 0 ;
00782   while ( (n++<ARG_LONG_MAX) && (*(arg++) != '\0') ) ;
00783   return (n>=ARG_LONG_MAX) ;
00784 }

int GDCM_NAME_SPACE::ArgMgr::IdStrCountChar char *  chaine,
int  caract
[private]
 

Counts the nb of occurrences of a given charact within a 'string'.

Parameters:
chaine Pointer to the 'string'
caract charact to count
Returns:
occurence number

Definition at line 589 of file gdcmArgMgr.cxx.

Referenced by ArgMgrGetListOfFloat(), ArgMgrGetListOfInt(), ArgMgrGetListOfString(), IdStrFloatEnum(), IdStrIntEnum(), and IdStrXInt16Enum().

00590 {
00591   int i=0;
00592   char *ptr;
00593   for ( ptr = chaine ; *ptr!='\0' ; ptr ++ ) 
00594      if (*ptr==caract) 
00595         i++;  
00596   return i;
00597 }

float * GDCM_NAME_SPACE::ArgMgr::IdStrFloatEnum char *  value,
int *  number
[private]
 

returns an array of 'FLOAT pairs'

Parameters:
value char array decribing a set of 'FLOAT pairs' (f1-l1, f2-l2, ...)
number nb of found pairs
Returns:
pointer to the array of 'FLOAT pairs'; NULL if fail

Definition at line 703 of file gdcmArgMgr.cxx.

References IdStrCountChar().

Referenced by ArgMgrGetFloatEnum().

00704 {
00705    float *liste;
00706    int taille;
00707    int i;
00708    *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00709    taille= *number;
00710    liste = (float *) calloc (1,sizeof(float)*2*taille );
00711    if ( !liste )
00712       return 0;
00713    i=0;
00714    while ( taille>0 ) 
00715    {
00716       liste[i] = (float) strtod ( value, &value );      
00717       if ( *value == '\0' ) 
00718       {
00719          liste[i+1]=liste[i];
00720          return liste;
00721       }
00722       if ( *(value++) != '-' ) 
00723       {
00724          liste[i+1]=liste[i];
00725          value--;
00726       }
00727       else
00728       {
00729           liste[i+1] = (float) strtod ( value, &value );
00730       }
00731       if ( *value == '\0' ) 
00732          return liste;
00733       if ( *(value++) != ',' )
00734       {
00735          free (liste);
00736          return 0;
00737       }
00738       taille --; i+=2;
00739    }
00740    return liste;
00741 }

int * GDCM_NAME_SPACE::ArgMgr::IdStrIntEnum char *  value,
int *  number
[private]
 

returns an array of 'INT pairs'

Parameters:
value char array decribing a set of 'INT pairs' (f1-l1, f2-l2, ...)
number nb of found INT pairs
Returns:
pointer to the array of 'INT pairs'

Definition at line 605 of file gdcmArgMgr.cxx.

References IdStrCountChar().

Referenced by ArgMgrGetIntEnum().

00606 {
00607    int* liste;
00608    int taille;
00609    int i;
00610 
00611    *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00612    taille= *number;
00613    liste = (int *) calloc (1,sizeof(int)*2*taille );
00614    if ( !liste )
00615    {
00616       return 0;
00617    }
00618    i=0;
00619    while ( taille>0 ) 
00620    {
00621       liste[i] = (int) strtol ( value, &value, 10 );
00622       if ( *value == '\0' ) 
00623       {
00624          liste[i+1]=liste[i];
00625          return liste;
00626       }
00627       if ( *(value++) != '-' ) 
00628       {
00629          liste[i+1]=liste[i];
00630          value--;
00631        }
00632        else
00633        {
00634           liste[i+1] = (int) strtol ( value, &value, 10 );
00635        }
00636        if ( *value == '\0' )
00637           return liste;
00638        if ( *(value++) != ',' )
00639        {
00640           free (liste);
00641           return 0;
00642        }
00643        taille --; i+=2;
00644    }
00645    return liste;
00646 }

uint16_t * GDCM_NAME_SPACE::ArgMgr::IdStrXInt16Enum char *  value,
int *  number
[private]
 

returns an array of set of 'INT16 pairs', passed in Hexadecimal

Parameters:
value char array decribing a set of 'INT16 pairs' (f1-l1, f2-l2, ...) coded in hexadecimal e.g. 0x0008,0x00ac
number nb of found pairs
Returns:
array of set of 'INT16 pairs'

Definition at line 655 of file gdcmArgMgr.cxx.

References IdStrCountChar().

Referenced by ArgMgrGetXInt16Enum().

00656 {
00657    uint16_t *liste;
00658    int taille;
00659    int i;
00660 
00661    *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00662    taille= *number;
00663    liste = (uint16_t *) calloc (1,sizeof(uint16_t)*2*taille );
00664    if ( !liste )
00665    {
00666       return 0;
00667    }
00668    i=0;
00669    while ( taille>0 ) 
00670    {
00671       liste[i] = (uint16_t) strtol ( value, &value, 16 );
00672       if ( *value == '\0' ) 
00673       {
00674          liste[i+1]=liste[i];
00675          return liste;
00676       }
00677       if ( *(value++) != '-' ) 
00678       {
00679          liste[i+1]=liste[i];
00680          value--;
00681        }
00682        else
00683        {
00684           liste[i+1] = (uint16_t) strtol ( value, &value, 16 );
00685        }
00686        if ( *value == '\0' )
00687           return liste;
00688        if ( *(value++) != ',' )
00689        {
00690           free (liste);
00691           return 0;
00692        }
00693        taille --; i+=2;
00694    }
00695    return liste;
00696 } 

const char * GDCM_NAME_SPACE::ArgMgr::LoadedParam const char *  ,
FILE * 
[private]
 

Definition at line 795 of file gdcmArgMgr.cxx.

References ARG_LONG_MAX.

Referenced by ArgLoadFromFile().

00796 {
00797   int    carlu;
00798   char  *car = (char *)param;
00799   int    quote = false;
00800   int    nbcar = 0;
00801 
00802   /* remove spaces at the beginning****/
00803   while ( isspace(carlu=fgetc (fd)) );
00804   if (carlu==EOF)
00805      return 0;
00806   /* Search for a " */
00807   if ( carlu=='\"' ) 
00808   {
00809     carlu=fgetc(fd);
00810     quote=true;
00811   /* Read all the characters */
00812   }
00813   while (  (carlu!=EOF)
00814         && (  ( (!quote)&&(!isspace(carlu)) )
00815          ||( (quote)&& !(carlu=='\"')   ) ) ) 
00816   {
00817      *(car++) = (char) carlu;
00818      nbcar ++;
00819   /* sans depasser la taille max*/
00820      if ( nbcar >= ARG_LONG_MAX ) 
00821      {
00822         std::cout << "\nError: Argument too long ( > "
00823                   << ARG_LONG_MAX << ")in parameter file."
00824                   << std::endl;
00825         break;
00826      }
00827      carlu = fgetc(fd);
00828   }
00829   *car = '\0';
00830   return param;
00831 }

char * GDCM_NAME_SPACE::ArgMgr::maj char *   )  [private]
 

Definition at line 899 of file gdcmArgMgr.cxx.

00900 {
00901    char *b = a;
00902    while ( *b !=0 ) 
00903    {
00904       if ( *b<='z' && *b>='a' ) *b = *b+'A'-'a';
00905       b++;
00906    }
00907    return a;
00908 }

char * GDCM_NAME_SPACE::ArgMgr::Majuscule const char *   )  [private]
 

Definition at line 757 of file gdcmArgMgr.cxx.

Referenced by ArgMgrDefined().

00758 {
00759   char *ptr, *ptr2, *ptr3;
00760   ptr2 = (char *)malloc(strlen(chaine)*sizeof(char)+1);
00761   ptr3=ptr2;
00762   for ( ptr = (char *)chaine ; *ptr!='\0' ; ptr ++ ) 
00763    {  
00764        *ptr3 = toupper ( * ptr ); ptr3++; 
00765    }
00766   *ptr3='\0'; 
00767   return ptr2;
00768 }


Member Data Documentation

char* GDCM_NAME_SPACE::ArgMgr::Appel [private]
 

Definition at line 108 of file gdcmArgMgr.h.

Referenced by ArgMgr(), ArgStdArgs(), and ~ArgMgr().

int GDCM_NAME_SPACE::ArgMgr::ArgCount [private]
 

Definition at line 107 of file gdcmArgMgr.h.

Referenced by ArgLoadFromFile(), and ArgMgr().

char* GDCM_NAME_SPACE::ArgMgr::ArgLab[ARGMAXCOUNT] [private]
 

Definition at line 105 of file gdcmArgMgr.h.

Referenced by ArgLoadFromFile(), ArgMgrDefined(), ArgMgrUnused(), and ~ArgMgr().

const char* GDCM_NAME_SPACE::ArgMgr::ArgParamOut [private]
 

Definition at line 102 of file gdcmArgMgr.h.

Referenced by ArgMgrSave(), and ArgStdArgs().

char* GDCM_NAME_SPACE::ArgMgr::ArgStr[ARGMAXCOUNT] [private]
 

Definition at line 106 of file gdcmArgMgr.h.

Referenced by ArgMgrValue().

char* GDCM_NAME_SPACE::ArgMgr::ArgUsed [private]
 

Definition at line 104 of file gdcmArgMgr.h.

Referenced by ArgMgr(), ArgMgrDefined(), ArgMgrUnused(), and ~ArgMgr().


The documentation for this class was generated from the following files:
Generated on Fri Aug 24 13:01:20 2007 for gdcm by  doxygen 1.4.6