-#include "argument_reader.hh"
+#include "configuration_manager.hh"
#include <stdio.h>
/*!
*\brief Constructor.
*
- * This constructor makes a new argument_reader ready to use.
+ * This constructor makes a new configuration_manager ready to use.
*\arg name Name of the application as mentioned in the
* "Use: <appname> ..." help message.
*/
-argument_reader::argument_reader(string name){
+configuration_manager::configuration_manager(string name){
app_name=name;
}
/*!
- *\brief Add a new parameter to be searched for.
+ *\brief Add a new configuration value to be searched for.
*\param shortname A character for the short form.
- * For example the 'h' in -h
+ * For example the h in -h
*\param longname The double dash longname. For example
- * "input_file=" in --input_file= or
- * "ignore_errors" in --ignore--errors
- *\param description A detailed parameter description.
+ * input_file in --input_file= or
+ *\param description A detailed description of the value.
*\param status Pointer to an integer. Will be set to 1 if arg found.
- *\target Pointer to a value should be read.
- * If no value is needed, pass NULL.
+ *\target Pointer to to string to put the value in.
*\placeholder A placeholder for the documentation.
- * For example "<filename>" in -f<filename>
+ * For example <filename> in -f<filename>
*/
-void argument_reader::add_param (string shortname, string longname,
+void configuration_manager::add_option_value (string shortname, string longname,
string description,
bool allow_cmdline,
bool allow_conffile,
int * status,
string * target, string placeholder){
- if(status!=NULL) opt_v.insert(opt_v.end(),
- opt_t(shortname,longname, description,
+ if(status!=NULL) option_values.insert(opt_v.end(),
+ opt_value_t(shortname,longname, description,
status,target,placeholder)
);
}
* argument reader.
* There would be no other way to determine the order.
*/
-void argument_reader::add_argument(string placeholder, string description, int * status, string * target){
+void configuration_manager::add_argument(string placeholder, string description, int * status, string * target){
if (target!=NULL) if(status!=NULL)
arg_v.insert(arg_v.end(),arg_t(placeholder,description,status,target));
}
*\Read in the args passed to main().
*\returns empty vector on success or the error messages to be output.
*/
-vector<string> argument_reader::read_args(int argc, char ** args){
+vector<string> configuration_manager::read_args(int argc, char ** args){
vector<string> result;
vector<string> argv;
for (char ** akt=args; *akt ;akt++) argv.insert(argv.end(),string(*akt));
*\arg target Reference to a vector<string> to which lots of helpful
* strings are appended.
*/
-void argument_reader::get_help(vector<string> & target){
+void configuration_manager::get_help(vector<string> & target){
target.insert(target.end(),"");
string line="Usage: "+app_name;
for (vector<opt_t>::iterator parm_p=opt_v.begin();parm_p<opt_v.end();parm_p++){
*\brief Generate help.
*\return A vector containing many helpful strings for the user.
*/
-vector<string> argument_reader::get_help(){
+vector<string> configuration_manager::get_help(){
vector<string> result;
get_help(result);
return result;
/**************************************************/
-argument_reader::opt_t::opt_t(string n_shortname, string n_longname,string n_description, int * n_status,
+configuration_manager::opt_t::opt_t(string n_shortname, string n_longname,string n_description, int * n_status,
string * n_target, string n_placeholder){
shortname=n_shortname;
longname=n_longname;
if (status) *status=0;
}
-argument_reader::arg_t::arg_t( string n_placeholder, string n_description,
+configuration_manager::arg_t::arg_t( string n_placeholder, string n_description,
int * n_status, string * n_target){
description=n_description;
status=n_status;
* (You want!!!)
* Sould be easy to use..... Enjoy.
*/
-class argument_reader{
+class configuration_manager{
public:
- argument_reader(string name);
+ configuration_manager(string name);
- void add_param (string shortname,
- string longname,
- string description,
- int *status,
- bool allow_commandline=true,
- bool allow_config_file=true,
- string *target=NULL,
- string placeholder=string("<string>")
- );
+ void add_option_switch (string shortname,
+ string longname,
+ string description,
+ int *status,
+ bool allow_commandline=true,
+ bool allow_config_file=true
+ );
+
+ void add_option_value (string shortname,
+ string longname,
+ string description,
+ int *status,
+ bool allow_commandline=true,
+ bool allow_config_file=true,
+ string *target=NULL,
+ string placeholder=string("<string>")
+ );
+ void add_argument (string longname,
+ string description,
+ int *status,
+ string *target=NULL,
+ string placeholder=string("<string>")
+ );
+
vector<string> read_args(int argc, char ** args);
vector<string> read_file(string filename);
void get_help (vector<string> & target);
vector<string> get_help();
- void add_argument(string placeholder, string description, int * status, string * target);
-
private:
/*!
- *\brief Container for one command line option.
+ *\brief Container for an option switch
*/
- class opt_t{
+ class opt_switch_t{
public:
- opt_t (string shortname, string longname,string description, int * status,
+ opt_switch_t (string shortname, string longname,string description, int * status
string * target=NULL, string placeholder=string("<string>"));
string shortname;
string longname;
string description;
string placeholder;
};
+ /*!
+ *\brief Container for an option value
+ */
+class opt_value_t{
+ public:
+ switch_t (string shortname, string longname,string description, int * status
+ string * target=NULL, string placeholder=string("<string>"));
+ string shortname;
+ string longname;
+ int * status;
+ string * target;
+ string description;
+ string placeholder;
+ bool allow_conffile;
+ bool allow_cmdline;
+};
/*!
- *\brief Container for one command line argument.
+ *\brief Container for a commandline argument
*/
- class arg_t{
+ class cmd_arg_t{
public:
arg_t (string placeholder,string description,
int * status, string * target);
string description;
string placeholder;
};
- vector<opt_t>opt_v;
- vector<arg_t>arg_v;
+
+ vector<opt_switch_t>option_switches;
+ vector<opt_value_t>option_values;
+ vector<cmd_arg_t>cmd_args;
string app_name;
-}; // class argument_reader
+}; // class configuration_manager
#endif