00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #ifndef __CLAW_ARGUMENTS_TABLE_HPP__
00032 #define __CLAW_ARGUMENTS_TABLE_HPP__
00033
00034 #include <claw/arguments.hpp>
00035
00036 namespace claw
00037 {
00048 class arguments_table
00049 {
00050 private:
00055 class argument_attributes
00056 {
00057 public:
00058 argument_attributes( const std::string& name,
00059 const std::string& second_name,
00060 const std::string& help_message, bool optional,
00061 const std::string& value_type );
00062
00063 bool operator<( const argument_attributes& that ) const;
00064
00065 std::string format_short_help() const;
00066 std::string format_long_help() const;
00067
00068 const std::string& get_name() const;
00069 const std::string& get_second_name() const;
00070
00071 bool is_optional() const;
00072
00073 private:
00075 const std::string m_name;
00076
00078 const std::string m_second_name;
00079
00081 const std::string m_help_message;
00082
00084 const bool m_optional;
00085
00087 const std::string m_value_type;
00088
00089 };
00090
00091 public:
00092 explicit arguments_table( const std::string& prog_name );
00093 arguments_table( int& argc, char** &argv );
00094
00095 void add( const std::string& short_name, const std::string& long_name,
00096 const std::string& help_msg = "", bool optional = false,
00097 const std::string& val_name = "" );
00098 void add_long( const std::string& long_name,
00099 const std::string& help_msg = "", bool optional = false,
00100 const std::string& val_name = "" );
00101 void add_short( const std::string& short_name,
00102 const std::string& help_msg = "", bool optional = false,
00103 const std::string& val_name = "" );
00104
00105 void parse( int& argc, char** &argv );
00106 void help( const std::string& free_args = "" ) const;
00107
00108 bool required_fields_are_set() const;
00109 bool has_value( const std::string& arg_name ) const;
00110 bool only_integer_values( const std::string& arg_name ) const;
00111 bool only_real_values( const std::string& arg_name ) const;
00112
00113 const std::string& get_program_name() const;
00114
00115 bool get_bool( const std::string& arg_name ) const;
00116 int get_integer( const std::string& arg_name ) const;
00117 double get_real( const std::string& arg_name ) const;
00118 const std::string& get_string( const std::string& arg_name ) const;
00119
00120 std::list<int> get_all_of_integer( const std::string& arg_name ) const;
00121 std::list<double> get_all_of_real( const std::string& arg_name ) const;
00122 std::list<std::string>
00123 get_all_of_string( const std::string& arg_name ) const;
00124
00125 void add_argument( const std::string& arg );
00126
00127 private:
00128 void get_argument_names( const std::string& arg_name,
00129 std::string& short_name,
00130 std::string& long_name ) const;
00131
00132 private:
00134 arguments m_arguments;
00135
00137 math::ordered_set<argument_attributes> m_short_arguments;
00138
00140 math::ordered_set<argument_attributes> m_long_arguments;
00141
00142 };
00143 }
00144
00145 #endif // __CLAW_ARGUMENTS_TABLE_HPP__