Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

base.CommandLineManager.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 Eric NICOLAS
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018   --------------------------------------------------------------------------*/
00019 #ifndef _SWORD_BASE_COMMANDLINEMANAGER_
00020 #define _SWORD_BASE_COMMANDLINEMANAGER_
00021 
00022 // The command line tools are initially based on the "option--" library by
00023 // Christian Holm and thus part of this source code is "Copyright (C) 2002
00024 // Christian Holm Christensen <cholm@nbi.dk>". However, lots of modifications
00025 // have been made both in the interfaces and in the way it behaves, so
00026 // don't expect any kind of compatibility.
00027 //
00028 // For information, the original library, also released under the termes
00029 // of the LGPL can be found at http://cholm.home.cern.ch/cholm/misc/#optionmm
00030 
00031 #include "base.CommandLineOptionBase.h"
00032 #include "base.CommandLineOption.h"
00033 #include "base.CommandLineFlag.h"
00034 #include <vector>
00035 
00036 namespace sword {
00037 
00039 
00105         class SWORDDECL CommandLineManager {
00106                 friend class CommandLineOptionBase;
00107         public:
00109 
00121                 CommandLineManager(
00122                         const std::string &title,
00123                         const std::string &version,
00124                         const std::string &copyright,
00125                         const std::string &usage,
00126                         int &argc,
00127                         char **argv,
00128                         bool fail=true);
00129 
00131                 void help(std::ostream &os) const;
00132 
00134                 void version(std::ostream &os) const;
00135 
00137                 bool wantHelp() const;
00138 
00140                 bool wantVersion() const;
00141 
00143 
00144                 void process();
00145 
00147     size_t size() const;
00148 
00149                 class ParsingException : public Exception {};
00150     class DuplicateOptionException : public Exception {};
00151 
00152         private:
00153                 std::string title_;
00154                 std::string version_;
00155                 std::string copyright_;
00156                 std::string usage_;
00157                 int   &argc_;
00158                 char **argv_;
00159                 bool   fail_;
00160                 //
00161                 typedef std::vector<CommandLineOptionBase*> Options;
00162                 Options     options_;
00163                 std::string programName_;
00164                 //
00165                 CommandLineFlag<bool> optionHelp_;
00166                 CommandLineFlag<bool> optionVersion_;
00167 
00168                 void add_(CommandLineOptionBase* option);
00169     void remove_(CommandLineOptionBase* option);
00170                 void handleShortOption_(int &i);
00171                 void handleLongOption_(int &i);
00172                 void cleanup_();
00173 
00174         private:
00175                 CommandLineManager(const CommandLineManager &rhs);
00176                 CommandLineManager &operator=(const CommandLineManager &rhs);
00177         };
00178 
00179 } // namespace sword
00180 
00181 #endif // _SWORD_BASE_COMMANDLINEMANAGER_

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2