cmtkCommandLineOption.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: 523 $
00024 //
00025 //  $LastChangedDate: 2009-08-27 16:30:35 -0700 (Thu, 27 Aug 2009) $
00026 //
00027 //  $LastChangedBy: torstenrohlfing $
00028 //
00029 */
00030 
00031 #include <typeinfo>
00032 
00033 template<class T>
00034 void
00035 cmtk::CommandLine::Option<T>
00036 ::Evaluate( const size_t argc, const char* argv[], size_t& index )
00037 {
00038   if ( this->Flag ) 
00039     *(this->Flag) = true;
00040   if ( index+1 < argc ) 
00041     {
00042     *(this->Var) = this->Convert<T>( argv[index+1] );
00043         ++index;
00044     } 
00045   else
00046     {
00047     throw( Exception( "Option needs an argument.", index ) );
00048     }
00049 }
00050 
00051 template<class T>
00052 mxml_node_t* 
00053 cmtk::CommandLine::Option<T>
00054 ::MakeXML(  mxml_node_t *const parent ) const 
00055 {
00056   if ( ! (this->m_Properties & PROPS_NOXML) )
00057     {
00058     if ( Flag ) // if there is a flag monitoring this option, then we need to create an additional boolean toggle
00059       {
00060       }
00061     
00062     mxml_node_t *node = Item::Helper<T>::MakeXML( this, parent );
00063     
00064     if ( !Flag ) // if there is no flag monitoring this option, then there must be a valid default value
00065       {
00066       mxml_node_t *dflt = mxmlNewElement( node, "default" );
00067       mxmlNewText( dflt, 0, CommandLineTypeTraits<T>::ValueToStringMinimal( this->Var ).c_str() );
00068       }
00069     return node;
00070     }
00071   return NULL;
00072 }
00073 
00074 template<class T>
00075 std::string
00076 cmtk::CommandLine::Option<T>
00077 ::GetParamTypeString() const
00078 {
00079   return Item::Helper<T>::GetParamTypeString( this );
00080 }
00081 
00082 template<class T>
00083 std::ostringstream& 
00084 cmtk::CommandLine::Option<T>
00085 ::PrintHelp( std::ostringstream& fmt ) const
00086 {
00087   if ( this->Flag && !(*this->Flag) )
00088     fmt << "\n[Default: disabled]";
00089   else
00090     fmt << "\n[Default value: " << CommandLineTypeTraits<T>::ValueToString( this->Var ) << "]";
00091   return fmt;
00092 }
00093 
00094 template<class T>
00095 void
00096 cmtk::CommandLine::Option<T>
00097 ::PrintWiki() const
00098 {
00099   if ( this->Flag && !(*this->Flag) )
00100     StdOut << " '''[Default: disabled]'''";
00101   else
00102     StdOut << " '''[Default value: " << CommandLineTypeTraits<T>::ValueToString( this->Var ) << "]'''";
00103 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines