ionflux.org | Impressum

CLArgs.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_CLARGS
00002 #define IONFLUX_TOOLS_CLARGS
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * CLArgs.hpp                    Command line argument parser.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <vector>
00032 #include "ionflux/Reporter.hpp"
00033 #include "ionflux/Tokenizer.hpp"
00034 
00035 namespace Ionflux
00036 {
00037 
00038 namespace Tools
00039 {
00040 
00048 
00049 typedef std::vector<std::string> CLParams;
00050 
00056 struct CLOption
00057 {
00059     std::string option;
00061     std::string value;
00068     bool splittable;
00069 };
00070 
00075 struct CLAcceptableOption
00076 {
00078     std::string option;
00080     bool acceptValue;
00081 };
00082 
00097 class CLArgs
00098 {
00099     protected:
00101         Ionflux::Tools::Reporter log;
00103         std::vector<std::string> args;
00105         std::vector<CLOption *> options;
00107         CLParams params;
00109         std::vector<CLAcceptableOption *> acceptable;
00111         bool checkOptions;
00113         std::vector<std::string> invalidOptions;
00114         
00128         virtual bool addOption(CLOption *newOption);
00129         
00131         virtual void parse();
00132         
00133     public:
00135         static const TokenType TT_OPTION;
00137         static const TokenType TT_ASSIGN;
00139         static const CLOption OPTION_NOT_SET;
00140         
00145         CLArgs();
00146         
00154         CLArgs(int argc, char *argv[]);
00155         
00160         virtual ~CLArgs();
00161         
00169         virtual void setArgs(int argc, char *argv[]);
00170         
00180         virtual CLOption *getOption(const std::string &searchOption);
00181         
00190         virtual bool isSet(const std::string &checkOption);
00191         
00199         virtual void getParams(CLParams &target);
00200         
00209         virtual void setCheckOptions(bool newCheckOptions);
00210         
00223         virtual void addAcceptableOption(const std::string &newOption, 
00224             bool newAcceptValue);
00225         
00235         virtual bool getCheckOptions();
00236         
00246         virtual CLAcceptableOption *getAcceptableOption(
00247             const std::string &searchOption);
00248         
00257         virtual bool isAcceptable(const std::string &checkOption);
00258         
00268         virtual bool acceptsValue(const std::string &checkOption);
00269         
00278         virtual std::vector<std::string> &getInvalidOptions();
00279         
00286         virtual bool optionsOK();
00287         
00289         virtual void clearAcceptableOptions();
00290         
00292         virtual void clearOptions();
00293         
00295         virtual void clearParams();
00296         
00298         virtual void printDebugInfo();
00299         
00304         virtual Reporter &getLog();
00305 };
00306 
00308 
00309 }
00310 
00311 }
00312 
00316 #endif

Generated on Tue Mar 14 20:58:29 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6