CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
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-2010 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 */ 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 }; // class argument_attributes 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 }; // class arguments_table 00143 } // namespace claw 00144 00145 #endif // __CLAW_ARGUMENTS_TABLE_HPP__