Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

gdcm::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.
char * ArgMgrUnused (void)
 Search for the first not yet used label.
int ArgMgrSave (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 );.
char * ArgMgrGetString (const char *param, char *)
 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, 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 (char *)
const char * LoadedParam (const char *, FILE *)
int ArgLoadFromFile (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::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 39 of file gdcmArgMgr.cxx.

References Appel, ARG_LONG_MAX, ArgCount, ArgLab, ArgLoadFromFile(), ARGMAXCOUNT, ArgStdArgs(), ArgStr, ArgUsed, FiltreLong(), and Majuscule().

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

gdcm::ArgMgr::~ArgMgr  ) 
 

canonical destructor

Definition at line 106 of file gdcmArgMgr.cxx.

References Appel, ArgCount, ArgLab, and ArgUsed.

00107 {
00108    for(int i=0;i<ArgCount;i++)
00109       if ( ArgLab[i] )
00110          free(ArgLab[i]);
00111    if ( ArgUsed )
00112       free(ArgUsed);
00113    if ( Appel )
00114       free(Appel);
00115 }


Member Function Documentation

int gdcm::ArgMgr::ArgLoadFromFile char *   )  [private]
 

Definition at line 827 of file gdcmArgMgr.cxx.

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

Referenced by ArgMgr().

00828 {
00829   int   nbl = 0;
00830   char  param[ARG_LONG_MAX+1];
00831   FILE  *fch;
00832 
00833   fch = fopen ( filename, ID_RFILE_TEXT );
00834   while ( LoadedParam (param, fch ) )
00835   {
00836     int n = strlen(param);
00837     if ( param[0]=='@' )
00838     {
00839       nbl  += ArgLoadFromFile ( &param[1] );
00840     }
00841     else
00842     {
00843       ArgLab [ArgCount] = strcpy ((char *) malloc(n+1), param ) ;
00844       nbl += n + 1 ;
00845       ArgCount++;
00846       if ( ArgCount >= ARGMAXCOUNT ) 
00847          break;
00848     }
00849   }
00850   fclose ( fch );
00851   return nbl;
00852 }

int gdcm::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 123 of file gdcmArgMgr.cxx.

References ArgCount, ArgLab, ArgUsed, and Majuscule().

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

00124 {
00125   int i;
00126   bool trouve;
00127   char *temp;
00128   temp = Majuscule ( param ) ;
00129   for ( i = ArgCount-1; i>0; i-- )
00130   { 
00131     trouve = ( strcmp( ArgLab[i], temp )==0 ) ;
00132     if ( trouve )
00133     {
00134       ArgUsed[i] = true ;           
00135       for ( int j=1; j<i; j++)
00136       {                     
00137          if ( (!ArgUsed[j])&&(!strcmp(ArgLab[i],ArgLab[j])) )
00138             ArgUsed[j] = i ;
00139       }
00140       return i ;
00141     }
00142   }
00143   return 0 ;
00144 }

float gdcm::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 265 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgMgrValue().

00266 {
00267    return     ( (ArgMgrDefined(param))
00268                ? ((float)atof(ArgMgrValue(param)))
00269                : (defaultVal) );
00270 }

float * gdcm::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 552 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrFloatEnum().

00553 {
00554    char  *value = ArgMgrValue(param);
00555    float *liste;
00556    if (!value) 
00557    {
00558       *number = 0; 
00559       return 0;
00560    }
00561    liste = IdStrFloatEnum(value, number);
00562    return liste;
00563 }

int gdcm::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 250 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgMgrValue().

00251 {
00252    return ( (ArgMgrDefined(label))
00253             ? (atoi(ArgMgrValue(label)))
00254             : (defaultVal) );
00255 }

int * gdcm::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 514 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrIntEnum().

00515 {
00516    char *value = ArgMgrValue(param);
00517    int *liste;
00518    if (!value) 
00519    {
00520       *number = 0; 
00521       return 0;
00522    }
00523    liste = IdStrIntEnum(value, number);
00524    return liste;
00525 }

int gdcm::ArgMgr::ArgMgrGetLabel const char *  param,
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 298 of file gdcmArgMgr.cxx.

