| ... | ... |
@@ -82,107 +82,109 @@ |
| 82 | 82 |
class GroupData |
| 83 | 83 |
{
|
| 84 | 84 |
public: |
| 85 | 85 |
typedef std::list<std::string> Opts; |
| 86 | 86 |
Opts opts; |
| 87 | 87 |
bool only_one; |
| 88 | 88 |
bool mandatory; |
| 89 | 89 |
GroupData() :only_one(false), mandatory(false) {}
|
| 90 | 90 |
}; |
| 91 | 91 |
|
| 92 | 92 |
typedef std::map<std::string,GroupData> Groups; |
| 93 | 93 |
Groups _groups; |
| 94 | 94 |
|
| 95 | 95 |
struct OtherArg |
| 96 | 96 |
{
|
| 97 | 97 |
std::string name; |
| 98 | 98 |
std::string help; |
| 99 | 99 |
OtherArg(std::string n, std::string h) :name(n), help(h) {}
|
| 100 | 100 |
|
| 101 | 101 |
}; |
| 102 | 102 |
|
| 103 | 103 |
std::vector<OtherArg> _others_help; |
| 104 | 104 |
std::vector<std::string> _file_args; |
| 105 | 105 |
std::string _command_name; |
| 106 |
|
|
| 107 |
|
|
| 108 |
private: |
|
| 109 |
//Bind a function to an option. |
|
| 110 |
|
|
| 111 |
//\param name The name of the option. The leading '-' must be omitted. |
|
| 112 |
//\param help A help string. |
|
| 113 |
//\retval func The function to be called when the option is given. It |
|
| 114 |
// must be of type "void f(void *)" |
|
| 115 |
//\param data Data to be passed to \c func |
|
| 116 |
ArgParser &funcOption(const std::string &name, |
|
| 117 |
const std::string &help, |
|
| 118 |
void (*func)(void *),void *data); |
|
| 106 | 119 |
|
| 107 | 120 |
public: |
| 108 | 121 |
|
| 109 | 122 |
///\e |
| 110 | 123 |
ArgParser(int argc, const char **argv); |
| 111 | 124 |
|
| 112 | 125 |
~ArgParser(); |
| 113 | 126 |
|
| 114 | 127 |
///Add a new integer type option |
| 115 | 128 |
|
| 116 | 129 |
///\param name The name of the option. The leading '-' must be omitted. |
| 117 | 130 |
///\param help A help string. |
| 118 | 131 |
///\retval value The value of the argument will be written to this variable. |
| 119 | 132 |
///\param obl Indicate if the option is mandatory. |
| 120 | 133 |
ArgParser &intOption(const std::string &name, |
| 121 | 134 |
const std::string &help, |
| 122 | 135 |
int value=0, bool obl=false); |
| 123 | 136 |
|
| 124 | 137 |
///Add a new floating point type option |
| 125 | 138 |
|
| 126 | 139 |
///\param name The name of the option. The leading '-' must be omitted. |
| 127 | 140 |
///\param help A help string. |
| 128 | 141 |
///\retval value The value of the argument will be written to this variable. |
| 129 | 142 |
///\param obl Indicate if the option is mandatory. |
| 130 | 143 |
ArgParser &doubleOption(const std::string &name, |
| 131 | 144 |
const std::string &help, |
| 132 | 145 |
double value=0, bool obl=false); |
| 133 | 146 |
|
| 134 | 147 |
///Add a new bool type option |
| 135 | 148 |
|
| 136 | 149 |
///\param name The name of the option. The leading '-' must be omitted. |
| 137 | 150 |
///\param help A help string. |
| 138 | 151 |
///\retval value The value of the argument will be written to this variable. |
| 139 | 152 |
///\param obl Indicate if the option is mandatory. |
| 140 | 153 |
////\note A mandatory bool obtion is of very little use.) |
| 141 | 154 |
ArgParser &boolOption(const std::string &name, |
| 142 | 155 |
const std::string &help, |
| 143 | 156 |
bool value=false, bool obl=false); |
| 144 | 157 |
|
| 145 | 158 |
///Add a new string type option |
| 146 | 159 |
|
| 147 | 160 |
///\param name The name of the option. The leading '-' must be omitted. |
| 148 | 161 |
///\param help A help string. |
| 149 | 162 |
///\retval value The value of the argument will be written to this variable. |
| 150 | 163 |
///\param obl Indicate if the option is mandatory. |
| 151 | 164 |
ArgParser &stringOption(const std::string &name, |
| 152 | 165 |
const std::string &help, |
| 153 | 166 |
std::string value="", bool obl=false); |
| 154 |
|
|
| 155 |
///Bind a function to an option. |
|
| 156 |
|
|
| 157 |
///\param name The name of the option. The leading '-' must be omitted. |
|
| 158 |
///\param help A help string. |
|
| 159 |
///\retval func The function to be called when the option is given. It |
|
| 160 |
/// must be of type "void f(void *)" |
|
| 161 |
///\param data Data to be passed to \c func |
|
| 162 |
ArgParser &funcOption(const std::string &name, |
|
| 163 |
const std::string &help, |
|
| 164 |
void (*func)(void *),void *data); |
|
| 165 | 167 |
|
| 166 | 168 |
///\name Options with an external strorage. |
| 167 | 169 |
///Using this functions, the value of the option will be directly written |
| 168 | 170 |
///into a variable once the option appears in the command line. |
| 169 | 171 |
|
| 170 | 172 |
///@{
|
| 171 | 173 |
|
| 172 | 174 |
///Add a new integer type option with a storage reference |
| 173 | 175 |
|
| 174 | 176 |
///\param name The name of the option. The leading '-' must be omitted. |
| 175 | 177 |
///\param help A help string. |
| 176 | 178 |
///\retval ref The value of the argument will be written to this variable. |
| 177 | 179 |
///\param obl Indicate if the option is mandatory. |
| 178 | 180 |
ArgParser &refOption(const std::string &name, |
| 179 | 181 |
const std::string &help, |
| 180 | 182 |
int &ref, bool obl=false); |
| 181 | 183 |
|
| 182 | 184 |
///Add a new floating type option with a storage reference |
| 183 | 185 |
|
| 184 | 186 |
///\param name The name of the option. The leading '-' must be omitted. |
| 185 | 187 |
///\param help A help string. |
| 186 | 188 |
///\retval ref The value of the argument will be written to this variable. |
| 187 | 189 |
///\param obl Indicate if the option is mandatory. |
| 188 | 190 |
ArgParser &refOption(const std::string &name, |
0 comments (0 inline)