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 #include <sstream>
00035
00036
00037 void
00038 cmtk::CommandLine::KeyToAction
00039 ::SetProperties( const long int properties )
00040 {
00041 this->m_Properties = properties;
00042 }
00043
00044 long int
00045 cmtk::CommandLine::KeyToAction
00046 ::GetProperties() const
00047 {
00048 return this->m_Properties;
00049 }
00050
00051 mxml_node_t*
00052 cmtk::CommandLine::KeyToAction
00053 ::MakeXML( mxml_node_t *const node ) const
00054 {
00055 if ( ! (this->m_Properties & PROPS_NOXML) )
00056 {
00057
00058 std::string xmlKeyStr = this->m_Key.m_KeyString;
00059 for ( size_t i = 0; i < xmlKeyStr.length(); ++i )
00060 {
00061 if ( xmlKeyStr[i] == '-' )
00062 xmlKeyStr[i] = '_';
00063 }
00064
00065 if ( this->m_Comment.length() )
00066 {
00067 mxmlNewText( mxmlNewElement( node, "description" ), 0, this->m_Comment.c_str() );
00068 }
00069
00070 if ( this->m_Key.m_KeyString.length() )
00071 {
00072 mxmlNewText( mxmlNewElement( node, "name" ), 0, xmlKeyStr.c_str() );
00073 mxmlNewText( mxmlNewElement( node, "label" ), 0, xmlKeyStr.c_str() );
00074 }
00075 if ( this->m_Key.m_KeyChar )
00076 {
00077 const char keyStr[] = { '-', this->m_Key.m_KeyChar, 0 };
00078 mxmlNewText( mxmlNewElement( node, "flag" ), 0, keyStr );
00079 }
00080 if ( this->m_Key.m_KeyString.length() )
00081 {
00082 mxmlNewText( mxmlNewElement( node, "longflag" ), 0, (std::string( "--" ) + xmlKeyStr).c_str() );
00083 }
00084
00085 return node;
00086 }
00087 return NULL;
00088 }
00089
00090 void
00091 cmtk::CommandLine::KeyToAction
00092 ::FormatHelp( std::ostringstream& fmt ) const
00093 {
00094 const std::string& typeInfo = this->GetActionTypeInfo();
00095 if ( this->m_Key.m_KeyString.size() )
00096 {
00097 fmt << "--" << this->m_Key.m_KeyString;
00098 if ( typeInfo.length() )
00099 {
00100 fmt << " " << typeInfo;
00101 }
00102 }
00103
00104 if ( this->m_Key.m_KeyChar && this->m_Key.m_KeyString.size() )
00105 {
00106 fmt << " / ";
00107 }
00108
00109 if ( this->m_Key.m_KeyChar )
00110 {
00111 fmt << "-" << this->m_Key.m_KeyChar;
00112 if ( typeInfo.length() )
00113 {
00114 fmt << " " << typeInfo;
00115 }
00116 }
00117
00118 if ( fmt.str().length() > static_cast<size_t>( CommandLine::HelpTextIndent-2 ) )
00119 fmt << "\n";
00120 else
00121 {
00122 while ( fmt.str().length() < static_cast<size_t>( CommandLine::HelpTextIndent ) )
00123 fmt << " ";
00124 }
00125
00126 if ( this->m_Comment.length() )
00127 {
00128 fmt << this->m_Comment;
00129 }
00130 }
00131
00132 void
00133 cmtk::CommandLine::KeyToAction
00134 ::PrintWikiWithPrefix( const std::string& prefix ) const
00135 {
00136 const std::string& typeInfo = this->GetActionTypeInfo();
00137
00138 StdOut << prefix << "; ";
00139 if ( this->m_Key.m_KeyString.size() )
00140 {
00141 StdOut << "<tt>--" << this->m_Key.m_KeyString << "</tt>";
00142 if ( typeInfo.length() )
00143 {
00144 StdOut << " <tt>" << typeInfo << "</tt>";
00145 }
00146 }
00147
00148 if ( this->m_Key.m_KeyChar && this->m_Key.m_KeyString.size() )
00149 {
00150 StdOut << " / ";
00151 }
00152
00153 if ( this->m_Key.m_KeyChar )
00154 {
00155 StdOut << "<tt>-" << this->m_Key.m_KeyChar << "</tt>";
00156 if ( typeInfo.length() )
00157 {
00158 StdOut << " <tt>" << typeInfo << "</tt>";
00159 }
00160 }
00161
00162 StdOut << " : ";
00163 if ( this->m_Comment.length() )
00164 {
00165 StdOut << this->m_Comment;
00166 }
00167 }
00168
00169 bool
00170 cmtk::CommandLine::KeyToAction
00171 ::MatchLongOption( const std::string& key ) const
00172 {
00173 if ( key.length() != this->m_Key.m_KeyString.length() )
00174 return false;
00175
00176 for ( size_t i = 0; i < key.length(); ++i )
00177 {
00178 if ( (key[i] == '-' || key[i] == '_') && (this->m_Key.m_KeyString[i] == '-' || this->m_Key.m_KeyString[i] == '_') )
00179 continue;
00180
00181 if ( key[i] != this->m_Key.m_KeyString[i] )
00182 return false;
00183 }
00184 return true;
00185 }
00186