References ArgMgrGetString(), and maj().

00299 {
00300   char *lab;
00301   char *vallab;
00302   int i = 1;
00303   char *tmp;
00304   tmp = (char *) malloc(strlen(liste)+1);
00305   strcpy(tmp,liste);
00306 
00307   if ( (vallab = ArgMgrGetString(param,(char *)NULL)) != 0 ) 
00308   { 
00309      for ( lab = strtok (tmp,"\\"); 
00310            lab != 0; 
00311            lab = strtok(0L,"\\"), i++ )
00312      { 
00313         if ( strcmp(maj(lab),maj(vallab))==0)
00314            return i;
00315      } 
00316      val=0;
00317    }
00318    free(tmp);
00319    return val;
00320 }

float * gdcm::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 474 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrCountChar().

00475 {
00476   char *value = ArgMgrValue(label);
00477   float *liste;
00478   float *elem;
00479   int taille;
00480   if (!value)
00481     return 0;
00482   *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00483   taille= *number;
00484   liste = (float *) calloc (1,sizeof(float)*taille );
00485   if ( !liste )
00486   {
00487      *number = 0;
00488      return 0;
00489   }
00490   elem = liste;
00491   //*number = 1;
00492 
00493   while ( taille>0 ) 
00494   {
00495     *(elem++) = (float) strtod ( value, &value );      
00496     if ( *value == '\0' )
00497        return liste;
00498     if ( *(value++) != ',' )
00499     {
00500       free (liste);
00501       return 0;
00502     }
00503     taille --;
00504   }
00505 return liste;
00506 }

int * gdcm::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 434 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrCountChar().

00435 {
00436   char *value = ArgMgrValue(label);
00437   int *liste;
00438   int *elem;
00439   int taille;
00440   if (!value)
00441   {
00442      *number = 0;
00443      return 0;
00444   }          
00445   *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */ 
00446   taille= *number;
00447   liste = (int *) calloc (1,sizeof(int)*taille );
00448   if ( !liste )
00449      return 0;
00450   elem = liste;
00451   //*number = 1;
00452 
00453   while ( taille>0 ) 
00454   {
00455     *(elem++) = (int) strtol ( value, &value, 10 );      
00456     if ( *value == '\0' )
00457        return liste;
00458     if ( *(value++) != ',' ) 
00459     {
00460       free (liste);
00461       return 0;
00462     }
00463     taille --;
00464   }
00465 return liste;
00466 }

char ** gdcm::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 400 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrCountChar().

00401 {
00402   int taille;
00403   char  *value = ArgMgrValue(label);
00404   char **liste;
00405   char **elem;
00406   char  *chainecur; 
00407   if (!value)
00408   {
00409      *number = 0;
00410      return 0;
00411   }
00412   *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00413   taille = *number;
00414   liste = (char **) malloc (sizeof(char*) * taille + strlen(value)+1);
00415   if ( !liste )
00416      return 0;
00417   value = strcpy( ((char*)liste)+sizeof(char*) * taille, value );
00418   for ( elem = liste, chainecur = strtok(value,", ");
00419         taille>0;
00420         taille--, chainecur = (chainecur) ? strtok ( 0, ", " ) : 0 )
00421   {
00422     *(elem++) = chainecur;
00423   }
00424   return liste;
00425 }

char * gdcm::ArgMgr::ArgMgrGetString const char *  param,
char *  defaultVal
 

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 280 of file gdcmArgMgr.cxx.

References ArgMgrDefined(), and ArgMgrValue().

Referenced by ArgMgrGetLabel(), and ArgMgrWantLabel().

00281 {
00282    return    ( (ArgMgrDefined(param)) 
00283               ? (ArgMgrValue(param))
00284               : (defaultVal) );
00285 }

uint16_t * gdcm::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 533 of file gdcmArgMgr.cxx.

References ArgMgrValue(), and IdStrXInt16Enum().

00534 {
00535    char *value = ArgMgrValue(param);
00536    uint16_t *liste;
00537    if (!value) 
00538    {
00539       *number = 0; 
00540       return 0;
00541    }
00542    liste = IdStrXInt16Enum(value, number);
00543    return liste;
00544 }

int gdcm::ArgMgr::ArgMgrPrintUnusedLabels void   ) 
 

Prints unused labels, if any.

Returns:
number of unused labels

Definition at line 183 of file gdcmArgMgr.cxx.

References ArgMgrUnused(), and ArgMgrValue().

00184 {
00185    char *label;
00186    int i=0;
00187    while ( (label=ArgMgrUnused())!=0 )
00188    {
00189       if (i==0)
00190          std::cout << "\n Unused Labels:" << std::endl
00191                    << "=============="    << std::endl;
00192       std::cout << "Label : " << label << " = " 
00193                 << ArgMgrValue(label) << std::endl;
00194       i++;
00195    }
00196    return i;
00197 }

int gdcm::ArgMgr::ArgMgrSave 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 220 of file gdcmArgMgr.cxx.

References ArgParamOut.

00221 {
00222    static int   deja = 0;
00223    FILE         *fd;
00224    if ( *ArgParamOut == '\0' )
00225       return 0;
00226    if ( deja ) 
00227    {
00228       fd = fopen ( ArgParamOut, "a+" );
00229    }
00230    else
00231    {
00232       deja = 1;
00233       fd = fopen ( ArgParamOut, "w" );
00234    } 
00235    if ( !fd ) 
00236       return 0;
00237    fprintf ( fd, "%s\n", param );
00238    fclose  ( fd );
00239    return 1;
00240 }

char * gdcm::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 165 of file gdcmArgMgr.cxx.

References ArgCount, ArgLab, ArgMgrDefined(), and ArgUsed.

Referenced by ArgMgrPrintUnusedLabels().

00166 {
00167    int i ;
00168    for ( i=ArgCount-1; i>0; i-- )
00169    {
00170       if ( ! ArgUsed[i] )
00171       {
00172          ArgMgrDefined(ArgLab[i]);
00173          return ArgLab[i] ;
00174       }
00175   }
00176   return NULL ;
00177 }

int gdcm::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 204 of file gdcmArgMgr.cxx.

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

00205 {
00206    while ( *usage ) 
00207       std::cout << std::endl << *(usage++);
00208    std::cout << std::endl; 
00209    return (0);
00210 }

char * gdcm::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 152 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().

00153 {
00154    int trouve ;
00155    if ( (trouve = ArgMgrDefined ( param )) != false )
00156       return ArgStr[trouve] ;
00157    else
00158       return NULL ;
00159 }

float gdcm::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 371 of file gdcmArgMgr.cxx.

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

00372 {
00373    return       ( (ArgMgrDefined(label) ) 
00374                 ? ((float)atof(ArgMgrValue(label) ) ) 
00375                 : (ArgMgrUsage(usage),(float)1.0) );
00376 }

int gdcm::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 356 of file gdcmArgMgr.cxx.

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

00357 {
00358    return        ( (ArgMgrDefined(label) ) 
00359                  ? (atoi(ArgMgrValue(label) ) ) 
00360                  : (ArgMgrUsage(usage),1) );
00361 }

int gdcm::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.
usage Usage program (displayed if label not found)
Returns:
int : range of value amongst the values list

Definition at line 332 of file gdcmArgMgr.cxx.

References ArgMgrGetString(), ArgMgrUsage(), and maj().

00333 {
00334    char *lab;
00335    char *vallab;
00336    int i = 1;
00337    if ( (vallab = ArgMgrGetString(param,0)) != 0 ) 
00338    {
00339       for ( lab = strtok (liste,"\\"); lab != 0; lab = strtok(0L,"\\"), i++ )
00340         if ( strcmp(maj(lab),maj(vallab))==0) 
00341            return i;
00342       return 0;
00343    }
00344    ArgMgrUsage(usage);
00345    return 0;
00346 }

char * gdcm::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 386 of file gdcmArgMgr.cxx.

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

00387 {
00388    return      ( (ArgMgrDefined(label) ) 
00389                ? (ArgMgrValue(label) ) 
00390                : (ArgMgrUsage(usage),(char*)0) );
00391 }

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

Definition at line 859 of file gdcmArgMgr.cxx.

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

Referenced by ArgMgr().

00860 {
00861   char *logfile;
00862   FILE *fd;
00863 
00864   if ( (ArgParamOut=ArgMgrValue((char*)ARG_LABEL_PARAMOUT))==0 )
00865     ArgParamOut = ARG_DEFAULT_PARAMOUT;
00866   if ( (logfile = ArgMgrValue((char*)ARG_LABEL_LOGFILE))!=0) 
00867   {
00868     if ( *logfile == '\0' )
00869        logfile = (char *)ARG_DEFAULT_LOGFILE;
00870     fd = fopen ( logfile, "a+" );
00871     if ( fd ) 
00872     {
00873       fprintf ( fd, "%s\n", Appel );
00874       fclose  ( fd );
00875     }
00876   }
00877 }

int gdcm::ArgMgr::FiltreLong char *   )  [private]
 

Definition at line 764 of file gdcmArgMgr.cxx.

References ARG_LONG_MAX.

Referenced by ArgMgr().

00765 {
00766   int  n = 0 ;
00767   while ( (n++<ARG_LONG_MAX) && (*(arg++) != '\0') ) ;
00768   return (n>=ARG_LONG_MAX) ;
00769 }

int gdcm::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 574 of file gdcmArgMgr.cxx.

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

00575 {
00576   int i=0;
00577   char *ptr;
00578   for ( ptr = chaine ; *ptr!='\0' ; ptr ++ ) 
00579      if (*ptr==caract) 
00580         i++;  
00581   return i;
00582 }

float * gdcm::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 688 of file gdcmArgMgr.cxx.

References IdStrCountChar().

Referenced by ArgMgrGetFloatEnum().

00689 {
00690    float *liste;
00691    int taille;
00692    int i;
00693    *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00694    taille= *number;
00695    liste = (float *) calloc (1,sizeof(float)*2*taille );
00696    if ( !liste )
00697       return 0;
00698    i=0;
00699    while ( taille>0 ) 
00700    {
00701       liste[i] = (float) strtod ( value, &value );      
00702       if ( *value == '\0' ) 
00703       {
00704          liste[i+1]=liste[i];
00705          return liste;
00706       }
00707       if ( *(value++) != '-' ) 
00708       {
00709          liste[i+1]=liste[i];
00710          value--;
00711       }
00712       else
00713       {
00714           liste[i+1] = (float) strtod ( value, &value );
00715       }
00716       if ( *value == '\0' ) 
00717          return liste;
00718       if ( *(value++) != ',' )
00719       {
00720          free (liste);
00721          return 0;
00722       }
00723       taille --; i+=2;
00724    }
00725    return liste;
00726 }

int * gdcm::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 590 of file gdcmArgMgr.cxx.

References IdStrCountChar().

Referenced by ArgMgrGetIntEnum().

00591 {
00592    int* liste;
00593    int taille;
00594    int i;
00595 
00596    *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00597    taille= *number;
00598    liste = (int *) calloc (1,sizeof(int)*2*taille );
00599    if ( !liste )
00600    {
00601       return 0;
00602    }
00603    i=0;
00604    while ( taille>0 ) 
00605    {
00606       liste[i] = (int) strtol ( value, &value, 10 );
00607       if ( *value == '\0' ) 
00608       {
00609          liste[i+1]=liste[i];
00610          return liste;
00611       }
00612       if ( *(value++) != '-' ) 
00613       {
00614          liste[i+1]=liste[i];
00615          value--;
00616        }
00617        else
00618        {
00619           liste[i+1] = (int) strtol ( value, &value, 10 );
00620        }
00621        if ( *value == '\0' )
00622           return liste;
00623        if ( *(value++) != ',' )
00624        {
00625           free (liste);
00626           return 0;
00627        }
00628        taille --; i+=2;
00629    }
00630    return liste;
00631 }

uint16_t * gdcm::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 640 of file gdcmArgMgr.cxx.

References IdStrCountChar().

Referenced by ArgMgrGetXInt16Enum().

