UnlabeledValueArg.h

Go to the documentation of this file.
00001 
00002 /****************************************************************************** 
00003  * 
00004  *  file:  UnlabeledValueArg.h
00005  * 
00006  *  Copyright (c) 2003, Michael E. Smoot .
00007  *  Copyright (c) 2004, Michael E. Smoot, Daniel Aarno.
00008  *  All rights reverved.
00009  * 
00010  *  See the file COPYING in the top directory of this distribution for
00011  *  more information.
00012  *  
00013  *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 
00014  *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
00015  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
00016  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
00017  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
00018  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
00019  *  DEALINGS IN THE SOFTWARE.  
00020  *  
00021  *****************************************************************************/ 
00022 
00023 
00024 #ifndef TCLAP_UNLABELED_VALUE_ARGUMENT_H
00025 #define TCLAP_UNLABELED_VALUE_ARGUMENT_H
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 #include <tclap/ValueArg.h>
00031 
00032 namespace TCLAP {
00033 
00040 template<class T>
00041 class UnlabeledValueArg : public ValueArg<T>
00042 {
00043 
00044 #ifdef TWO_STAGE_NAME_LOOKUP
00045      //If compiler has two stage name lookup (as gcc >= 3.4 does)
00046      //this is requried to prevent undef. symbols
00047      using ValueArg<T>::_ignoreable;
00048      using ValueArg<T>::_hasBlanks;
00049      using ValueArg<T>::_extractValue;
00050      using ValueArg<T>::_typeDesc;
00051      using ValueArg<T>::_name;
00052      using ValueArg<T>::_description;
00053      using ValueArg<T>::_alreadySet;
00054 #endif
00055 
00056      public:
00057 
00081           UnlabeledValueArg( const std::string& name, 
00082                               const std::string& desc, 
00083                                T value,
00084                                const std::string& typeDesc,
00085                                  bool ignoreable = false,
00086                                Visitor* v = NULL); 
00087 
00112           UnlabeledValueArg( const std::string& name, 
00113                               const std::string& desc, 
00114                                T value,
00115                                const std::string& typeDesc,
00116                                  CmdLineInterface& parser,
00117                                  bool ignoreable = false,
00118                                Visitor* v = NULL );                        
00119                               
00141           UnlabeledValueArg( const std::string& name, 
00142                               const std::string& desc, 
00143                                T value,
00144                                const std::vector<T>& allowed,
00145                                  bool ignoreable = false,
00146                                Visitor* v = NULL ); 
00147 
00148           
00171           UnlabeledValueArg( const std::string& name, 
00172                               const std::string& desc, 
00173                                T value,
00174                                const std::vector<T>& allowed,
00175                                  CmdLineInterface& parser,
00176                                  bool ignoreable = false,
00177                                Visitor* v = NULL);
00178                               
00187           virtual bool processArg(int* i, std::vector<std::string>& args); 
00188 
00192           virtual std::string shortID(const std::string& val="val") const;
00193 
00197           virtual std::string longID(const std::string& val="val") const;
00198 
00202           virtual bool operator==(const Arg& a ) const;
00203 
00208           virtual void addToList( std::list<Arg*>& argList ) const;
00209 };
00210 
00214 template<class T>
00215 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 
00216                                              const std::string& desc, 
00217                                              T val,
00218                                              const std::string& typeDesc,
00219                                              bool ignoreable,
00220                                              Visitor* v)
00221 : ValueArg<T>("", name, desc, true, val, typeDesc, v)
00222 { 
00223      _ignoreable = ignoreable;
00224 }
00225 
00226 template<class T>
00227 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 
00228                                              const std::string& desc, 
00229                                              T val,
00230                                              const std::string& typeDesc,
00231                                              CmdLineInterface& parser,
00232                                              bool ignoreable,
00233                                              Visitor* v)
00234 : ValueArg<T>("", name, desc, true, val, typeDesc, v)
00235 { 
00236      _ignoreable = ignoreable;
00237      parser.add( this );
00238 }
00239 
00243 template<class T>
00244 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 
00245                            const std::string& desc, 
00246                            T val,
00247                            const std::vector<T>& allowed,
00248                            bool ignoreable,
00249                            Visitor* v)
00250 : ValueArg<T>("", name, desc, true, val, allowed, v)
00251 { 
00252      _ignoreable = ignoreable;
00253 }
00254 
00255 template<class T>
00256 UnlabeledValueArg<T>::UnlabeledValueArg(const std::string& name, 
00257                                              const std::string& desc, 
00258                                              T val,
00259                                              const std::vector<T>& allowed,
00260                                              CmdLineInterface& parser,
00261                                              bool ignoreable,
00262                                              Visitor* v)
00263 : ValueArg<T>("", name, desc, true, val, allowed,  v)
00264 { 
00265      _ignoreable = ignoreable;
00266      parser.add( this );
00267 }
00268 
00272 template<class T>
00273 bool UnlabeledValueArg<T>::processArg(int *i, std::vector<std::string>& args) 
00274 {
00275      
00276      if ( _alreadySet )
00277           return false;
00278      
00279      if ( _hasBlanks( args[*i] ) )
00280           return false;
00281 
00282      // never ignore an unlabeled arg
00283      
00284      _extractValue( args[*i] );
00285      _alreadySet = true;
00286      return true;
00287 }
00288 
00292 template<class T>
00293 std::string UnlabeledValueArg<T>::shortID(const std::string& val) const
00294 {
00295      std::string id = "<" + _typeDesc + ">";
00296 
00297      return id;
00298 }
00299 
00303 template<class T>
00304 std::string UnlabeledValueArg<T>::longID(const std::string& val) const
00305 {
00306      // Ideally we would like to be able to use RTTI to return the name
00307      // of the type required for this argument.  However, g++ at least, 
00308      // doesn't appear to return terribly useful "names" of the types.  
00309      std::string id = "<" + _typeDesc + ">";
00310 
00311      return id;     
00312 }
00313 
00317 template<class T>
00318 bool UnlabeledValueArg<T>::operator==(const Arg& a ) const
00319 {
00320      if ( _name == a.getName() || _description == a.getDescription() )
00321           return true;
00322      else
00323           return false;
00324 }
00325 
00326 template<class T>
00327 void UnlabeledValueArg<T>::addToList( std::list<Arg*>& argList ) const
00328 {
00329      argList.push_back( (Arg*)this );
00330 }
00331 
00332 }
00333 #endif

Generated on Sun Mar 11 15:33:24 2007 for MetalWarriors by  doxygen 1.4.7