cmtkCommandLineItem.txx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 2009 SRI International
00004 //
00005 //  This file is part of the Computational Morphometry Toolkit.
00006 //
00007 //  http://www.nitrc.org/projects/cmtk/
00008 //
00009 //  The Computational Morphometry Toolkit is free software: you can
00010 //  redistribute it and/or modify it under the terms of the GNU General Public
00011 //  License as published by the Free Software Foundation, either version 3 of
00012 //  the License, or (at your option) any later version.
00013 //
00014 //  The Computational Morphometry Toolkit is distributed in the hope that it
00015 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00016 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 //  GNU General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU General Public License along
00020 //  with the Computational Morphometry Toolkit.  If not, see
00021 //  <http://www.gnu.org/licenses/>.
00022 //
00023 //  $Revision: 778 $
00024 //
00025 //  $LastChangedDate: 2009-11-16 14:20:25 -0800 (Mon, 16 Nov 2009) $
00026 //
00027 //  $LastChangedBy: torstenrohlfing $
00028 //
00029 */
00030 
00031 #include <typeinfo>
00032 
00033 template<class T>
00034 mxml_node_t* 
00035 cmtk::CommandLine::Item::Helper<T>
00036 ::MakeXML( const Item* item, mxml_node_t *const parent )
00037 {
00038   if ( ! (item->m_Properties & PROPS_NOXML) )
00039     {
00040     const char* typeName = CommandLineTypeTraits<T>::GetName();
00041     
00042     mxml_node_t *node = NULL;
00043     if ( std::string( typeName ) == "string" )
00044       {
00045       if ( item->m_Properties & PROPS_IMAGE )
00046         {
00047         node = mxmlNewElement( parent, "image" );
00048         
00049         if ( item->m_Properties & PROPS_LABELS )
00050           mxmlElementSetAttr( node, "type", "label" );
00051         else
00052           mxmlElementSetAttr( node, "type", "scalar" );
00053         }
00054       else if ( item->m_Properties & PROPS_XFORM )
00055         {
00056         node = mxmlNewElement( parent, "transform" );
00057         mxmlElementSetAttr( node, "fileExtensions", ".txt" );
00058         }
00059       else if ( item->m_Properties & PROPS_FILENAME )
00060         node = mxmlNewElement( parent, "file" );
00061       else if ( item->m_Properties & PROPS_DIRNAME )
00062         node = mxmlNewElement( parent, "directory" );
00063       else 
00064         node = mxmlNewElement( parent, "string" );
00065       
00066       if ( item->m_Properties & PROPS_OUTPUT )
00067         mxmlNewText( mxmlNewElement( node, "channel" ), 0, "output" );
00068       else
00069         mxmlNewText( mxmlNewElement( node, "channel" ), 0, "input" );
00070       }
00071     else
00072       node = mxmlNewElement( parent, typeName );
00073     
00074     // write any attributes the user might have set
00075     for ( std::map<std::string,std::string>::const_iterator attrIt = item->m_Attributes.begin(); attrIt != item->m_Attributes.end(); ++attrIt )
00076       {
00077       mxmlElementSetAttr( node, attrIt->first.c_str(), attrIt->second.c_str() );
00078       }
00079     
00080     return node;
00081     }
00082   return NULL;
00083 }
00084 
00085 template<class T>
00086 std::string
00087 cmtk::CommandLine::Item::Helper<T>
00088 ::GetParamTypeString( const Item* item )
00089 {
00090   const std::string& typeName = CommandLineTypeTraits<T>::GetName();
00091     
00092   if ( typeName == "string" )
00093     {
00094     if ( item->m_Properties & PROPS_IMAGE )
00095       {
00096       if ( item->m_Properties & PROPS_LABELS )
00097         return "<labelmap-path>";
00098       else
00099         return "<image-path>";
00100       }
00101     else if ( item->m_Properties & PROPS_XFORM )
00102       {
00103       return "<transformation-path>";
00104       }
00105     else if ( item->m_Properties & PROPS_FILENAME )
00106       return "<path>";
00107     else if ( item->m_Properties & PROPS_DIRNAME )
00108       return "<directory>";
00109     else 
00110       return "<string>";
00111     }
00112 
00113   return std::string("<")+typeName+std::string(">");
00114 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines