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 #ifndef __cmtkCommandLine_h_included_
00034 #define __cmtkCommandLine_h_included_
00035
00036 #include <cmtkconfig.h>
00037
00038 #include <System/cmtkCannotBeCopied.h>
00039
00040 #include <map>
00041 #include <list>
00042 #include <string>
00043 #include <sstream>
00044 #include <vector>
00045
00046 #include <stdlib.h>
00047 #include <string.h>
00048
00049 #include <System/cmtkSmartPtr.h>
00050 #include <System/cmtkConsole.h>
00051 #include <System/cmtkCommandLineTypeTraits.h>
00052 #include <System/cmtkExitException.h>
00053
00054 #include <mxml.h>
00055
00056 namespace
00057 cmtk
00058 {
00059
00062
00137 class CommandLine :
00139 private CannotBeCopied
00140 {
00141 public:
00143 typedef CommandLine Self;
00144
00146 typedef enum
00147 {
00149 PRG_TITLE = 0,
00151 PRG_DESCR = 1,
00153 PRG_CATEG = 2,
00155 PRG_ACKNL = 3,
00157 PRG_LCNSE = 4,
00159 PRG_CNTRB = 5,
00161 PRG_DOCUM = 6,
00163 PRG_VERSN = 7,
00165 PRG_SYNTX = 100
00166 } ProgramProperties;
00167
00169 typedef enum
00170 {
00172 PROPS_XML = 0,
00174 PROPS_ADVANCED = 1,
00176 PROPS_MULTIPLE = 2,
00178 PROPS_NOXML = 4,
00180 PROPS_DIRNAME = 8,
00182 PROPS_FILENAME = 16,
00184 PROPS_IMAGE = 32,
00186 PROPS_LABELS = 64,
00188 PROPS_XFORM = 128,
00190 PROPS_OUTPUT = 256,
00192 PROPS_OPTIONAL = 512
00193 } ItemProperties;
00194
00196 void SetProgramInfo( const ProgramProperties key, const std::string& value )
00197 {
00198 this->m_ProgramInfo[key] = value;
00199 }
00200
00202 class Exception
00203 {
00204 public:
00206 Exception( const char* message = NULL, const size_t index = 0 ) :
00207 Message( message ), Index( index )
00208 {}
00209
00211 Exception( const std::string& message, const size_t index = 0 ) :
00212 Message( message ), Index( index )
00213 {}
00214
00216 std::string Message;
00217
00219 size_t Index;
00220 };
00221
00223 typedef void (*CallbackFunc)();
00224
00226 typedef void (*CallbackFuncArg)( const char* );
00227
00229 typedef void (*CallbackFuncIntArg)( const long int );
00230
00232 typedef void (*CallbackFuncDblArg)( const double );
00233
00235 typedef void (*CallbackFuncMultiArg)( const char**, int& argsUsed );
00236
00248 class Key
00249 {
00250 public:
00252 explicit Key( const std::string& keyString ) : m_KeyChar( 0 ), m_KeyString( keyString ) {}
00253
00255 explicit Key( const char keyChar, const std::string& keyString ) : m_KeyChar( keyChar ), m_KeyString( keyString ) {}
00256
00258 char m_KeyChar;
00259
00261 std::string m_KeyString;
00262 };
00263
00265 class Item
00266 {
00267 public:
00269 typedef SmartPointer<Item> SmartPtr;
00270
00272 Item() : m_Properties( PROPS_XML ) {};
00273
00275 virtual ~Item() {}
00276
00278 virtual Item* SetProperties( const long int properties )
00279 {
00280 this->m_Properties = properties;
00281 return this;
00282 }
00283
00285 virtual long int GetProperties() const
00286 {
00287 return this->m_Properties;
00288 }
00289
00291 virtual Item* SetAttribute( const std::string& key, const std::string& value )
00292 {
00293 this->m_Attributes[key] = value;
00294 return this;
00295 }
00296
00298 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index ) = 0;
00299
00301 virtual mxml_node_t* MakeXML( mxml_node_t *const parent
00302 ) const = 0;
00303
00305 virtual std::string GetParamTypeString() const { return ""; }
00306
00308 virtual std::ostringstream& PrintHelp( std::ostringstream& fmt
00309 ) const
00310 {
00311
00312 return fmt;
00313 }
00314
00316 virtual void PrintWiki() const
00317 {
00318
00319 }
00320
00322 virtual bool IsDefault() const
00323 {
00324 return false;
00325 }
00326
00327 protected:
00329 long int m_Properties;
00330
00332 std::map<std::string, std::string> m_Attributes;
00333
00335 static long int ConvertStrToLong( const char* str );
00336
00338 static double ConvertStrToDouble( const char* str );
00339
00341 template<class T> T Convert( const char* str );
00342
00344 template<class T>
00345 class Helper
00346 {
00347 public:
00349 static mxml_node_t* MakeXML( const Item* item, mxml_node_t *const parent );
00350
00352 static std::string GetParamTypeString( const Item* item );
00353 };
00354
00355 private:
00357 friend class CommandLine;
00358 };
00359
00360 private:
00362 template<class T>
00363 class Switch :
00365 public Item
00366 {
00367 public:
00369 Switch( T *const field, const T value ) :
00370 m_Field( field ),
00371 m_Value( value )
00372 {
00373 }
00374
00376 virtual ~Switch() {}
00377
00379 virtual void Evaluate( const size_t, const char*[], size_t& )
00380 {
00381 *this->m_Field = this->m_Value;
00382 }
00383
00385 virtual mxml_node_t* MakeXML( mxml_node_t *const parent ) const
00386 {
00387 if ( ! (this->m_Properties & PROPS_NOXML) )
00388 {
00389 return mxmlNewElement( parent, "boolean" );
00390 }
00391 return NULL;
00392 }
00393
00395 virtual std::ostringstream& PrintHelp( std::ostringstream& fmt
00396 ) const
00397 {
00398 if ( this->IsDefault() )
00399 fmt << "\n[This is the default]";
00400 return fmt;
00401 }
00402
00404 virtual void PrintWiki() const
00405 {
00406 if ( this->IsDefault() )
00407 StdOut << " '''[This is the default]'''";
00408 }
00409
00411 virtual bool IsDefault() const
00412 {
00413 return ( *(this->m_Field) == this->m_Value );
00414 }
00415
00416 private:
00418 T* m_Field;
00419
00421 const T m_Value;
00422 };
00423
00425 template<class T>
00426 class Option :
00428 public Item
00429 {
00430 public:
00432 Option( T *const var, bool *const flag ) : Var( var ), Flag( flag ) {}
00433
00435 virtual ~Option() {}
00436
00438 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index );
00439
00441 virtual mxml_node_t* MakeXML( mxml_node_t *const parent ) const;
00442
00444 virtual std::string GetParamTypeString() const;
00445
00447 virtual std::ostringstream& PrintHelp( std::ostringstream& fmt
00448 ) const;
00449
00451 virtual void PrintWiki() const;
00452
00453 protected:
00455 T* Var;
00456
00458 bool* Flag;
00459 };
00460
00462 template<class T>
00463 class List :
00465 public Item
00466 {
00467 public:
00469 List( std::list<T>& list ) : m_pList( &list ) {}
00470
00472 virtual ~List() {}
00473
00475 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index );
00476
00478 virtual mxml_node_t* MakeXML( mxml_node_t *const parent ) const;
00479
00480 private:
00482 std::list<T>* m_pList;
00483 };
00484
00491 template<class T>
00492 class Vector :
00494 public Item
00495 {
00496 public:
00498 Vector( std::vector<T>& vector ) : m_pVector( &vector ), m_HasBeenUsed( false ) {}
00499
00501 virtual ~Vector() {}
00502
00504 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index );
00505
00507 virtual mxml_node_t* MakeXML( mxml_node_t *const parent ) const;
00508
00510 virtual std::string GetParamTypeString() const;
00511
00512 private:
00514 std::vector<T>* m_pVector;
00515
00517 bool m_HasBeenUsed;
00518 };
00519
00521 class Callback :
00523 public Item
00524 {
00525 public:
00527 Callback( CallbackFunc func ) : m_Func( func ), m_FuncArg( NULL ), m_FuncIntArg( NULL ), m_FuncDblArg( NULL ), m_FuncMultiArg( NULL ) {}
00528
00530 Callback( CallbackFuncArg funcArg ) : m_Func( NULL ), m_FuncArg( funcArg ), m_FuncIntArg( NULL ), m_FuncDblArg( NULL ), m_FuncMultiArg( NULL ) {}
00531
00533 Callback( CallbackFuncIntArg funcIntArg ) : m_Func( NULL ), m_FuncArg( NULL ), m_FuncIntArg( funcIntArg ), m_FuncDblArg( NULL ), m_FuncMultiArg( NULL ) {}
00534
00536 Callback( CallbackFuncDblArg funcDblArg ) : m_Func( NULL ), m_FuncArg( NULL ), m_FuncIntArg( NULL ), m_FuncDblArg( funcDblArg ), m_FuncMultiArg( NULL ) {}
00537
00539 Callback( CallbackFuncMultiArg funcMultiArg ) : m_Func( NULL ), m_FuncArg( NULL ), m_FuncIntArg( NULL ), m_FuncDblArg( NULL ), m_FuncMultiArg( funcMultiArg ) {}
00540
00542 virtual ~Callback() {}
00543
00545 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index );
00546
00548 virtual mxml_node_t* MakeXML( mxml_node_t *const parent ) const;
00549
00551 virtual std::string GetParamTypeString() const;
00552
00553 private:
00555 CallbackFunc m_Func;
00556
00558 CallbackFuncArg m_FuncArg;
00559
00561 CallbackFuncIntArg m_FuncIntArg;
00562
00564 CallbackFuncDblArg m_FuncDblArg;
00565
00567 CallbackFuncMultiArg m_FuncMultiArg;
00568 };
00569
00571 class NonOptionParameter :
00573 public Option<const char*>
00574 {
00575 public:
00577 typedef NonOptionParameter Self;
00578
00580 typedef SmartPointer<Self> SmartPtr;
00581
00583 typedef Option<const char*> Superclass;
00584
00586 NonOptionParameter( const char* *const var, const char* name, const char* comment, bool *const flag ) : Superclass( var, flag ), m_Name( name ), m_Comment( comment ) {};
00587
00589 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index );
00590
00592 virtual mxml_node_t* MakeXMLWithIndex( mxml_node_t *const parent,
00593 const int index
00594 ) const;
00595
00597 virtual std::string GetParamTypeString() const;
00598
00600 virtual std::ostringstream& PrintHelp( std::ostringstream& fmt
00601 ) const
00602 {
00603
00604 if ( this->Var )
00605 fmt << "\n[Default: " << *(this->Var) << "]";
00606 else
00607 fmt << "\n[There is no default for this parameter]";
00608 return fmt;
00609 }
00610
00612 virtual void PrintWiki() const
00613 {
00614
00615 if ( this->Var )
00616 StdOut << " '''[Default: " << *(this->Var) << "]'''\n";
00617 else
00618 StdOut << " '''[There is no default for this parameter]'''\n";
00619 }
00620
00622 const char* m_Name;
00623
00625 const char* m_Comment;
00626 };
00627
00629 class NonOptionParameterVector :
00631 public Option< std::vector<std::string> >
00632 {
00633 public:
00635 typedef NonOptionParameterVector Self;
00636
00638 typedef SmartPointer<Self> SmartPtr;
00639
00641 typedef Option< std::vector<std::string> > Superclass;
00642
00644 NonOptionParameterVector( std::vector<std::string> *pvec, const char* name, const char* comment, bool *const flag )
00645 : Superclass( pvec, flag ),
00646 m_Name( name ),
00647 m_Comment( comment ) {};
00648
00650 virtual void Evaluate( const size_t argc, const char* argv[], size_t& index );
00651
00653 virtual mxml_node_t* MakeXMLWithIndex( mxml_node_t *const parent,
00654 const int index
00655 ) const;
00656
00658 virtual std::string GetParamTypeString() const;
00659
00661 virtual std::ostringstream& PrintHelp( std::ostringstream& fmt
00662 ) const
00663 {
00664 if ( this->Var->size() )
00665 {
00666 fmt << "\n[Default: ( \"" << (*this->Var)[0] << "\"";
00667 for ( size_t i = 1; i < this->Var->size(); ++i )
00668 fmt << ", \"" << (*this->Var)[i] << "\" ";
00669 fmt << ") ]";
00670 }
00671 else
00672 {
00673 fmt << "\n[Default: (empty)]";
00674 }
00675 return fmt;
00676 }
00677
00679 virtual void PrintWiki() const
00680 {
00681 if ( this->Var->size() )
00682 {
00683 StdOut << "'''[Default: ( \"" << (*this->Var)[0] << "\"";
00684 for ( size_t i = 1; i < this->Var->size(); ++i )
00685 StdOut << ", \"" << (*this->Var)[i] << "\" ";
00686 StdOut << ") ]'''\n";
00687 }
00688 else
00689 {
00690 StdOut << "'''[Default: (empty)]'''\n";
00691 }
00692 }
00693
00695 const char* m_Name;
00696
00698 const char* m_Comment;
00699 };
00700
00701 public:
00703 CommandLine( const int properties = PROPS_NOXML );
00704
00706 ~CommandLine();
00707
00709 class EnumGroupBase;
00710
00712 class KeyToAction
00713 {
00714 public:
00716 typedef SmartPointer<KeyToAction> SmartPtr;
00717
00719 const Key m_Key;
00720
00722 KeyToAction( const Key& key,
00723 const std::string& comment ) :
00724 m_Key( key ),
00725 m_Comment( comment ),
00726 m_Properties( PROPS_XML )
00727 {}
00728
00730 virtual ~KeyToAction() {};
00731
00733 virtual bool MatchAndExecute( const std::string& key,
00734 const size_t argc,
00735 const char* argv[],
00736 size_t& index
00737 ) = 0;
00738
00740 virtual bool MatchAndExecute( const char keyChar,
00741 const size_t argc,
00742 const char* argv[],
00743 size_t& index
00744 ) = 0;
00745
00747 virtual void SetProperties( const long int properties );
00748
00750 virtual long int GetProperties() const;
00751
00753 virtual mxml_node_t* MakeXML( mxml_node_t *const parent
00754 ) const;
00755
00757 virtual void PrintHelp( const size_t globalIndent = 0 ) const = 0;
00758
00759 protected:
00761 virtual void FormatHelp( std::ostringstream& fmt ) const;
00762
00764 virtual void PrintWikiWithPrefix( const std::string& prefix = "" ) const;
00765
00767 virtual std::string GetActionTypeInfo() const
00768 {
00769 return "";
00770 }
00771
00773 std::string m_Comment;
00774
00776 long int m_Properties;
00777
00784 virtual bool MatchLongOption( const std::string& key ) const;
00785
00787 friend class CommandLine;
00788
00790 friend class CommandLine::EnumGroupBase;
00791 };
00792
00794 class KeyToActionSingle :
00796 public KeyToAction
00797 {
00798 public:
00800 typedef KeyToAction Superclass;
00801
00803 typedef SmartPointer<KeyToActionSingle> SmartPtr;
00804
00806 KeyToActionSingle( const Key& key,
00807 Item::SmartPtr action,
00808 const std::string& comment ) :
00809 KeyToAction( key, comment ),
00810 m_Action( action )
00811 {}
00812
00814 virtual ~KeyToActionSingle() {};
00815
00817 bool MatchAndExecute( const std::string& key,
00818 const size_t argc,
00819 const char* argv[],
00820 size_t& index
00821 );
00822
00824 bool MatchAndExecute( const char keyChar,
00825 const size_t argc,
00826 const char* argv[],
00827 size_t& index
00828 );
00829
00831 virtual mxml_node_t* MakeXML( mxml_node_t *const parent
00832 ) const;
00833
00835 virtual void PrintHelp( const size_t globalIndent = 0 ) const;
00836
00838 virtual void PrintWikiWithPrefix( const std::string& prefix = "" ) const;
00839
00841 virtual std::string GetActionTypeInfo() const
00842 {
00843 return this->m_Action->GetParamTypeString();
00844 }
00845
00847 Item::SmartPtr m_Action;
00848 };
00849
00851 class EnumGroupBase :
00853 public std::list< SmartPointer<KeyToActionSingle> >
00854 {
00855 public:
00857 typedef SmartPointer<EnumGroupBase> SmartPtr;
00858
00860 std::string GetDefaultKey() const
00861 {
00862 for ( const_iterator it = this->begin(); it != this->end(); ++it )
00863 {
00864 if ( (*it)->m_Action->IsDefault() )
00865 {
00866 return std::string( (*it)->m_Key.m_KeyString );
00867 }
00868 }
00869 return "";
00870 }
00871 };
00872
00874 class KeyToActionEnum :
00876 public KeyToAction
00877 {
00878 public:
00880 typedef KeyToAction Superclass;
00881
00883 typedef SmartPointer<KeyToActionEnum> SmartPtr;
00884
00891 KeyToActionEnum( const Key& key ,
00892 EnumGroupBase::SmartPtr keyToActionEnum ,
00893 const std::string& comment ) :
00894 KeyToAction( key, comment ),
00895 m_EnumGroup( keyToActionEnum )
00896 {}
00897
00899 virtual ~KeyToActionEnum() {};
00900
00902 bool MatchAndExecute( const std::string& key,
00903 const size_t argc,
00904 const char* argv[],
00905 size_t& index
00906 );
00907
00909 bool MatchAndExecute( const char keyChar,
00910 const size_t argc,
00911 const char* argv[],
00912 size_t& index
00913 );
00914
00916 virtual mxml_node_t* MakeXML( mxml_node_t *const parent
00917 ) const;
00918
00920 virtual void PrintHelp( const size_t globalIndent = 0 ) const;
00921
00923 virtual void PrintWikiWithPrefix( const std::string& prefix = "" ) const;
00924
00925 private:
00927 EnumGroupBase::SmartPtr m_EnumGroup;
00928
00930 friend class EnumGroupBase;
00931 };
00932
00934 template<class TDataType>
00935 class EnumGroup :
00937 public EnumGroupBase
00938 {
00939 public:
00941 typedef SmartPointer< EnumGroup<TDataType> > SmartPtr;
00942
00944 EnumGroup( TDataType *const variable
00945 ) :
00946 m_Variable( variable )
00947 {
00948 }
00949
00951 Item::SmartPtr&
00952 AddSwitch( const Key& key, const TDataType& value, const std::string& comment )
00953 {
00954 KeyToActionSingle::SmartPtr keyToAction( new KeyToActionSingle( key, Item::SmartPtr( new Switch<TDataType>( this->m_Variable, value ) ), comment ) );
00955 this->push_back( keyToAction );
00956 return keyToAction->m_Action;
00957 }
00958
00959 private:
00961 TDataType *m_Variable;
00962 };
00963
00965 template<class TDataType>
00966 typename EnumGroup<TDataType>::SmartPtr AddEnum( const std::string& name, TDataType *const variable, const std::string& comment )
00967 {
00968 typename EnumGroup<TDataType>::SmartPtr enumGroup( new EnumGroup<TDataType>( variable ) );
00969 KeyToActionEnum::SmartPtr keyToAction( new KeyToActionEnum( Key( name ), enumGroup, comment ) );
00970
00971 this->m_KeyActionList->push_back( keyToAction );
00972 this->m_KeyActionListComplete.push_back( keyToAction );
00973
00974 return enumGroup;
00975 }
00976
00978 template<class T>
00979 Item::SmartPtr
00980 AddSwitch( const Key& key, T *const var, const T value, const char* comment )
00981 {
00982 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new Switch<T>( var, value ) ), comment ) ) )->m_Action;
00983 }
00984
00986 template<class T>
00987 Item::SmartPtr
00988 AddOption( const Key& key, T *const var, const char* comment, bool *const flag = NULL )
00989 {
00990 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new Option<T>( var, flag ) ), comment ) ) )->m_Action;
00991 }
00992
00994 template<class T>
00995 Item::SmartPtr
00996 AddList( const Key& key, std::list<T>& list, const char* comment )
00997 {
00998 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new List<T>( list ) ), comment ) ) )->m_Action;
00999 }
01000
01002 template<class T>
01003 Item::SmartPtr
01004 AddVector( const Key& key, std::vector<T>& vector, const char* comment )
01005 {
01006 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new Vector<T>( vector ) ), comment ) ) )->m_Action;
01007 }
01008
01010 Item::SmartPtr
01011 AddCallback( const Key& key, CallbackFunc func, const char* comment )
01012 {
01013 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new Callback( func ) ), comment ) ) )->m_Action;
01014 }
01015
01017 template<class TArg>
01018 Item::SmartPtr
01019 AddCallback( const Key& key, void (*funcArg)( const TArg ), const char* comment )
01020 {
01021 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new Callback( funcArg ) ), comment ) ) )->m_Action;
01022 }
01023
01025 Item::SmartPtr
01026 AddCallback( const Key& key, CallbackFuncMultiArg funcMultiArg, const char* comment )
01027 {
01028 return this->AddKeyAction( KeyToActionSingle::SmartPtr( new KeyToActionSingle( key, Item::SmartPtr( new Callback( funcMultiArg ) ), comment ) ) )->m_Action;
01029 }
01030
01032 Item::SmartPtr
01033 AddParameter( const char* *const var, const char* name, const char* comment, bool *const flag = NULL )
01034 {
01035 NonOptionParameter::SmartPtr parameter( new NonOptionParameter( var, name, comment, flag ) );
01036 this->m_NonOptionParameterList.push_back( parameter );
01037 return parameter;
01038 }
01039
01041 Item::SmartPtr
01042 AddParameterVector( std::vector<std::string>* pvec, const char* name, const char* comment, bool *const flag = NULL )
01043 {
01044 NonOptionParameterVector::SmartPtr vparameter( new NonOptionParameterVector( pvec, name, comment, flag ) );
01045 this->m_NonOptionParameterVectorList.push_back( vparameter );
01046 return vparameter;
01047 }
01048
01050 typedef std::vector<KeyToAction::SmartPtr> KeyActionListType;
01051
01053 KeyActionListType* m_KeyActionList;
01054
01056 KeyActionListType m_KeyActionListComplete;
01057
01059 KeyToActionSingle::SmartPtr AddKeyAction( const KeyToActionSingle::SmartPtr& keyAction )
01060 {
01061 this->m_KeyActionList->push_back( keyAction );
01062 this->m_KeyActionListComplete.push_back( keyAction );
01063 return keyAction;
01064 }
01065
01067 KeyToActionEnum::SmartPtr AddKeyAction( const KeyToActionEnum::SmartPtr& keyAction )
01068 {
01069 this->m_KeyActionList->push_back( keyAction );
01070 this->m_KeyActionListComplete.push_back( keyAction );
01071 return keyAction;
01072 }
01073
01075 class KeyActionGroupType
01076 {
01077 public:
01079 typedef SmartPointer<KeyActionGroupType> SmartPtr;
01080
01082 KeyActionGroupType( const std::string& name, const std::string& description ) : m_Name( name ), m_Description( description ) {};
01083
01085 std::string m_Name;
01086
01088 std::string m_Description;
01089
01091 KeyActionListType m_KeyActionList;
01092
01094 virtual void SetProperties( const long int properties )
01095 {
01096 this->m_Properties = properties;
01097 }
01098
01100 virtual long int GetProperties() const
01101 {
01102 return this->m_Properties;
01103 }
01104
01105 private:
01107 long int m_Properties;
01108 };
01109
01111 KeyActionGroupType::SmartPtr& BeginGroup( const char* name, const char* description );
01112
01114 void EndGroup();
01115
01117 bool Parse( const int argc, const char* argv[] ) throw( ExitException, Self::Exception );
01118
01120 static const int HelpTextIndent = 10;
01121
01123 void PrintHelp() const;
01124
01126 void PrintWiki() const;
01127
01129 size_t GetNextIndex() const { return this->Index; }
01130
01134 const char* GetNext()
01135 {
01136 if ( Index >= ArgC )
01137 throw( Exception( "Out of arguments.", Index ) );
01138 return ArgV[Index++];
01139 }
01140
01144 const char* GetNextOptional()
01145 {
01146 if ( Index >= ArgC ) return NULL;
01147 return ArgV[Index++];
01148 }
01149
01153 void WriteXML() const;
01154
01155 private:
01157 size_t ArgC;
01158
01160 const char** ArgV;
01161
01163 long int m_Properties;
01164
01166 size_t Index;
01167
01169 typedef std::vector<KeyActionGroupType::SmartPtr> KeyActionGroupListType;
01170
01172 KeyActionGroupListType m_KeyActionGroupList;
01173
01175 typedef std::vector<NonOptionParameter::SmartPtr> NonOptionParameterListType;
01176
01178 NonOptionParameterListType m_NonOptionParameterList;
01179
01181 typedef std::vector<NonOptionParameterVector::SmartPtr> NonOptionParameterVectorListType;
01182
01184 NonOptionParameterVectorListType m_NonOptionParameterVectorList;
01185
01187 typedef std::map<ProgramProperties,std::string> ProgramPropertiesMapType;
01188
01190 ProgramPropertiesMapType m_ProgramInfo;
01191
01193 mxml_node_t* AddProgramInfoXML( mxml_node_t *const parent ,
01194 const ProgramProperties key ,
01195 const char* name ) const;
01196
01198 void SetDefaultInfo();
01199
01201 template<class T> friend class Option;
01202
01204 template<class T> friend class Switch;
01205
01207 friend class Callback;
01208 };
01209
01211 Console& operator<<( Console& console, CommandLine::Exception e );
01212
01214
01215 }
01216
01217 #include "cmtkCommandLineItem.txx"
01218 #include "cmtkCommandLineOption.txx"
01219 #include "cmtkCommandLineConvert.txx"
01220 #include "cmtkCommandLineList.txx"
01221 #include "cmtkCommandLineVector.txx"
01222
01223 #endif // #ifndef __cmtkCommandLine_h_included_