00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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 };
00108 }
00109
00110 #endif // __CLAW_ARGUMENTS_HPP__