• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

arguments.hpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #ifndef __CLAW_ARGUMENTS_HPP__
00031 #define __CLAW_ARGUMENTS_HPP__
00032 
00033 #include <string>
00034 #include <map>
00035 #include <claw/ordered_set.hpp>
00036 
00037 namespace claw
00038 {
00050   class arguments
00051   {
00052   private:
00053     typedef
00054     std::map< std::string, std::list<std::string> > valued_arguments_map;
00055 
00056   public:
00057     arguments();
00058     explicit arguments( const std::string& prog_name );
00059     arguments( int& argc, char** &argv );
00060     arguments( int& argc, char** &argv,
00061                const claw::math::ordered_set<std::string>& allowed );
00062 
00063     void parse( int& argc, char** &argv );
00064     void parse( int& argc, char** &argv,
00065                 const claw::math::ordered_set<std::string>& allowed );
00066 
00067     bool has_value( const std::string& arg_name ) const;
00068     bool only_integer_values( const std::string& arg_name ) const;
00069     bool only_real_values( const std::string& arg_name ) const;
00070 
00071     const std::string& get_program_name() const;
00072 
00073     bool get_bool( const std::string& arg_name ) const;
00074     int get_integer( const std::string& arg_name ) const;
00075     double get_real( const std::string& arg_name ) const;
00076     const std::string& get_string( const std::string& arg_name ) const;
00077 
00078     std::list<int> get_all_of_integer( const std::string& arg_name ) const;
00079     std::list<double> get_all_of_real( const std::string& arg_name ) const;
00080     std::list<std::string>
00081     get_all_of_string( const std::string& arg_name ) const;
00082 
00083     void add_argument( const std::string& arg );
00084 
00085   private:
00086     void parse( int& argc, char** &argv, bool always_allowed,
00087                 const claw::math::ordered_set<std::string>& allowed );
00088     void split_argument
00089     ( const std::string& arg, std::string& name, std::string& value ) const;
00090 
00091     void remove_null_arguments( int& argc, char** &argv ) const;
00092 
00093     void process_boolean
00094     ( char* &arg, bool always_allowed,
00095       const claw::math::ordered_set<std::string>& allowed );
00096 
00097   private:
00099     std::string m_program_name;
00100 
00102     claw::math::ordered_set<std::string> m_flags;
00103 
00105     valued_arguments_map m_pairs;
00106 
00107   }; // class arguments
00108 } // namespace claw
00109 
00110 #endif // __CLAW_ARGUMENTS_HPP__

Generated on Sat Sep 18 2010 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.1