cmdlineoptions/cpp/CmdLineOptions.h

77 lines
2.0 KiB
C
Raw Permalink Normal View History

/*
* 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>
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
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
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 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);
};
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);
private:
2015-10-04 17:11:59 +02:00
char cmdchar;
CmdLineOptions();
static std::unique_ptr<CmdLineOptions> instance;
2015-10-04 20:10:52 +02:00
std::map<std::string, std::shared_ptr<Option>> options;
};
} /* namespace cmdlineoptions */
#endif /* CMDLINEOPTIONS_H_ */