/*************************************************************************** * Copyright (C) 2005 by Mircea Bardac * * dev@mircea.bardac.net * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef ARGUMENTPARSER_H #define ARGUMENTPARSER_H #include #include /** @author Mircea Bardac @version 1.0 */ /** * Structure to hold an argument definition */ struct ArgumentDetails { // we will use this structure to keep extra information // on the arguments bool takesValue; QString helpdesc; }; /** * Class to handle arguments and their values */ class ArgumentParser{ private: int argc; char **argv; QMap abbrevs; // association: abbrev => argument name QMap arguments; // association: agument name => value QMap argData; // control attributes int gotError; // index where the parsing error occured bool stopOnUnknownArg; // flag which indicates if parsing stops when error is encountered QString convertAbbrev(const QString); bool takesValue(QString); bool knownArg(QString); // QString argGetValue(QString,int); // get value from --param="value value_continued end" // QString argGetValue(int &); //get value from -abrevparam "value value_2 ..." public: ArgumentParser(int, char**); ~ArgumentParser(); void parse(); void addArgument (const QString argname, const QString abbrev="", const bool takesValue=false, const QString helpdesc=""); // argument list management functions // void addAbbrev(QString argname, QString abbrev); // void removeAbbrev(QString abbrev); bool existsArg(const QString); // argument value reading functions int getInt(const QString); QString getString(const QString); // bool getBool(QString argname); // useless (use existsArg() instead) // debug functions bool parseError() { return (gotError>0); }; // void showArgs(); }; #endif