claw 1.9.0
 
Loading...
Searching...
No Matches
arguments.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@stuff-o-matic.com
24*/
30#ifndef __CLAW_ARGUMENTS_HPP__
31#define __CLAW_ARGUMENTS_HPP__
32
33#include <claw/ordered_set.hpp>
34
35#include <map>
36#include <string>
37
38namespace claw
39{
52 {
53 private:
54 typedef std::map<std::string, std::list<std::string> >
55 valued_arguments_map;
56
57 public:
58 arguments();
59 explicit arguments(const std::string& prog_name);
60 arguments(int& argc, char**& argv);
61 arguments(int& argc, char**& argv,
63
64 void parse(int& argc, char**& argv);
65 void parse(int& argc, char**& argv,
67
68 bool has_value(const std::string& arg_name) const;
69 bool only_integer_values(const std::string& arg_name) const;
70 bool only_real_values(const std::string& arg_name) const;
71
72 const std::string& get_program_name() const;
73
74 bool get_bool(const std::string& arg_name) const;
75 int get_integer(const std::string& arg_name) const;
76 double get_real(const std::string& arg_name) const;
77 const std::string& get_string(const std::string& arg_name) const;
78
79 std::list<int> get_all_of_integer(const std::string& arg_name) const;
80 std::list<double> get_all_of_real(const std::string& arg_name) const;
81 std::list<std::string>
82 get_all_of_string(const std::string& arg_name) const;
83
84 void add_argument(const std::string& arg);
85
86 private:
87 void parse(int& argc, char**& argv, bool always_allowed,
89 bool split_argument(const std::string& arg, std::string& name,
90 std::string& value) const;
91
92 void remove_null_arguments(int& argc, char**& argv) const;
93
94 void process_boolean(char*& arg, bool always_allowed,
96
97 private:
99 std::string m_program_name;
100
103
105 valued_arguments_map m_pairs;
106
107 }; // class arguments
108}
109
110#endif // __CLAW_ARGUMENTS_HPP__
void add_argument(const std::string &arg)
Add an argument in our list.
void parse(int &argc, char **&argv)
Parse arguments.
Definition arguments.cpp:89
double get_real(const std::string &arg_name) const
Get the real value of an argument.
bool has_value(const std::string &arg_name) const
Tell if a value is associated to an argument.
const std::string & get_program_name() const
Get the name of the program.
arguments()
Constructor.
Definition arguments.cpp:41
bool only_integer_values(const std::string &arg_name) const
Tell if only integer values are associated to an argument.
std::list< std::string > get_all_of_string(const std::string &arg_name) const
Get all string values of an argument.
bool get_bool(const std::string &arg_name) const
Get the boolean state of an argument.
const std::string & get_string(const std::string &arg_name) const
Get the string value of an argument.
std::list< int > get_all_of_integer(const std::string &arg_name) const
Get all integer values of an argument.
std::list< double > get_all_of_real(const std::string &arg_name) const
Get all real values of an argument.
int get_integer(const std::string &arg_name) const
Get the integer value of an argument.
bool only_real_values(const std::string &arg_name) const
Tell if only real values are associated to an argument.
A class to manage sets of ordered items.
This is the main namespace.
A class to manage sets of ordered items.