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 #include <tclap/OptionalUnlabeledTracker.h>
00031 
00032 namespace TCLAP {
00033 
00039 template<class T>
00040 class UnlabeledMultiArg : public MultiArg<T>
00041 {
00042 
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         using MultiArg<T>::_alreadySet;
00052         using MultiArg<T>::toString;
00053 
00054         public:
00055                 
00073                 UnlabeledMultiArg( const std::string& name,
00074                                            const std::string& desc,
00075                                                    bool req,
00076                                            const std::string& typeDesc,
00077                                                    bool ignoreable = false,
00078                                            Visitor* v = NULL );
00097                 UnlabeledMultiArg( const std::string& name,
00098                                            const std::string& desc,
00099                                                    bool req,
00100                                            const std::string& typeDesc,
00101                                                    CmdLineInterface& parser,
00102                                                    bool ignoreable = false,
00103                                            Visitor* v = NULL );
00104                                                  
00120                 UnlabeledMultiArg( const std::string& name,
00121                                                    const std::string& desc,
00122                                                    bool req,
00123                                                    Constraint<T>* constraint,
00124                                                    bool ignoreable = false,
00125                                                    Visitor* v = NULL );
00126 
00143                 UnlabeledMultiArg( const std::string& name, 
00144                                                    const std::string& desc, 
00145                                                    bool req,
00146                                                    Constraint<T>* constraint,
00147                                                    CmdLineInterface& parser,
00148                                                    bool ignoreable = false,
00149                                                    Visitor* v = NULL );
00150                                                  
00159                 virtual bool processArg(int* i, std::vector<std::string>& args); 
00160 
00165                 virtual std::string shortID(const std::string& val="val") const;
00166 
00171                 virtual std::string longID(const std::string& val="val") const;
00172 
00177                 virtual bool operator==(const Arg& a) const;
00178 
00183                 virtual void addToList( std::list<Arg*>& argList ) const;
00184 };
00185 
00186 template<class T>
00187 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00188                                                         const std::string& desc, 
00189                                                                                 bool req,
00190                                                             const std::string& typeDesc,
00191                                                                                 bool ignoreable,
00192                                                             Visitor* v)
00193 : MultiArg<T>("", name, desc,  req, typeDesc, v)
00194 { 
00195         _ignoreable = ignoreable;
00196         OptionalUnlabeledTracker::check(true, toString());
00197 }
00198 
00199 template<class T>
00200 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00201                                                         const std::string& desc, 
00202                                                                                 bool req,
00203                                                             const std::string& typeDesc,
00204                                                                                 CmdLineInterface& parser,
00205                                                                                 bool ignoreable,
00206                                                             Visitor* v)
00207 : MultiArg<T>("", name, desc,  req, typeDesc, v)
00208 { 
00209         _ignoreable = ignoreable;
00210         OptionalUnlabeledTracker::check(true, toString());
00211         parser.add( this );
00212 }
00213 
00214 
00215 template<class T>
00216 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00217                                                         const std::string& desc, 
00218                                                                                 bool req,
00219                                                             Constraint<T>* constraint,
00220                                                                                 bool ignoreable,
00221                                                             Visitor* v)
00222 : MultiArg<T>("", name, desc,  req, constraint, v)
00223 { 
00224         _ignoreable = ignoreable;
00225         OptionalUnlabeledTracker::check(true, toString());
00226 }
00227 
00228 template<class T>
00229 UnlabeledMultiArg<T>::UnlabeledMultiArg(const std::string& name, 
00230                                                         const std::string& desc, 
00231                                                                                 bool req,
00232                                                             Constraint<T>* constraint,
00233                                                                                 CmdLineInterface& parser,
00234                                                                                 bool ignoreable,
00235                                                             Visitor* v)
00236 : MultiArg<T>("", name, desc,  req, constraint, v)
00237 { 
00238         _ignoreable = ignoreable;
00239         OptionalUnlabeledTracker::check(true, toString());
00240         parser.add( this );
00241 }
00242 
00243 
00244 template<class T>
00245 bool UnlabeledMultiArg<T>::processArg(int *i, std::vector<std::string>& args) 
00246 {
00247 
00248         if ( _hasBlanks( args[*i] ) )
00249                 return false;
00250 
00251         // never ignore an unlabeled multi arg
00252 
00253 
00254         // always take the first value, regardless of the start string 
00255         _extractValue( args[(*i)] );
00256 
00257         /*
00258         // continue taking args until we hit the end or a start string 
00259         while ( (unsigned int)(*i)+1 < args.size() &&
00260                         args[(*i)+1].find_first_of( Arg::flagStartString() ) != 0 &&
00261             args[(*i)+1].find_first_of( Arg::nameStartString() ) != 0 ) 
00262                 _extractValue( args[++(*i)] );
00263         */
00264 
00265         _alreadySet = true;
00266 
00267         return true;
00268 }
00269 
00270 template<class T>
00271 std::string UnlabeledMultiArg<T>::shortID(const std::string& val) const
00272 {
00273         static_cast<void>(val); // Ignore input, don't warn
00274         return std::string("<") + _typeDesc + "> ...";
00275 }
00276 
00277 template<class T>
00278 std::string UnlabeledMultiArg<T>::longID(const std::string& val) const
00279 {
00280         static_cast<void>(val); // Ignore input, don't warn
00281         return std::string("<") + _typeDesc + ">  (accepted multiple times)";
00282 }
00283 
00284 template<class T>
00285 bool UnlabeledMultiArg<T>::operator==(const Arg& a) const
00286 {
00287         if ( _name == a.getName() || _description == a.getDescription() )
00288                 return true;
00289         else
00290                 return false;
00291 }
00292 
00293 template<class T>
00294 void UnlabeledMultiArg<T>::addToList( std::list<Arg*>& argList ) const
00295 {
00296         argList.push_back( const_cast<Arg*>(static_cast<const Arg* const>(this)) );
00297 }
00298 
00299 }
00300 
00301 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


mapstitch
Author(s): Philipp M. Scholl
autogenerated on Mon Jul 15 2013 16:57:34