Claw  1.7.3
arguments_table.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
31 #ifndef __CLAW_ARGUMENTS_TABLE_HPP__
32 #define __CLAW_ARGUMENTS_TABLE_HPP__
33 
34 #include <claw/arguments.hpp>
35 
36 namespace claw
37 {
49  {
50  private:
55  class argument_attributes
56  {
57  public:
58  argument_attributes( const std::string& name,
59  const std::string& second_name,
60  const std::string& help_message, bool optional,
61  const std::string& value_type );
62 
63  bool operator<( const argument_attributes& that ) const;
64 
65  std::string format_short_help() const;
66  std::string format_long_help() const;
67 
68  const std::string& get_name() const;
69  const std::string& get_second_name() const;
70 
71  bool is_optional() const;
72 
73  private:
75  const std::string m_name;
76 
78  const std::string m_second_name;
79 
81  const std::string m_help_message;
82 
84  const bool m_optional;
85 
87  const std::string m_value_type;
88 
89  }; // class argument_attributes
90 
91  public:
92  explicit arguments_table( const std::string& prog_name );
93  arguments_table( int& argc, char** &argv );
94 
95  void add( const std::string& short_name, const std::string& long_name,
96  const std::string& help_msg = "", bool optional = false,
97  const std::string& val_name = "" );
98  void add_long( const std::string& long_name,
99  const std::string& help_msg = "", bool optional = false,
100  const std::string& val_name = "" );
101  void add_short( const std::string& short_name,
102  const std::string& help_msg = "", bool optional = false,
103  const std::string& val_name = "" );
104 
105  void parse( int& argc, char** &argv );
106  void help( const std::string& free_args = "" ) const;
107 
108  bool required_fields_are_set() const;
109  bool has_value( const std::string& arg_name ) const;
110  bool only_integer_values( const std::string& arg_name ) const;
111  bool only_real_values( const std::string& arg_name ) const;
112 
113  const std::string& get_program_name() const;
114 
115  bool get_bool( const std::string& arg_name ) const;
116  int get_integer( const std::string& arg_name ) const;
117  double get_real( const std::string& arg_name ) const;
118  const std::string& get_string( const std::string& arg_name ) const;
119 
120  std::list<int> get_all_of_integer( const std::string& arg_name ) const;
121  std::list<double> get_all_of_real( const std::string& arg_name ) const;
122  std::list<std::string>
123  get_all_of_string( const std::string& arg_name ) const;
124 
125  void add_argument( const std::string& arg );
126 
127  private:
128  void get_argument_names( const std::string& arg_name,
129  std::string& short_name,
130  std::string& long_name ) const;
131 
132  private:
134  arguments m_arguments;
135 
137  math::ordered_set<argument_attributes> m_short_arguments;
138 
141 
142  }; // class arguments_table
143 } // namespace claw
144 
145 #endif // __CLAW_ARGUMENTS_TABLE_HPP__
claw::arguments_table::only_integer_values
bool only_integer_values(const std::string &arg_name) const
Tell if only integer values are associated to an argument.
Definition: arguments_table.cpp:333
claw::arguments_table::add_argument
void add_argument(const std::string &arg)
Add an argument in our list.
Definition: arguments_table.cpp:550
claw::arguments_table::only_real_values
bool only_real_values(const std::string &arg_name) const
Tell if only real values are associated to an argument.
Definition: arguments_table.cpp:360
claw::arguments_table::required_fields_are_set
bool required_fields_are_set() const
Tell if all arguments not marqued as "optional" have been specified in the command line.
Definition: arguments_table.cpp:289
claw::arguments_table::get_integer
int get_integer(const std::string &arg_name) const
Get the integer value of an argument.
Definition: arguments_table.cpp:410
claw::arguments_table::get_program_name
const std::string & get_program_name() const
Get the name of the program.
Definition: arguments_table.cpp:385
claw::arguments_table::get_string
const std::string & get_string(const std::string &arg_name) const
Get the string value of an argument.
Definition: arguments_table.cpp:451
claw::arguments_table::has_value
bool has_value(const std::string &arg_name) const
Tell if an argument has a value.
Definition: arguments_table.cpp:310
claw
This is the main namespace.
Definition: algorithm.hpp:33
claw::arguments_table::get_real
double get_real(const std::string &arg_name) const
Get the real value of an argument.
Definition: arguments_table.cpp:430
claw::arguments_table::parse
void parse(int &argc, char **&argv)
Parse the command line arguments.
Definition: arguments_table.cpp:214
claw::arguments_table::get_all_of_real
std::list< double > get_all_of_real(const std::string &arg_name) const
Get all real values of an argument.
Definition: arguments_table.cpp:496
claw::arguments_table::get_all_of_integer
std::list< int > get_all_of_integer(const std::string &arg_name) const
Get all integer values of an argument.
Definition: arguments_table.cpp:471
claw::math::ordered_set< argument_attributes >
claw::arguments_table::add
void add(const std::string &short_name, const std::string &long_name, const std::string &help_msg="", bool optional=false, const std::string &val_name="")
Add an argument in the table.
Definition: arguments_table.cpp:161
arguments.hpp
A class to manage the arguments of your program.
claw::arguments_table
A class to manage the arguments of your program, with automatic management of short/long arguments an...
Definition: arguments_table.hpp:48
claw::arguments_table::get_all_of_string
std::list< std::string > get_all_of_string(const std::string &arg_name) const
Get all string values of an argument.
Definition: arguments_table.cpp:521
claw::arguments_table::add_long
void add_long(const std::string &long_name, const std::string &help_msg="", bool optional=false, const std::string &val_name="")
Add an argument in the table.
Definition: arguments_table.cpp:180
claw::arguments_table::get_bool
bool get_bool(const std::string &arg_name) const
Get the boolean state of an argument.
Definition: arguments_table.cpp:395
claw::arguments
A class to manage the arguments of your program.
Definition: arguments.hpp:50
claw::arguments_table::add_short
void add_short(const std::string &short_name, const std::string &help_msg="", bool optional=false, const std::string &val_name="")
Add an argument in the table.
Definition: arguments_table.cpp:197
claw::arguments_table::help
void help(const std::string &free_args="") const
Print some help about the arguments.
Definition: arguments_table.cpp:239
claw::arguments_table::arguments_table
arguments_table(const std::string &prog_name)
Constructor.
Definition: arguments_table.cpp:132