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 #ifndef OFCMDLN_H
00031 #define OFCMDLN_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034 #include "dcmtk/ofstd/oftypes.h"
00035 #include "dcmtk/ofstd/oflist.h"
00036 #include "dcmtk/ofstd/ofstring.h"
00037 #include "dcmtk/ofstd/ofconsol.h"
00038
00039 #define INCLUDE_CSTDIO
00040 #include "dcmtk/ofstd/ofstdinc.h"
00041
00042
00043
00044
00045
00046
00048 typedef signed long OFCmdSignedInt;
00050 typedef unsigned long OFCmdUnsignedInt;
00052 typedef double OFCmdFloat;
00054 typedef OFString OFCmdString;
00055
00056
00057 typedef OFListIterator(OFString) OFListIterator_OFString;
00058
00059
00060
00061
00062
00063
00064 struct OFCmdOption;
00065 struct OFCmdParamPos;
00066
00067
00068
00069
00070
00071
00075 struct OFCmdParam
00076 {
00077
00080 enum E_ParamMode
00081 {
00083 PM_Mandatory,
00085 PM_Optional,
00087 PM_MultiMandatory,
00089 PM_MultiOptional
00090 };
00091
00098 OFCmdParam(const char *param,
00099 const char *descr,
00100 const E_ParamMode mode)
00101 : ParamName(param),
00102 ParamDescription(descr),
00103 ParamMode(mode)
00104 {
00105 }
00106
00108 const OFString ParamName;
00110 const OFString ParamDescription;
00112 const E_ParamMode ParamMode;
00113
00114 private:
00115
00117 OFCmdParam& operator=(const OFCmdParam& arg);
00118 };
00119
00120
00121
00122
00123
00124
00129 class OFCommandLine
00130 {
00131
00132 public:
00133
00134
00135
00138 enum E_ParseStatus
00139 {
00141 PS_Normal,
00143 PS_NoArguments,
00145 PS_ExclusiveOption,
00147 PS_UnknownOption,
00149 PS_MissingValue,
00151 PS_MissingParameter,
00153 PS_TooManyParameters,
00155 PS_CannotOpenCommandFile
00156 };
00157
00158
00161 enum E_ValueStatus
00162 {
00164 VS_Normal,
00166 VS_Invalid,
00168 VS_NoMore,
00170 VS_Empty,
00172 VS_Underflow,
00174 VS_Overflow
00175 };
00176
00177
00180 enum E_ParamValueStatus
00181 {
00183 PVS_Normal,
00185 PVS_Invalid,
00187 PVS_CantFind,
00189 PVS_Empty,
00191 PVS_Underflow,
00193 PVS_Overflow
00194 };
00195
00198 enum E_FindOptionMode
00199 {
00201 FOM_Normal,
00203 FOM_First,
00205 FOM_Next,
00207 FOM_FirstFromLeft,
00209 FOM_NextFromLeft
00210 };
00211
00212
00213
00214
00217 OFCommandLine();
00218
00221 virtual ~OFCommandLine();
00222
00223
00224
00225
00230 void setOptionChars(const char *chars);
00231
00237 void setOptionColumns(const int longCols,
00238 const int shortCols);
00239
00244 void setParamColumn(const int column);
00245
00258 OFBool addOption(const char *longOpt,
00259 const char *shortOpt,
00260 const int valueCount,
00261 const char *valueDescr,
00262 const char *optDescr,
00263 const int flags = 0);
00264
00275 OFBool addOption(const char *longOpt,
00276 const char *shortOpt,
00277 const char *optDescr,
00278 const int flags = 0);
00279
00291 OFBool addOption(const char *longOpt,
00292 const int valueCount,
00293 const char *valueDescr,
00294 const char *optDescr,
00295 const int flags = 0);
00296
00306 OFBool addOption(const char *longOpt,
00307 const char *optDescr,
00308 const int flags = 0);
00309
00317 void addGroup(const char *name,
00318 const int longCols = 0,
00319 const int shortCols = 0);
00320
00328 void addSubGroup(const char *name,
00329 const int longCols = 0,
00330 const int shortCols = 0);
00331
00341 OFBool addParam(const char *param,
00342 const char *descr,
00343 const OFCmdParam::E_ParamMode mode = OFCmdParam::PM_Mandatory);
00344
00353 OFBool addParam(const char *param,
00354 const OFCmdParam::E_ParamMode mode = OFCmdParam::PM_Mandatory);
00355
00356
00357
00358
00363 const OFString &getProgramName() const
00364 {
00365 return ProgramName;
00366 }
00367
00373 int getArgCount() const
00374 {
00375 return OFstatic_cast(int, ArgumentList.size());
00376 }
00377
00383 OFBool gotoFirstArg();
00384
00390 OFBool gotoNextArg();
00391
00399 OFBool getCurrentArg(const char *&arg);
00400
00409 OFBool getCurrentArg(OFCmdString &arg);
00410
00416 int getParamCount() const
00417 {
00418 return OFstatic_cast(int, ParamPosList.size());
00419 }
00420
00425 int getMinParamCount() const
00426 {
00427 return MinParamCount;
00428 }
00429
00434 int getMaxParamCount() const
00435 {
00436 return MaxParamCount;
00437 }
00438
00445 OFBool hasExclusiveOption() const
00446 {
00447 return ExclusiveOption;
00448 }
00449
00450
00451
00452
00459 OFBool findParam(const int pos);
00460
00468 E_ParamValueStatus getParam(const int pos,
00469 OFCmdSignedInt &value);
00470
00480 E_ParamValueStatus getParamAndCheckMin(const int pos,
00481 OFCmdSignedInt &value,
00482 const OFCmdSignedInt low,
00483 const OFBool incl = OFTrue);
00484
00494 E_ParamValueStatus getParamAndCheckMinMax(const int pos,
00495 OFCmdSignedInt &value,
00496 const OFCmdSignedInt low,
00497 const OFCmdSignedInt high);
00498
00508 E_ParamValueStatus getParam(const int pos,
00509 OFCmdUnsignedInt &value);
00510
00522 E_ParamValueStatus getParamAndCheckMin(const int pos,
00523 OFCmdUnsignedInt &value,
00524 const OFCmdUnsignedInt low,
00525 const OFBool incl = OFTrue);
00526
00538 E_ParamValueStatus getParamAndCheckMinMax(const int pos,
00539 OFCmdUnsignedInt &value,
00540 const OFCmdUnsignedInt low,
00541 const OFCmdUnsignedInt high);
00542
00550 E_ParamValueStatus getParam(const int pos,
00551 OFCmdFloat &value);
00552
00562 E_ParamValueStatus getParamAndCheckMin(const int pos,
00563 OFCmdFloat &value,
00564 const OFCmdFloat low,
00565 const OFBool incl = OFTrue);
00566
00576 E_ParamValueStatus getParamAndCheckMinMax(const int pos,
00577 OFCmdFloat &value,
00578 const OFCmdFloat low,
00579 const OFCmdFloat high);
00580
00588 E_ParamValueStatus getParam(const int pos,
00589 const char *¶m);
00590
00598 E_ParamValueStatus getParam(const int pos,
00599 OFCmdString ¶m);
00600
00601
00602
00603
00620 OFBool findOption(const char *longOpt,
00621 const signed int pos = 0,
00622 const E_FindOptionMode mode = FOM_Normal);
00623
00629 OFBool gotoFirstOption();
00630
00636 OFBool gotoNextOption();
00637
00646 OFBool getCurrentOption(const char *&opt);
00647
00656 OFBool getCurrentOption(OFCmdString &opt);
00657
00660 void beginOptionBlock();
00661
00664 void endOptionBlock();
00665
00666
00667
00668
00675 E_ValueStatus getValue(OFCmdSignedInt &value);
00676
00685 E_ValueStatus getValueAndCheckMin(OFCmdSignedInt &value,
00686 const OFCmdSignedInt low,
00687 const OFBool incl = OFTrue);
00688
00697 E_ValueStatus getValueAndCheckMinMax(OFCmdSignedInt &value,
00698 const OFCmdSignedInt low,
00699 const OFCmdSignedInt high);
00700
00707 E_ValueStatus getValue(OFCmdUnsignedInt &value);
00708
00717 E_ValueStatus getValueAndCheckMin(OFCmdUnsignedInt &value,
00718 const OFCmdUnsignedInt low,
00719 const OFBool incl = OFTrue);
00720
00729 E_ValueStatus getValueAndCheckMinMax(OFCmdUnsignedInt &value,
00730 const OFCmdUnsignedInt low,
00731 const OFCmdUnsignedInt high);
00732
00739 E_ValueStatus getValue(OFCmdFloat &value);
00740
00749 E_ValueStatus getValueAndCheckMin(OFCmdFloat &value,
00750 const OFCmdFloat low,
00751 const OFBool incl = OFTrue);
00752
00761 E_ValueStatus getValueAndCheckMinMax(OFCmdFloat &value,
00762 const OFCmdFloat low,
00763 const OFCmdFloat high);
00764
00771 E_ValueStatus getValue(const char *&value);
00772
00779 E_ValueStatus getValue(OFCmdString &value);
00780
00781
00782
00783
00796 E_ParseStatus parseLine(int argCount,
00797 char *argValue[],
00798 const int flags = 0,
00799 const int startPos = 1);
00800
00801
00802
00803
00809 void getSyntaxString(OFString &syntaxStr) const;
00810
00817 void getOptionString(OFString &optionStr) const;
00818
00824 void getParamString(OFString ¶mStr) const;
00825
00831 void getStatusString(const E_ParseStatus status,
00832 OFString &statusStr);
00833
00839 void getStatusString(const E_ParamValueStatus status,
00840 OFString &statusStr);
00841
00847 void getStatusString(const E_ValueStatus status,
00848 OFString &statusStr);
00849
00850
00851
00852
00854 static const int PF_ExpandWildcards;
00856 static const int PF_NoCommandFiles;
00857
00858
00859
00861 static const int AF_Exclusive;
00863 static const int AF_Internal;
00866 static const int AF_NoWarning;
00867
00868 protected:
00869
00872 OFBool checkOption(const OFString &option,
00873 const OFBool mode = OFTrue) const;
00874
00877 OFBool findParam(int pos,
00878 OFListIterator(OFCmdParamPos *) &pos_iter);
00879
00882 const OFCmdOption *findCmdOption(const OFString &option) const;
00883
00886 void storeParameter(const OFString ¶m,
00887 const int directOption = 0);
00888
00891 E_ParseStatus parseCommandFile(const char *argValue,
00892 OFList<OFString> &argList);
00893
00896 int packColumnValues(int longCols,
00897 int shortCols) const;
00898
00901 void unpackColumnValues(const int value,
00902 unsigned int &longCols,
00903 unsigned int &shortCols) const;
00904
00905 #ifdef HAVE_WINDOWS_H
00906
00909 void expandWildcards(const OFString ¶m,
00910 int directOption = 0);
00911 #endif
00912
00915 E_ParseStatus checkParamCount();
00916
00919 OFBool getLastArg(OFString &arg);
00920
00923 OFBool getMissingParam(OFString ¶m);
00924
00925
00926 private:
00927
00929 OFString ProgramName;
00930
00932 OFList<OFCmdOption *> ValidOptionList;
00934 OFList<OFCmdParam *> ValidParamList;
00935
00937 OFList<OFString> ArgumentList;
00939 OFListIterator(OFString) ArgumentIterator;
00940
00942 OFList<OFCmdParamPos *> ParamPosList;
00944 OFList<OFListIterator_OFString> OptionPosList;
00946 OFListIterator(OFListIterator_OFString) OptionPosIterator;
00948 OFListIterator(OFListIterator_OFString) OptionBlockIterator;
00949
00951 OFBool OptionBlockMode;
00953 OFString OptionChars;
00954
00956 OFBool ExclusiveOption;
00957
00959 int LongColumn;
00961 int ShortColumn;
00963 int ParamColumn;
00964
00966 int MinParamCount;
00968 int MaxParamCount;
00969
00971 OFCmdParam::E_ParamMode LastParamMode;
00972
00973
00974 private:
00975
00977 OFCommandLine &operator=(const OFCommandLine &obj);
00978 };
00979
00980
00981 #endif
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146