2015-10-04 14:42:45 +02:00
|
|
|
/*
|
|
|
|
* cmdlineoptions.h
|
|
|
|
*
|
|
|
|
* Created on: 04. Okt. 2015
|
|
|
|
* Author: qwc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CMDLINEOPTIONS_H_
|
|
|
|
#define CMDLINEOPTIONS_H_
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2015-10-04 20:10:52 +02:00
|
|
|
#include <map>
|
2015-10-04 14:42:45 +02:00
|
|
|
|
|
|
|
namespace cmdlineoptions {
|
|
|
|
|
|
|
|
// using namespace std;
|
|
|
|
|
|
|
|
class CmdLineOptions;
|
|
|
|
|
|
|
|
class Option {
|
|
|
|
private:
|
|
|
|
// important information
|
|
|
|
std::string name;
|
|
|
|
std::string description;
|
|
|
|
bool set;
|
2015-10-04 17:11:59 +02:00
|
|
|
// lists for attributes of an option
|
2015-10-04 14:42:45 +02:00
|
|
|
std::unique_ptr<std::list<std::string>> options;
|
|
|
|
std::unique_ptr<std::list<std::string>> possibleParameters;
|
|
|
|
std::unique_ptr<std::list<std::string>> defaultParameters;
|
2015-10-04 17:11:59 +02:00
|
|
|
// values, this list can only be filled by parsing the input data
|
2015-10-04 14:42:45 +02:00
|
|
|
std::unique_ptr<std::list<std::string>> values;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Option();
|
|
|
|
Option(std::string name);
|
|
|
|
virtual ~Option();
|
|
|
|
|
2015-10-04 17:11:59 +02:00
|
|
|
// Methods setting configuration attributes
|
|
|
|
std::shared_ptr<Option> setName(std::string name);
|
|
|
|
std::shared_ptr<Option> addCommand(std::string cmd);
|
|
|
|
std::shared_ptr<Option> addPossibleParameter(std::string param);
|
|
|
|
std::shared_ptr<Option> addDefaultParameter(std::string param);
|
|
|
|
std::shared_ptr<Option> setStrictChoice(bool strict);
|
2015-10-04 14:42:45 +02:00
|
|
|
|
2015-10-04 17:11:59 +02:00
|
|
|
// Methods for retrieving information in different formats
|
|
|
|
std::shared_ptr<std::list<std::string>> getValues();
|
|
|
|
std::string getValueAsString(uint index);
|
|
|
|
uint getValueCount();
|
|
|
|
int getValueAsInteger(uint index);
|
|
|
|
double getValueAsDouble(uint index);
|
|
|
|
float getValueAsFloat(uint index);
|
2015-10-04 14:42:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CmdLineOptions {
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~CmdLineOptions();
|
2015-10-04 20:10:52 +02:00
|
|
|
static const std::unique_ptr<CmdLineOptions> &i();
|
|
|
|
std::shared_ptr<Option> create(std::string &name);
|
|
|
|
std::shared_ptr<Option> getOption(std::string &name);
|
|
|
|
void setCommandCharacter(char &cmdchar);
|
2015-10-04 17:11:59 +02:00
|
|
|
|
2015-10-04 20:10:52 +02:00
|
|
|
void parse(char **argv, int argc);
|
2015-10-04 17:11:59 +02:00
|
|
|
void parse(std::list<std::string> argv);
|
2015-10-04 14:42:45 +02:00
|
|
|
|
|
|
|
private:
|
2015-10-04 17:11:59 +02:00
|
|
|
char cmdchar;
|
2015-10-04 14:42:45 +02:00
|
|
|
CmdLineOptions();
|
|
|
|
static std::unique_ptr<CmdLineOptions> instance;
|
2015-10-04 20:10:52 +02:00
|
|
|
std::map<std::string, std::shared_ptr<Option>> options;
|
2015-10-04 14:42:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace cmdlineoptions */
|
|
|
|
|
|
|
|
#endif /* CMDLINEOPTIONS_H_ */
|