cmtkCommandLineXML.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //  Copyright 2004-2009 SRI International
00005 //
00006 //  This file is part of the Computational Morphometry Toolkit.
00007 //
00008 //  http://www.nitrc.org/projects/cmtk/
00009 //
00010 //  The Computational Morphometry Toolkit is free software: you can
00011 //  redistribute it and/or modify it under the terms of the GNU General Public
00012 //  License as published by the Free Software Foundation, either version 3 of
00013 //  the License, or (at your option) any later version.
00014 //
00015 //  The Computational Morphometry Toolkit is distributed in the hope that it
00016 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00017 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 //  GNU General Public License for more details.
00019 //
00020 //  You should have received a copy of the GNU General Public License along
00021 //  with the Computational Morphometry Toolkit.  If not, see
00022 //  <http://www.gnu.org/licenses/>.
00023 //
00024 //  $Revision: 2152 $
00025 //
00026 //  $LastChangedDate: 2010-08-04 10:19:33 -0700 (Wed, 04 Aug 2010) $
00027 //
00028 //  $LastChangedBy: torstenrohlfing $
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   // check for globally disabled XML support (some tools should not be used as Slicer plugins, for example)
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 ); // Slicer's XML parser needs an extra \n after the last line
00133 
00134     mxmlDelete( xml );
00135     }
00136 }
00137 
00138 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines