Go to the documentation of this file.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 #include "cmtkCommandLine.h"
00033
00034 void
00035 cmtk::CommandLine::KeyToActionEnum
00036 ::PrintHelp( const size_t globalIndent ) const
00037 {
00038 std::ostringstream fmt;
00039 this->Superclass::FormatHelp( fmt );
00040
00041 fmt << "\nSupported values: ";
00042 for ( EnumGroupBase::const_iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00043 {
00044 fmt << "\"" << (*it)->m_Key.m_KeyString << "\", ";
00045 }
00046
00047 const std::string defaultKey = this->m_EnumGroup->GetDefaultKey();
00048 if ( defaultKey.length() )
00049 {
00050 fmt << "where the default is \"" << defaultKey << "\", ";
00051 }
00052
00053 fmt << "or use one of the following";
00054
00055 StdErr.FormatText( fmt.str(), CommandLine::HelpTextIndent + globalIndent, StdErr.GetLineWidth(), -CommandLine::HelpTextIndent ) << "\n";
00056
00057 for ( EnumGroupBase::const_iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00058 {
00059 (*it)->PrintHelp( globalIndent + 10 );
00060 }
00061 }
00062
00063 void
00064 cmtk::CommandLine::KeyToActionEnum
00065 ::PrintWikiWithPrefix( const std::string& prefix ) const
00066 {
00067 this->Superclass::PrintWikiWithPrefix( prefix );
00068
00069 StdOut << "Supported values: ";
00070 for ( EnumGroupBase::const_iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00071 {
00072 StdOut << "\"<tt>" << (*it)->m_Key.m_KeyString << "</tt>\", ";
00073 }
00074
00075 const std::string defaultKey = this->m_EnumGroup->GetDefaultKey();
00076 if ( defaultKey.length() )
00077 {
00078 StdOut << "where the default is \"" << defaultKey << "\", ";
00079 }
00080
00081 StdOut << "or use one of the following\n";
00082
00083 for ( EnumGroupBase::const_iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00084 {
00085 (*it)->PrintWikiWithPrefix( ":" );
00086 }
00087 }
00088
00089 mxml_node_t*
00090 cmtk::CommandLine::KeyToActionEnum
00091 ::MakeXML( mxml_node_t *const parent ) const
00092 {
00093 if ( ! (this->m_Properties & PROPS_NOXML) )
00094 {
00095 mxml_node_t *node = mxmlNewElement( parent, "string-enumeration" );
00096
00097 mxml_node_t* defaultElement = mxmlNewElement( node, "default" );
00098 mxmlNewText( defaultElement, 0, this->m_EnumGroup->GetDefaultKey().c_str() );
00099
00100 for ( EnumGroupBase::const_iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00101 {
00102 mxml_node_t* element = mxmlNewElement( node, "element" );
00103 mxmlNewText( element, 0, (*it)->m_Key.m_KeyString.c_str() );
00104 }
00105
00106 return this->Superclass::MakeXML( node );
00107 }
00108 return NULL;
00109 }
00110
00111 bool
00112 cmtk::CommandLine::KeyToActionEnum
00113 ::MatchAndExecute( const std::string& key, const size_t argc, const char* argv[], size_t& index )
00114 {
00115 if ( this->MatchLongOption( std::string( key ) ) )
00116 {
00117
00118 if ( this->m_EnumGroup )
00119 {
00120 for ( EnumGroupBase::iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00121 {
00122 size_t ii = index+1;
00123 if ( (*it)->MatchAndExecute( argv[ii], argc, argv, ii ) )
00124 {
00125 index = ii;
00126 return true;
00127 }
00128 }
00129 }
00130 }
00131
00132
00133 if ( this->m_EnumGroup )
00134 {
00135 for ( EnumGroupBase::iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00136 {
00137 if ( (*it)->MatchAndExecute( key, argc, argv, index ) )
00138 {
00139 return true;
00140 }
00141 }
00142 }
00143
00144 return false;
00145 }
00146
00147 bool
00148 cmtk::CommandLine::KeyToActionEnum
00149 ::MatchAndExecute( const char keyChar, const size_t argc, const char* argv[], size_t& index )
00150 {
00151
00152 for ( EnumGroupBase::iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00153 {
00154 size_t ii = index+1;
00155 if ( (*it)->MatchAndExecute( argv[ii], argc, argv, ii ) )
00156 {
00157 index = ii;
00158 return true;
00159 }
00160 }
00161
00162
00163 for ( EnumGroupBase::iterator it = this->m_EnumGroup->begin(); it != this->m_EnumGroup->end(); ++it )
00164 {
00165 if ( (*it)->MatchAndExecute( keyChar, argc, argv, index ) )
00166 {
00167 return true;
00168 }
00169 }
00170
00171 return false;
00172 }