/****************************************************************************** * * file: MultiArg.h * * Copyright (c) 2003, Michael E. Smoot . * All rights reverved. * * See the file COPYING in the top directory of this distribution for * more information. * * THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * *****************************************************************************/ #ifndef __MULTIPLE_ARGUMENT_HH__ #define __MULTIPLE_ARGUMENT_HH__ #include #include #include #include using namespace std; namespace TCLAP { template class MultiArg : public Arg { protected: vector _values; string _typeDesc; void _extractValue(int i, vector& args); public: MultiArg( const string& flag, const string& name, const string& desc, bool req, const string& typeDesc, Visitor* v = NULL); ~MultiArg(); virtual bool processArg(int* i, vector& args); const vector& getValue() ; virtual string shortID(const string& val="val") const; virtual string longID(const string& val="val") const; }; template MultiArg::MultiArg(const string& flag, const string& name, const string& desc, bool req, const string& typeDesc, Visitor* v) : Arg( flag, name, desc, req, true, v ), _typeDesc( typeDesc ) { }; template MultiArg::~MultiArg() { }; template const vector& MultiArg::getValue() { return _values; }; template bool MultiArg::processArg(int *i, vector& args) { if ( _ignoreable && Arg::ignoreRest() ) return false; if ( argMatches( args[*i] ) ) { (*i)++; if ( *i < args.size() ) { _extractValue( *i, args ); return true; } else throw( ArgException("Missing a value for this argument!", toString() ) ); } else return false; } template void MultiArg::_extractValue(int i, vector& args) { T temp; istringstream is(args[i]); is >> temp; if ( is.fail() ) throw( ArgException("Couldn't read argument value!", toString())); _values.push_back(temp); _checkWithVisitor(); } template string MultiArg::shortID(const string& val) const { string id = Arg::shortID(_typeDesc) + " ... "; return id; } template string MultiArg::longID(const string& val) const { string id = Arg::longID(_typeDesc) + " (accepted multiple times)"; return id; } } #endif