arguments_table.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#ifndef __CLAW_ARGUMENTS_TABLE_HPP__
#define __CLAW_ARGUMENTS_TABLE_HPP__
#include <claw/arguments.hpp>
namespace claw
{
class arguments_table
{
private:
class argument_attributes
{
public:
argument_attributes( const std::string& name,
const std::string& second_name,
const std::string& help_message, bool optional,
const std::string& value_type );
bool operator<( const argument_attributes& that ) const;
std::string format_short_help() const;
std::string format_long_help() const;
const std::string& get_name() const;
const std::string& get_second_name() const;
bool is_optional() const;
private:
const std::string m_name;
const std::string m_second_name;
const std::string m_help_message;
const bool m_optional;
const std::string m_value_type;
}; // class argument_attributes
public:
explicit arguments_table( const std::string& prog_name );
arguments_table( int& argc, char** &argv );
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 = "" );
void add_long( const std::string& long_name,
const std::string& help_msg = "", bool optional = false,
const std::string& val_name = "" );
void add_short( const std::string& short_name,
const std::string& help_msg = "", bool optional = false,
const std::string& val_name = "" );
void parse( int& argc, char** &argv );
void help( const std::string& free_args = "" ) const;
bool required_fields_are_set() const;
bool has_value( const std::string& arg_name ) const;
bool only_integer_values( const std::string& arg_name ) const;
bool only_real_values( const std::string& arg_name ) const;
const std::string& get_program_name() const;
bool get_bool( const std::string& arg_name ) const;
int get_integer( const std::string& arg_name ) const;
double get_real( const std::string& arg_name ) const;
const std::string& get_string( const std::string& arg_name ) const;
std::list<int> get_all_of_integer( const std::string& arg_name ) const;
std::list<double> get_all_of_real( const std::string& arg_name ) const;
std::list<std::string>
get_all_of_string( const std::string& arg_name ) const;
void add_argument( const std::string& arg );
private:
void get_argument_names( const std::string& arg_name,
std::string& short_name,
std::string& long_name ) const;
private:
arguments m_arguments;
math::ordered_set<argument_attributes> m_short_arguments;
math::ordered_set<argument_attributes> m_long_arguments;
}; // class arguments_table
} // namespace claw
#endif // __CLAW_ARGUMENTS_TABLE_HPP__
arguments.hpp
A class to manage the arguments of your program.
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::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::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::arguments_table
arguments_table(const std::string &prog_name)
Constructor.
Definition arguments_table.cpp:132
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::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::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::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::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::add_argument
void add_argument(const std::string &arg)
Add an argument in our list.
Definition arguments_table.cpp:550
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_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::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_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::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
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_real
double get_real(const std::string &arg_name) const
Get the real value of an argument.
Definition arguments_table.cpp:430
claw::arguments
A class to manage the arguments of your program.
Definition arguments.hpp:51
claw::math::ordered_set
A class to manage sets of ordered items.
Definition ordered_set.hpp:46
claw
This is the main namespace.
Definition algorithm.hpp:34