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 #include <cmtkconfig.h>
00032
00033 #include "cmtkCommandLine.h"
00034
00035 #include <mxml.h>
00036
00037 #include <stdio.h>
00038
00039 namespace
00040 cmtk
00041 {
00042
00045
00046 mxml_node_t*
00047 CommandLine::AddProgramInfoXML( mxml_node_t *const parent, const ProgramProperties key, const char* name ) const
00048 {
00049 ProgramPropertiesMapType::const_iterator it = this->m_ProgramInfo.find( key );
00050 if ( it != this->m_ProgramInfo.end() )
00051 {
00052 mxml_node_t *node = mxmlNewElement( parent, name );
00053 mxmlNewText( node, 0, it->second.c_str() );
00054 return node;
00055 }
00056 return NULL;
00057 }
00058
00059 const char *
00060 cmtkWhitespaceWriteMiniXML( mxml_node_t*, int where)
00061 {
00062 switch ( where )
00063 {
00064 case MXML_WS_BEFORE_OPEN:
00065 return NULL;
00066 case MXML_WS_AFTER_OPEN:
00067 return "\n";
00068 case MXML_WS_BEFORE_CLOSE:
00069 return "\n";
00070 case MXML_WS_AFTER_CLOSE:
00071 return "\n";
00072 }
00073 return NULL;
00074 }
00075
00076 void
00077 CommandLine::WriteXML
00078 () const
00079 {
00080
00081 if ( ! (this->m_Properties & PROPS_NOXML) )
00082 {
00083 mxml_node_t *xml = mxmlNewXML("1.0");
00084
00085 mxml_node_t *x_exec = mxmlNewElement(xml, "executable");
00086
00087 this->AddProgramInfoXML( x_exec, PRG_CATEG, "category" );
00088 this->AddProgramInfoXML( x_exec, PRG_TITLE, "title" );
00089 this->AddProgramInfoXML( x_exec, PRG_DESCR, "description" );
00090 this->AddProgramInfoXML( x_exec, PRG_LCNSE, "license" );
00091 this->AddProgramInfoXML( x_exec, PRG_CNTRB, "contributor" );
00092 this->AddProgramInfoXML( x_exec, PRG_ACKNL, "acknowledgements" );
00093 this->AddProgramInfoXML( x_exec, PRG_DOCUM, "documentation-url" );
00094 this->AddProgramInfoXML( x_exec, PRG_VERSN, "version" );
00095
00096 for ( KeyActionGroupListType::const_iterator grp = this->m_KeyActionGroupList.begin(); grp != this->m_KeyActionGroupList.end(); ++grp )
00097 {
00098 if ( ! ((*grp)->GetProperties() & PROPS_NOXML) )
00099 {
00100 mxml_node_t *parameterGroup = mxmlNewElement( x_exec, "parameters" );
00101
00102 if ( (*grp)->GetProperties() & PROPS_ADVANCED )
00103 mxmlElementSetAttr( parameterGroup, "advanced", "true" );
00104
00105 const std::string& name = (*grp)->m_Name;
00106 if ( name == "MAIN" )
00107 {
00108 mxmlNewText( mxmlNewElement( parameterGroup, "label" ), 0, "General" );
00109 mxmlNewText( mxmlNewElement( parameterGroup, "description" ), 0, "General Parameters" );
00110
00111 int index = 0;
00112 for ( NonOptionParameterListType::const_iterator it = this->m_NonOptionParameterList.begin(); it != this->m_NonOptionParameterList.end(); ++it )
00113 {
00114 (*it)->MakeXMLWithIndex( parameterGroup, index++ );
00115 }
00116 }
00117 else
00118 {
00119 mxmlNewText( mxmlNewElement( parameterGroup, "label" ), 0, name.c_str() );
00120 mxmlNewText( mxmlNewElement( parameterGroup, "description" ), 0, (*grp)->m_Description.c_str() );
00121 }
00122
00123 const KeyActionListType& kal = (*grp)->m_KeyActionList;
00124 for ( KeyActionListType::const_iterator it = kal.begin(); it != kal.end(); ++it )
00125 {
00126 (*it)->MakeXML( parameterGroup );
00127 }
00128 }
00129 }
00130
00131 mxmlSaveFile( xml, stdout, cmtkWhitespaceWriteMiniXML );
00132 fputs( "\n", stdout );
00133
00134 mxmlDelete( xml );
00135 }
00136 }
00137
00138 }