Compare commits

...

13 Commits

7 changed files with 180 additions and 0 deletions

3
.gitignore vendored
View File

@ -5,3 +5,6 @@
*.war *.war
*.ear *.ear
/bin /bin
*/.settings/
*/.gradle
*/build*

31
.gitlab-ci.yml Normal file
View File

@ -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

3
cpp/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.user
*.swp
build*

8
cpp/CMakeLists.txt Normal file
View File

@ -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)

41
cpp/CmdLineOptions.cpp Normal file
View File

@ -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 */

76
cpp/CmdLineOptions.h Normal file
View File

@ -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_ */

View File

@ -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 */