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 arguments_table( int& argc, char** &argv );
00093
00094 void add( const std::string& short_name, const std::string& long_name,
00095 const std::string& help_msg = "", bool optional = false,
00096 const std::string& val_name = "" );
00097 void add_long( const std::string& long_name,
00098 const std::string& help_msg = "", bool optional = false,
00099 const std::string& val_name = "" );
00100 void add_short( const std::string& short_name,
00101 const std::string& help_msg = "", bool optional = false,
00102 const std::string& val_name = "" );
00103
00104 void parse( int& argc, char** &argv );
00105 void help( const std::string& free_args = "" ) const;
00106
00107 bool required_fields_are_set() const;
00108 bool has_value( const std::string& arg_name ) const;
00109
00110 const std::string& get_program_name() const;
00111
00112 bool get_bool( const std::string& arg_name ) const;
00113 int get_integer( const std::string& arg_name ) const;
00114 double get_real( const std::string& arg_name ) const;
00115 const std::string& get_string( const std::string& arg_name ) const;
00116
00117 void add_argument( const std::string& arg );
00118
00119 private:
00120 void get_argument_names( const std::string& arg_name,
00121 std::string& short_name,
00122 std::string& long_name ) const;
00123
00124 private:
00126 arguments m_arguments;
00127
00129 math::ordered_set<argument_attributes> m_short_arguments;
00130
00132 math::ordered_set<argument_attributes> m_long_arguments;
00133
00134 };
00135 }
00136
00137 #endif // __CLAW_ARGUMENTS_TABLE_HPP__