00641 {
00642    uint16_t *liste;
00643    int taille;
00644    int i;
00645 
00646    *number = IdStrCountChar(value,',')+1; /* nb Elements = nb Commas +1 */
00647    taille= *number;
00648    liste = (uint16_t *) calloc (1,sizeof(uint16_t)*2*taille );
00649    if ( !liste )
00650    {
00651       return 0;
00652    }
00653    i=0;
00654    while ( taille>0 ) 
00655    {
00656       liste[i] = (uint16_t) strtol ( value, &value, 16 );
00657       if ( *value == '\0' ) 
00658       {
00659          liste[i+1]=liste[i];
00660          return liste;
00661       }
00662       if ( *(value++) != '-' ) 
00663       {
00664          liste[i+1]=liste[i];
00665          value--;
00666        }
00667        else
00668        {
00669           liste[i+1] = (uint16_t) strtol ( value, &value, 16 );
00670        }
00671        if ( *value == '\0' )
00672           return liste;
00673        if ( *(value++) != ',' )
00674        {
00675           free (liste);
00676           return 0;
00677        }
00678        taille --; i+=2;
00679    }
00680    return liste;
00681 } 

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

Definition at line 780 of file gdcmArgMgr.cxx.

References ARG_LONG_MAX.

Referenced by ArgLoadFromFile().

00781 {
00782   int    carlu;
00783   char  *car = (char *)param;
00784   int    quote = false;
00785   int    nbcar = 0;
00786 
00787   /* remove spaces at the beginning****/
00788   while ( isspace(carlu=fgetc (fd)) );
00789   if (carlu==EOF)
00790      return 0;
00791   /* Search for a " */
00792   if ( carlu=='\"' ) 
00793   {
00794     carlu=fgetc(fd);
00795     quote=true;
00796   /* Read all the characters */
00797   }
00798   while (  (carlu!=EOF)
00799         && (  ( (!quote)&&(!isspace(carlu)) )
00800          ||( (quote)&& !(carlu=='\"')   ) ) ) 
00801   {
00802      *(car++) = (char) carlu;
00803      nbcar ++;
00804   /* sans depasser la taille max*/
00805      if ( nbcar >= ARG_LONG_MAX ) 
00806      {
00807         std::cout << "\nError: Argument too long ( > "
00808                   << ARG_LONG_MAX << ")in parameter file."
00809                   << std::endl;
00810         break;
00811      }
00812      carlu = fgetc(fd);
00813   }
00814   *car = '\0';
00815   return param;
00816 }

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

Definition at line 884 of file gdcmArgMgr.cxx.

Referenced by ArgMgrGetLabel(), and ArgMgrWantLabel().

00885 {
00886    char *b = a;
00887    while ( *b !=0 ) 
00888    {
00889       if ( *b<='z' && *b>='a' ) *b = *b+'A'-'a';
00890       b++;
00891    }
00892    return a;
00893 }

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

Definition at line 742 of file gdcmArgMgr.cxx.

Referenced by ArgMgr(), and ArgMgrDefined().

00743 {
00744   char *ptr, *ptr2, *ptr3;
00745   ptr2 = (char *)malloc(strlen(chaine)*sizeof(char)+1);
00746   ptr3=ptr2;
00747   for ( ptr = (char *)chaine ; *ptr!='\0' ; ptr ++ ) 
00748    {  
00749        *ptr3 = toupper ( * ptr ); ptr3++; 
00750    }
00751   *ptr3='\0'; 
00752   return ptr2;
00753 }


Member Data Documentation

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

Definition at line 108 of file gdcmArgMgr.h.

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

int gdcm::ArgMgr::ArgCount [private]
 

Definition at line 107 of file gdcmArgMgr.h.

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

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

Definition at line 105 of file gdcmArgMgr.h.

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

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

Definition at line 102 of file gdcmArgMgr.h.

Referenced by ArgMgrSave(), and ArgStdArgs().

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

Definition at line 106 of file gdcmArgMgr.h.

Referenced by ArgMgr(), and ArgMgrValue().

char* gdcm::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 Jan 20 10:14:31 2006 for gdcm by  doxygen 1.4.4