UnlabeledMultiArg.h

Go to the documentation of this file.
00001 
00002 /****************************************************************************** 
00003  * 
00004  *  file:  UnlabeledMultiArg.h
00005  * 
00006  *  Copyright (c) 2003, Michael E. Smoot.
00007  *  All rights reverved.
00008  * 
00009  *  See the file COPYING in the top directory of this distribution for
00010  *  more information.
00011  *  
00012  *  THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS 
00013  *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
00014  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
00015  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
00016  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
00017  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
00018  *  DEALINGS IN THE SOFTWARE.  
00019  *  
00020  *****************************************************************************/ 
00021 
00022 
00023 #ifndef TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
00024 #define TCLAP_MULTIPLE_UNLABELED_ARGUMENT_H
00025 
00026 #include <string>
00027 #include <vector>
00028 
00029 #include <tclap/MultiArg.h>
00030 
00031 namespace TCLAP {
00032 
00038 template<class T>
00039 class UnlabeledMultiArg : public MultiArg<T>
00040 {
00041 
00042 #ifdef TWO_STAGE_NAME_LOOKUP
00043      //If compiler has two stage name lookup (as gcc >= 3.4 does)
00044      //this is requried to prevent undef. symbols
00045      using MultiArg<T>::_ignoreable;
00046      using MultiArg<T>::_hasBlanks;
00047      using MultiArg<T>::_extractValue;
00048      using MultiArg<T>::_typeDesc;
00049      using MultiArg<T>::_name;
00050      using MultiArg<T>::_description;
00051 #endif
00052 
00053      public:
00054           
00070           UnlabeledMultiArg( const std::string& name,
00071                                const std::string& desc,
00072                                const std::string& typeDesc,
00073                                  bool ignoreable = false,
00074                                Visitor* v = NULL );
00091           UnlabeledMultiArg( const std::string& name,
00092                                const std::string& desc,
00093                                const std::string& typeDesc,
00094                                  CmdLineInterface& parser,
00095                                  bool ignoreable = false,
00096                                Visitor* v = NULL );
00097                                
00111           UnlabeledMultiArg( const std::string& name,
00112                                  const std::string& desc,
00113                                  const std::vector<T>& allowed,
00114                                  bool ignoreable = false,
00115                                  Visitor* v = NULL );
00116 
00131           UnlabeledMultiArg( const std::string& name, 
00132                                  const std::string& desc, 
00133                                  const std::vector<T>& allowed,
00134                                  CmdLineInterface& parser,
00135                                  bool ignoreable = false,
00136                                  Visitor* v = NULL );
00137                                
00146           virtual bool processArg(int* i, std::vector<std::string>& args); 
00147 
00152           virtual std::string shortID(const std::string& val="val") const;
00153 
00158           virtual std::string longID(const std::string& val="val") const;
00159 
00164           virtual bool operator==(const Arg& a) const;
00165 
00170           virtual void addToList( std::list<Arg*>& argList ) const;
00171 };
00172 
00173 template<class T>
00174 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00175                                             const std::string& desc, 
00176                                              const std::string& typeDesc,
00177                                                   bool ignoreable,
00178                                              Visitor* v)
00179 : MultiArg<T>("", name, desc,  false, typeDesc, v)
00180 { 
00181      _ignoreable = ignoreable;
00182 }
00183 
00184 template<class T>
00185 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00186                                             const std::string& desc, 
00187                                              const std::string& typeDesc,
00188                                                   CmdLineInterface& parser,
00189                                                   bool ignoreable,
00190                                              Visitor* v)
00191 : MultiArg<T>("", name, desc,  false, typeDesc, v)
00192 { 
00193      _ignoreable = ignoreable;
00194      parser.add( this );
00195 }
00196 
00197 
00198 template<class T>
00199 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00200                                             const std::string& desc, 
00201                                              const std::vector<T>& allowed,
00202                                                   bool ignoreable,
00203                                              Visitor* v)
00204 : MultiArg<T>("", name, desc,  false, allowed, v)
00205 { 
00206      _ignoreable = ignoreable;
00207 }
00208 
00209 template<class T>
00210 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00211                                             const std::string& desc, 
00212                                              const std::vector<T>& allowed,
00213                                                   CmdLineInterface& parser,
00214                                                   bool ignoreable,
00215                                              Visitor* v)
00216 : MultiArg<T>("", name, desc,  false, allowed, v)
00217 { 
00218      _ignoreable = ignoreable;
00219      parser.add( this );
00220 }
00221 
00222 
00223 template<class T>
00224 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args) 
00225 {
00226 
00227      if ( _hasBlanks( args[*i] ) )
00228           return false;
00229 
00230      // never ignore an unlabeled multi arg
00231 
00232      _extractValue( args[*i] );
00233      return true;
00234 }
00235 
00236 template<class T>
00237 std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
00238 {
00239      std::string id = "<" + _typeDesc + "> ...";
00240 
00241      return id;
00242 }
00243 
00244 template<class T>
00245 std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
00246 {
00247      std::string id = "<" + _typeDesc + ">  (accepted multiple times)";
00248 
00249      return id;
00250 }
00251 
00252 template<class T>
00253 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
00254 {
00255      if ( _name == a.getName() || _description == a.getDescription() )
00256           return true;
00257      else
00258           return false;
00259 }
00260 
00261 template<class T>
00262 void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
00263 {
00264      argList.push_back( (Arg*)this );
00265 }
00266 
00267 }
00268 
00269 #endif

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