Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
Marcel M. Otte | a5ac7be0e9 | |
Marcel M. Otte | aea0ebba87 | |
Marcel Otte | 9527611da8 | |
Marcel M. Otte | 750bf518ce | |
Marcel M. Otte | bd6deca62e | |
Marcel M. Otte | 50b8645f8c | |
Marcel M. Otte | b6a26a17a1 | |
Marcel M. Otte | b23249d5b9 | |
Marcel M. Otte | e4d053e134 | |
Marcel M. Otte | 30b04c079e | |
Marcel M. Otte | cf03f083c0 | |
Marcel M. Otte | 7ed2f20596 | |
Marcel M. Otte | 3d44d607c8 |
|
@ -5,3 +5,6 @@
|
|||
*.war
|
||||
*.ear
|
||||
/bin
|
||||
*/.settings/
|
||||
*/.gradle
|
||||
*/build*
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
stages:
|
||||
- build
|
||||
|
||||
build-c:
|
||||
image: archlinux_gcc_qt5
|
||||
stage: build
|
||||
script:
|
||||
- cd c; make
|
||||
artifacts:
|
||||
paths:
|
||||
- c/libcmdlineoptions.*
|
||||
- c/tests-*
|
||||
|
||||
build-cpp:
|
||||
image: archlinux_gcc5.3_qt5
|
||||
stage: build
|
||||
script:
|
||||
- cd cpp; mkdir build; cd build
|
||||
- cmake ..
|
||||
- make
|
||||
artifacts:
|
||||
paths:
|
||||
- cpp/build/libCmdLineOptions.so
|
||||
- cpp/build/libCmdLineOptions_static.a
|
||||
|
||||
#test-c:
|
||||
#stage: test
|
||||
#script:
|
||||
#- cd c; make test
|
||||
#dependencies:
|
||||
#- build-c
|
|
@ -0,0 +1,3 @@
|
|||
*.user
|
||||
*.swp
|
||||
build*
|
|
@ -0,0 +1,8 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project(CmdLineOptions)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "--std=c++14 -g -Wall")
|
||||
add_library(CmdLineOptions_static STATIC CmdLineOptions.cpp)
|
||||
add_library(CmdLineOptions SHARED CmdLineOptions.cpp)
|
||||
|
||||
#add_executable(CmdLineOptions_test CmdLineOptions_test.cpp)
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* cmdlineoptions.cpp
|
||||
*
|
||||
* Created on: 04. Okt. 2015
|
||||
* Author: qwc
|
||||
*/
|
||||
|
||||
#include "CmdLineOptions.h"
|
||||
|
||||
namespace cmdlineoptions {
|
||||
|
||||
CmdLineOptions::~CmdLineOptions() {}
|
||||
|
||||
const std::unique_ptr<CmdLineOptions> &CmdLineOptions::i() {
|
||||
if (!instance) {
|
||||
instance = std::unique_ptr<CmdLineOptions>(new CmdLineOptions());
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
std::shared_ptr<Option> CmdLineOptions::create(std::string &name) {
|
||||
std::shared_ptr<Option> option = std::make_shared<Option>(name);
|
||||
this->options.insert(std::make_pair(name, option));
|
||||
return option;
|
||||
}
|
||||
|
||||
std::shared_ptr<Option> CmdLineOptions::getOption(std::string &name) {
|
||||
return this->options.at(name);
|
||||
}
|
||||
|
||||
void CmdLineOptions::setCommandCharacter(char &cmdchar) {
|
||||
this->cmdchar = cmdchar;
|
||||
}
|
||||
|
||||
void CmdLineOptions::parse(char **argv, int argc) {}
|
||||
|
||||
void CmdLineOptions::parse(std::list<std::string> argv) {}
|
||||
|
||||
CmdLineOptions::CmdLineOptions() {}
|
||||
|
||||
} /* namespace cmdlineoptions */
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* cmdlineoptions.h
|
||||
*
|
||||
* Created on: 04. Okt. 2015
|
||||
* Author: qwc
|
||||
*/
|
||||
|
||||
#ifndef CMDLINEOPTIONS_H_
|
||||
#define CMDLINEOPTIONS_H_
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
namespace cmdlineoptions {
|
||||
|
||||
// using namespace std;
|
||||
|
||||
class CmdLineOptions;
|
||||
|
||||
class Option {
|
||||
private:
|
||||
// important information
|
||||
std::string name;
|
||||
std::string description;
|
||||
bool set;
|
||||
// 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;
|
||||
// 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();
|
||||
|
||||
// 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);
|
||||
|
||||
// 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();
|
||||
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);
|
||||
|
||||
void parse(char **argv, int argc);
|
||||
void parse(std::list<std::string> argv);
|
||||
|
||||
private:
|
||||
char cmdchar;
|
||||
CmdLineOptions();
|
||||
static std::unique_ptr<CmdLineOptions> instance;
|
||||
std::map<std::string, std::shared_ptr<Option>> options;
|
||||
};
|
||||
|
||||
} /* namespace cmdlineoptions */
|
||||
|
||||
#endif /* CMDLINEOPTIONS_H_ */
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* cmdlineoptions_test.cpp
|
||||
*
|
||||
* Created on: 04. Okt. 2015
|
||||
* Author: qwc
|
||||
*/
|
||||
|
||||
#include "CmdLineOptions.h"
|
||||
|
||||
namespace cmdlineoptions {
|
||||
|
||||
int main(int argc, char**argv)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
} /* namespace cmdlineoptions */
|
Loading…
Reference in New Issue