This commit is contained in:
T. van der Zwan 2013-08-14 08:55:17 +00:00
commit e8b97dcb01
19 changed files with 3373 additions and 3 deletions

View File

@ -1,7 +1,8 @@
# define the minimum cmake version (as required by cmake)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_TOOLCHAIN_FILE /opt/raspberrypi/Toolchain-RaspberryPi.cmake)
#set(CMAKE_TOOLCHAIN_FILE /opt/raspberrypi/Toolchain-RaspberryPi.cmake)
# Define the main-project name
project(Hyperion)

View File

@ -7,3 +7,4 @@
# otherwise agree to in writing.
add_subdirectory(jsoncpp)
add_subdirectory(getoptPlusPlus)

View File

@ -0,0 +1,17 @@
# Copyright (c) 2012 TNO, The Netherlands.
#
# This file contains information proprietary to TNO.
#
# Any disclosure or use of this information or any reproduction of this document or any part thereof for
# other than the specified purpose for which it is intended is expressly prohibited except as TNO may
# otherwise agree to in writing.
project(getoptPlusPlus)
include_directories(
../../include/getoptPlusPlus)
add_library(getoptPlusPlus
../../include/getoptPlusPlus/getoptpp.h
../../include/getoptPlusPlus/parameter.include.cc
getoptpp.cc)

View File

@ -0,0 +1,66 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.
“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.
An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.
A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.
The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.
The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version:
* a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or
* b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:
* a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
* b) Accompany the object code with a copy of the GNU GPL and this license document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following:
* a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License.
* b) Accompany the Combined Work with a copy of the GNU GPL and this license document.
* c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document.
* d) Do one of the following:
o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.
o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version.
* e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following:
* a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License.
* b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

View File

@ -0,0 +1,16 @@
SOURCES=getoptpp.cc test.cc
HEADERS=getoptpp.h
OBJECTS=$(SOURCES:.cc=.o)
LDFLAGS=
CXXFLAGS=-O0 -ggdb -Wall
CFLAGS=$(CXXFLAGS)
CC=g++
TARGET=getopt-test
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CXX) $(LDFLAGS) -o $(TARGET) $(OBJECTS)
$(SOURCES): $(HEADERS)
clean:
rm -rf $(TARGET) $(OBJECTS) *~

View File

@ -0,0 +1,8 @@
A very small class library that replaces getopt() and
getopt_long()-functionality with a more C++-friendly approach.
Additionally, it does not rely on UNIX-specific code.
See test.cc for a sample application and COPYING for license information.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,337 @@
/* (C) 2011 Viktor Lofgren
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "getoptpp.h"
#include <stdexcept>
#include <cassert>
using namespace std;
namespace vlofgren {
/*
*
* Class OptionsParser
*
*
*/
OptionsParser::OptionsParser(const char* programDesc) : fprogramDesc(programDesc) {}
OptionsParser::~OptionsParser() {}
ParameterSet& OptionsParser::getParameters() {
return parameters;
}
void OptionsParser::parse(int argc, const char* argv[]) throw(runtime_error)
{
argv0 = argv[0];
if(argc == 1) return;
vector<string> v(&argv[1], &argv[argc]);
ParserState state(*this, v);
for(; !state.end(); state.advance()) {
std::list<Parameter*>::iterator i;
for(i = parameters.parameters.begin();
i != parameters.parameters.end(); i++)
{
int n = 0;
try
{
n = (*i)->receive(state);
}
catch(Parameter::ExpectedArgument &)
{
throw Parameter::ExpectedArgument(state.get() + ": expected an argument");
}
catch(Parameter::UnexpectedArgument &)
{
throw Parameter::UnexpectedArgument(state.get() + ": did not expect an argument");
}
catch(Switchable::SwitchingError &)
{
throw Parameter::ParameterRejected(state.get() + ": parameter already set");
}
catch(Parameter::ParameterRejected & pr) {
std::string what = pr.what();
if(what.length())
{
throw Parameter::ParameterRejected(state.get() + ": " + what);
}
throw Parameter::ParameterRejected(state.get() + " (unspecified error)");
}
for (int j = 1; j < n; ++j)
{
state.advance();
}
if(n != 0)
{
break;
}
}
if(i == parameters.parameters.end()) {
std::string file = state.get();
if(file == "--") {
state.advance();
break;
}
else if(file.at(0) == '-')
throw Parameter::ParameterRejected(string("Bad parameter: ") + file);
else files.push_back(state.get());
}
}
if(!state.end()) for(; !state.end(); state.advance()) {
files.push_back(state.get());
}
}
void OptionsParser::usage() const {
cerr << fprogramDesc << endl;
cerr << "Usage: " << programName() << " [OPTIONS]" << endl << endl;
cerr << "Parameters: " << endl;
std::list<Parameter*>::const_iterator i;
for(i = parameters.parameters.begin();
i != parameters.parameters.end(); i++)
{
cerr.width(30);
cerr << std::left << " " + (*i)->usageLine();
cerr.width(40);
cerr << std::left << (*i)->description() << endl;
}
}
const vector<string>& OptionsParser::getFiles() const {
return files;
}
const string& OptionsParser::programName() const {
return argv0;
}
/*
* Parameter set
*
*
*/
ParameterSet::ParameterSet(const ParameterSet& ps) {
throw new runtime_error("ParameterSet not copyable");
}
ParameterSet::~ParameterSet() {
for(std::list<Parameter*>::iterator i = parameters.begin();
i != parameters.end(); i++)
{
delete *i;
}
}
/* The typical use case for command line arguments makes linear searching completely
* acceptable here.
*/
Parameter& ParameterSet::operator[](char c) const {
for(std::list<Parameter*>::const_iterator i = parameters.begin(); i!= parameters.end(); i++) {
if((*i)->shortOption() == c) return *(*i);
}
throw out_of_range("ParameterSet["+c+string("]"));
}
Parameter& ParameterSet::operator[](const string& param) const {
for(std::list<Parameter*>::const_iterator i = parameters.begin(); i!= parameters.end(); i++) {
if((*i)->longOption() == param) return *(*i);
}
throw out_of_range("ParameterSet["+param+"]");
}
/*
*
* Class ParserState
*
*
*/
ParserState::ParserState(OptionsParser &opts, vector<string>& args) :
opts(opts), arguments(args), iterator(args.begin())
{
}
const string ParserState::peek() const {
vector<string>::const_iterator next = iterator+1;
if(next != arguments.end()) return *next;
else return "";
}
const string ParserState::get() const {
if(!end()) return *iterator;
else return "";
}
void ParserState::advance() {
iterator++;
}
bool ParserState::end() const {
return iterator == arguments.end();
}
/*
*
* Class Parameter
*
*
*/
Parameter::Parameter(char shortOption, const std::string & longOption, const std::string & description) :
fshortOption(shortOption), flongOption(longOption), fdescription(description)
{
}
Parameter::~Parameter() {}
const string& Parameter::description() const { return fdescription; }
const string& Parameter::longOption() const { return flongOption; }
bool Parameter::hasShortOption() const { return fshortOption != 0x0; }
char Parameter::shortOption() const { assert(hasShortOption()); return fshortOption; }
/*
*
* Class Switchable
*
*
*/
bool Switchable::isSet() const { return fset; }
Switchable::~Switchable() {};
Switchable::Switchable() : fset(false) {}
void MultiSwitchable::set() throw (Switchable::SwitchingError) { fset = true; }
MultiSwitchable::~MultiSwitchable() {}
void UniquelySwitchable::set() throw (Switchable::SwitchingError) {
if(UniquelySwitchable::isSet()) throw Switchable::SwitchingError();
fset = true;
}
UniquelySwitchable::~UniquelySwitchable() {}
PresettableUniquelySwitchable::~PresettableUniquelySwitchable() {}
bool PresettableUniquelySwitchable::isSet() const {
return UniquelySwitchable::isSet() || fpreset.isSet();
}
void PresettableUniquelySwitchable::set() throw (Switchable::SwitchingError)
{
UniquelySwitchable::set();
}
void PresettableUniquelySwitchable::preset() {
fpreset.set();
}
/*
*
* PODParameter specializations
*
*
*
*/
template<>
PODParameter<string>::PODParameter(char shortOption, const char *longOption,
const char* description) : CommonParameter<PresettableUniquelySwitchable>(shortOption, longOption, description) {
preset();
}
template<>
int PODParameter<int>::validate(const string &s) throw(Parameter::ParameterRejected)
{
// This is sadly necessary for strto*-functions to operate on
// const char*. The function doesn't write to the memory, though,
// so it's quite safe.
char* cstr = const_cast<char*>(s.c_str());
if(*cstr == '\0') throw ParameterRejected("No argument given");
long l = strtol(cstr, &cstr, 10);
if(*cstr != '\0') throw ParameterRejected("Expected int");
if(l > INT_MAX || l < INT_MIN) {
throw ParameterRejected("Expected int");
}
return l;
}
template<>
long PODParameter<long>::validate(const string &s) throw(Parameter::ParameterRejected)
{
char* cstr = const_cast<char*>(s.c_str());
if(*cstr == '\0') throw ParameterRejected("No argument given");
long l = strtol(cstr, &cstr, 10);
if(*cstr != '\0') throw ParameterRejected("Expected long");
return l;
}
template<>
double PODParameter<double>::validate(const string &s) throw(Parameter::ParameterRejected)
{
char* cstr = const_cast<char*>(s.c_str());
if(*cstr == '\0') throw ParameterRejected("No argument given");
double d = strtod(cstr, &cstr);
if(*cstr != '\0') throw ParameterRejected("Expected double");
return d;
}
template<>
string PODParameter<string>::validate(const string &s) throw(Parameter::ParameterRejected)
{
return s;
}
} //namespace

View File

@ -0,0 +1,196 @@
/* (C) 2011 Viktor Lofgren
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "getoptpp.h"
#include <cstdlib>
#include <cctype>
#include <iostream>
#include <algorithm>
using namespace std;
using namespace vlofgren;
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/*
*
* This is one way of adding new parameter types,
* inheriting existing types and adding new validation.
*
* In this case, StringParameter (which is a typedef of PODParameter<string> gets
* a new validator that only accepts strings with only letters.
*
*/
class AlphabeticParameter : public StringParameter {
public:
AlphabeticParameter(char shortName, const char* longName, const char* description) :
StringParameter(shortName, longName, description) {}
virtual ~AlphabeticParameter() {}
void receiveSwitch() throw(Parameter::ParameterRejected) {
throw Parameter::ParameterRejected();
}
/* isalpha may be a macro */
static bool isNotAlpha(char c) { return !isalpha(c); }
virtual string validate(const string& arg) throw(Parameter::ParameterRejected) {
int nonalpha = count_if(arg.begin(), arg.end(), isNotAlpha);
if(nonalpha) throw Parameter::ParameterRejected("I only want numbers");
else return arg;
}
};
/*
*
* The other way is to specialize the PODParameter class
*
*/
enum RockPaperScissor { ROCK, PAPER, SCISSOR } ;
namespace vlofgren {
// needs to live in the vlofgren namespace for whatever reason
template<> enum RockPaperScissor
PODParameter<enum RockPaperScissor>::validate(const string &s) throw(Parameter::ParameterRejected)
{
if(s == "rock")
return ROCK;
else if(s == "paper")
return PAPER;
else if(s == "scissor")
return SCISSOR;
else {
throw ParameterRejected("Invalid argument");
}
}
}
typedef PODParameter<enum RockPaperScissor> RockPaperScissorParameter;
/*
*
* Dummy program
*
*/
int main(int argc, const char* argv[]) {
// Create a parser
OptionsParser optp("An example program (that also runs some tests)");
ParameterSet& ps = optp.getParameters();
/* An alternative option is to simply extend the options parser and set all this up
* in the constructor.
*/
ps.add<SwitchParameter>('f', "foo", "Enable the foo system (no argument)");
ps.add<StringParameter>('b', "bar", "Enable the bar system (string argument)");
ps.add<PODParameter<double> >('z', "baz", "Enable the baz system (floating point argument");
PODParameter<int>& i = ps.add<PODParameter<int> >('i', "foobar", "Enable the foobar system (integer argument");
i.setDefault(15);
ps.add<AlphabeticParameter>('a', "alpha", "Custom parameter that requires a string of letters");
ps.add<RockPaperScissorParameter>('r', "rps", "Takes the values rock, paper or scissor");
ps.add<SwitchParameter>('h', "help", "Display help screen");
// Register the parameters with the parser
try {
// Parse argv
optp.parse(argc, argv);
// Test for the help flag
if(ps['h'].isSet()) {
optp.usage();
return EXIT_SUCCESS;
}
// Print out what values the parameters were given
cout << "The following parameters were set:" << endl;
cout << "foo: " << (ps['f'].isSet() ? "true" : "false") << endl;
cout << "bar: \"" << ps['b'].get<string>() << "\""<< endl;
cout << "baz: ";
if(ps['z'].isSet()) {
cout << ps['z'].get<double>() << endl;
} else {
cout << "not set" << endl;
}
/* You can also save the return value from ParserSet::add() if
* you feel the operator[].get<T>() stuff is a bit much */
cout << "foobar: ";
if(i.isSet()) {
cout << i.get<int>() << endl;
} else {
cout << "not set" << endl;
}
cout << "alpha: ";
if(ps["alpha"].isSet()) {
cout << ps["alpha"].get<string>() << endl;
} else {
cout << "not set" << endl;
}
cout << "rps: ";
if(ps["rps"].isSet()) {
cout << ps["rps"].get<enum RockPaperScissor>() << endl;
} else {
cout << "not set" << endl;
}
} catch(Parameter::ParameterRejected &p){
// This will happen if the user has fed some malformed parameter to the program
cerr << p.what() << endl;
optp.usage();
return EXIT_FAILURE;
} catch(runtime_error &e) {
// This will happen if you try to access a parameter that hasn't been set
cerr << e.what() << endl;
return EXIT_FAILURE;
}
// List what non-parameter options were given (typically files)
cout << "The following file arguments were given:" << endl;
vector<string> files = optp.getFiles();
for(vector<string>::iterator i = files.begin(); i != files.end(); i++) {
cout << "\t" << *i << endl;
}
return EXIT_SUCCESS;
}
#endif

Binary file not shown.

View File

@ -0,0 +1,398 @@
/* (C) 2011 Viktor Lofgren
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modifications:
*
* - Removed using namespace std from header
* - Changed Parameter container type from std::set to std::list to presume order
* - Changed arguments of Parameters to be a seperated arguments on the command line
* - Make the choice of receiving arguments or not in subclasses of CommonParameter
*/
#include <list>
#include <vector>
#include <stdexcept>
#include <string>
#include <climits>
#include <cstdlib>
#include <sstream>
#include <iostream>
#ifndef GETOPTPP_H
#define GETOPTPP_H
namespace vlofgren {
class Parameter;
class ParserState;
class OptionsParser;
/** Container for a set of parameters */
class ParameterSet {
public:
/** Find a parameter by short option form */
Parameter& operator[](char c) const;
/** Find a parameter by long option form. */
Parameter& operator[](const std::string &s) const;
/** Factory method that adds a new parameter of
* type T to the set.
*
* This is just for convenience. It allows ParameterSet
* to manage the pointers, as well as (usually) making the
* code slightly easier to read.
*
* Do not try to add non-Parameter types lest you will invoke
* the wrath of gcc's template error messages.
*
* @returns The created parameter. The reference is valid
* as long as ParameterSet exists.
*/
template<typename T>
T &add(char shortName, const char* longName, const char* description);
ParameterSet() {}
~ParameterSet();
protected:
friend class OptionsParser;
std::list<Parameter*> parameters;
private:
ParameterSet(const ParameterSet& ps);
};
/** getopt()-style parser for command line arguments
*
* Matches each element in argv against given
* parameters, and collects non-parameter arguments
* (typically files) in a vector.
*
*/
class OptionsParser {
public:
OptionsParser(const char *programDesc);
virtual ~OptionsParser();
ParameterSet& getParameters();
/** Parse command line arguments */
void parse(int argc, const char* argv[]) throw(std::runtime_error);
/** Generate a usage screen */
void usage() const;
/** Return the name of the program, as
* given by argv[0]
*/
const std::string& programName() const;
/** Return a vector of each non-parameter */
const std::vector<std::string>& getFiles() const;
protected:
std::string argv0;
std::string fprogramDesc;
ParameterSet parameters;
std::vector<std::string> files;
friend class ParserState;
};
/**
* Corresponds to the state of the parsing, basically just a wrapper
* for a const_iterator that handles nicer.
*/
class ParserState {
public:
const std::string peek() const;
const std::string get() const;
void advance();
bool end() const;
protected:
ParserState(OptionsParser &opts, std::vector<std::string>& args);
private:
friend class OptionsParser;
OptionsParser &opts;
const std::vector<std::string> &arguments;
std::vector<std::string>::const_iterator iterator;
};
/**
*
* Abstract base class of all parameters
*
*/
class Parameter {
public:
/** Generic exception thrown when a parameter is malformed
*/
class ParameterRejected : public std::runtime_error {
public:
ParameterRejected(const std::string& s) : std::runtime_error(s) {}
ParameterRejected() : runtime_error("") {}
};
/** Exception thrown when a parameter did not expect an argument */
class UnexpectedArgument : public ParameterRejected {
public:
UnexpectedArgument(const std::string &s) : ParameterRejected(s) {}
UnexpectedArgument() {}
};
/** Exception thrown when a parameter expected an argument */
class ExpectedArgument : public ParameterRejected {
public:
ExpectedArgument(const std::string &s) : ParameterRejected(s) {}
ExpectedArgument() {}
};
Parameter(char shortOption, const std::string & longOption, const std::string & description);
virtual ~Parameter();
/** Test whether the parameter has been set */
virtual bool isSet() const = 0;
/** This parameter's line in OptionsParser::usage() */
virtual std::string usageLine() const = 0;
/** Description of the parameter (rightmost field in OptionsParser::usage()) */
const std::string& description() const;
/** The long name of this parameter (e.g. "--option"), without the dash. */
const std::string& longOption() const;
/** Check if this parameters has a short option */
bool hasShortOption() const;
/** The short name of this parameter (e.g. "-o"), without the dash. */
char shortOption() const;
protected:
/** Receive a potential parameter from the parser (and determien if it's ours)
*
* The parser will pass each potential parameter through it's registered parameters'
* receive function.
*
* @throw ParameterRejected if the parameter belongs to us, but is malformed somehow.
*
* @param state Allows access to the current argument. This is a fairly powerful
* iterator that technically allows for more complex grammar than what is
* presently used.
*/
virtual int receive(ParserState& state) throw(ParameterRejected) = 0;
friend class OptionsParser;
char fshortOption;
const std::string flongOption;
const std::string fdescription;
private:
};
/*
*
* Abstract base class of all parameters
*
*/
class Switchable;
/** Base class for most parameter implementations.
*
* It parses the argument in receive() and if it matches,
* calls receiveSwitch() or receiveArgument() which are implemented
* in child classes.
*
* The SwitchingBehavior mixin determines what happens if the argument
* is set multiple times.
*/
template<typename SwitchingBehavior=Switchable>
class CommonParameter : public Parameter, protected SwitchingBehavior {
public:
/** Test whether the parameter has been set */
virtual bool isSet() const;
CommonParameter(char shortOption, const char *longOption,
const char* description);
virtual ~CommonParameter();
virtual std::string usageLine() const;
protected:
/** Parse the argument given by state, and dispatch either
* receiveSwitch() or receiveArgument() accordingly.
*
* @param state The current argument being parsed.
* @return The number of parameters taken from the input
*/
virtual int receive(ParserState& state) throw(ParameterRejected) = 0;
};
/** This class (used as a mixin) defines how a parameter
* behaves when switched on, specifically when switched on multiple times.
*
*/
class Switchable {
public:
class SwitchingError : public Parameter::ParameterRejected {};
/** Test whether the parameter has been set */
virtual bool isSet() const;
/** Set the parameter
*
*/
virtual void set() throw (SwitchingError) = 0;
virtual ~Switchable();
Switchable();
protected:
bool fset;
};
/** Switching behavior that does not complain when set multiple times. */
class MultiSwitchable : public Switchable {
public:
virtual ~MultiSwitchable();
virtual void set() throw(SwitchingError);
};
/** Switching behavior that allows switching only once.
*
* This is typically what you want if your parameter has an argument.
*
*/
class UniquelySwitchable : public Switchable {
public:
virtual ~UniquelySwitchable();
/** Set the parameter
*
* @throw SwitchingError Thrown if the parameter is already set.
*/
virtual void set() throw (SwitchingError);
};
/** Switching behavior that makes possible allows presettable parameters,
* that is, it can either be set by the program, or by a command line argument,
* and the command-line part is UniquelySwitchable, but the program part
* is MultiSwitchable (and is set by preset())
*
*
*/
class PresettableUniquelySwitchable : public UniquelySwitchable {
public:
/** Test whether the parameter has been set OR preset */
virtual bool isSet() const;
/** Call if the parameter has been set.
*
* @throw SwitchingError thrown if the parameter is already set
* (doesn't care if it's been pre-set)
*/
virtual void set() throw (Switchable::SwitchingError);
/** Call if the parameter has been preset */
virtual void preset();
virtual ~PresettableUniquelySwitchable();
private:
MultiSwitchable fpreset;
};
/* Parameter that does not take an argument, and throws an exception
* if an argument is given */
template<typename SwitchingBehavior=MultiSwitchable>
class SwitchParameter : public CommonParameter<SwitchingBehavior> {
public:
SwitchParameter(char shortOption, const char *longOption,
const char* description);
virtual ~SwitchParameter();
protected:
virtual int receive(ParserState& state) throw(Parameter::ParameterRejected);
};
/** Plain-Old-Data parameter. Performs input validation.
*
* Currently only supports int, long and double, but extending
* it to other types (even non-POD) is as easy as partial template specialization.
*
* Specifically, you need to specialize validate().
*/
template<typename T, typename SwitchingBehavior=PresettableUniquelySwitchable>
class PODParameter : public CommonParameter<SwitchingBehavior> {
public:
PODParameter(char shortOption, const char *longOption,
const char* description);
virtual ~PODParameter();
/* Retreive the value of the argument. Throws an exception if
* the value hasn't been set (test with isSet())
*/
T getValue() const;
/** Type-casting operator, for convenience. */
operator T() const;
/** Set a default value for this parameter */
virtual void setDefault(T value);
std::string usageLine() const;
protected:
virtual int receive(ParserState& state) throw(Parameter::ParameterRejected);
/** Validation function for the data type.
*
* @throw ParameterRejected if the argument does not conform to this data type.
* @return the value corresponding to the argument.
*/
virtual T validate(const std::string& s) throw (Parameter::ParameterRejected);
T value;
};
typedef PODParameter<int> IntParameter;
typedef PODParameter<long> LongParameter;
typedef PODParameter<double> DoubleParameter;
typedef PODParameter<std::string> StringParameter;
#include "parameter.include.cc"
} //namespace
#endif

View File

@ -0,0 +1,177 @@
/* (C) 2011 Viktor Lofgren
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef GETOPTPP_H
/* This file contains template voodoo, and due to the unique way GCC handles
* templates, it needs to be included as a header (and it -is-). Do not attempt to
* compile this file directly!
*/
template<typename T>
T &ParameterSet::add(char shortName, const char* longName, const char* description) {
T* p = new T(shortName, longName, description);
parameters.push_back(p);
return *p;
}
/*
*
* Class CommonParameter implementation
*
*
*/
template<typename SwitchingBehavior>
CommonParameter<SwitchingBehavior>::~CommonParameter() {}
template<typename SwitchingBehavior>
CommonParameter<SwitchingBehavior>::CommonParameter(char shortOption, const char *longOption,
const char* description) : Parameter(shortOption, longOption, description) {}
template<typename SwitchingBehavior>
bool CommonParameter<SwitchingBehavior>::isSet() const{
return SwitchingBehavior::isSet();
}
template<typename SwitchingBehavior>
std::string CommonParameter<SwitchingBehavior>::usageLine() const {
std::stringstream strstr;
if (hasShortOption())
{
strstr << "-" << shortOption() << ", ";
}
else
{
strstr << " ";
}
strstr.width(20);
strstr << std::left << "--" + longOption();
return strstr.str();
}
/*
*
* Class SwitchParameter
*
*
*/
template<typename SwitchingBehavior>
SwitchParameter<SwitchingBehavior>::SwitchParameter(char shortOption, const char *longOption,
const char* description) : CommonParameter<SwitchingBehavior>(shortOption, longOption, description) {}
template<typename SwitchingBehavior>
SwitchParameter<SwitchingBehavior>::~SwitchParameter() {}
template<typename SwitchingBehavior>
int SwitchParameter<SwitchingBehavior>::receive(ParserState& state) throw(Parameter::ParameterRejected) {
const std::string arg = state.get();
if(arg.at(0) != '-') return false;
if ((arg.at(1) == '-' && arg.substr(2) == this->longOption()) ||
(this->hasShortOption() && arg.at(1) == this->shortOption() && arg.length() == 2))
{
this->set();
return 1;
}
return 0;
}
/*
* PODParameter stuff
*
*/
template<typename T, typename SwitchingBehavior>
PODParameter<T, SwitchingBehavior>::PODParameter(char shortOption, const char *longOption,
const char* description) : CommonParameter<PresettableUniquelySwitchable>(shortOption, longOption, description) {}
template<typename T, typename SwitchingBehavior>
PODParameter<T, SwitchingBehavior>::~PODParameter() {}
template<typename T, typename SwitchingBehavior>
PODParameter<T, SwitchingBehavior>::operator T() const { return getValue(); }
template<typename T, typename SwitchingBehavior>
void PODParameter<T, SwitchingBehavior>::setDefault(T value) {
PresettableUniquelySwitchable::preset();
this->value = value;
}
template<typename T, typename SwitchingBehavior>
T PODParameter<T, SwitchingBehavior>::getValue() const {
if(!this->isSet()) {
throw std::runtime_error(
std::string("Attempting to retreive the argument of parameter") + this->longOption() + " but it hasn't been set!");
}
return value;
}
template<typename T, typename SwitchingBehavior>
std::string PODParameter<T, SwitchingBehavior>::usageLine() const {
std::stringstream strstr;
if (this->hasShortOption())
{
strstr << "-" << this->shortOption() << ", ";
}
else
{
strstr << " ";
}
strstr.width(20);
strstr << std::left << "--" + this->longOption() + " <arg>";
return strstr.str();
}
template<typename T, typename SwitchingBehavior>
int PODParameter<T, SwitchingBehavior>::receive(ParserState& state) throw(Parameter::ParameterRejected) {
const std::string arg = state.get();
if(arg.at(0) != '-') return false;
if((arg.at(1) == '-' && arg.substr(2) == this->longOption()) ||
(this->hasShortOption() && arg.at(1) == this->shortOption() && arg.length() == 2))
{
// retrieve the argument
std::string arg1 = state.peek();
if (arg1.length() == 0)
{
throw Parameter::ExpectedArgument(arg + ": expected an argument");
return 1;
}
this->set();
value = this->validate(arg1);
return 2;
}
return 0;
}
#endif

View File

@ -2,10 +2,10 @@
add_executable(WriteConfig
WriteConfig.cpp)
add_executable(hyperion-d
add_executable(hyperiond
hyperion-d.cpp)
target_link_libraries(hyperion-d
target_link_libraries(hyperiond
hyperion)
# Find the libPNG
@ -22,3 +22,5 @@ if(PNG_FOUND)
hyperion
${PNG_LIBRARIES})
endif(PNG_FOUND)
add_subdirectory(hyperion-remote)

View File

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 2.8)
project(hyperion-remote)
find_package(Qt4 REQUIRED QtCore QtGui QtNetwork)
# The following I do not undrstand completely...
# libQtCore.so uses some hardcoded library path inside which are incorrect after copying the file RPi file system
# Therefor, an extra path is needed on which to find the required libraries
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
include_directories(${QT_INCLUDES})
set(hyperion-remote_HEADERS
CustomParameter.h
Connection.h
ColorTransformValues.h)
set(hyperion-remote_SOURCES
hyperion-remote.cpp
Connection.cpp)
add_executable(hyperion-remote
${hyperion-remote_HEADERS}
${hyperion-remote_SOURCES})
qt4_use_modules(hyperion-remote
Core
Gui
Network)
target_link_libraries(hyperion-remote
hyperion-utils
getoptPlusPlus)

View File

@ -0,0 +1,9 @@
#pragma once
/// Simple structure to contain the values of a color transformation
struct ColorTransformValues
{
double valueRed;
double valueGreen;
double valueBlue;
};

View File

@ -0,0 +1,186 @@
// stl includes
#include <stdexcept>
// hyperion-remote includes
#include "Connection.h"
Connection::Connection(const std::string & a, bool printJson) :
_printJson(printJson),
_socket()
{
QString address(a.c_str());
QStringList parts = address.split(":");
if (parts.size() != 2)
{
throw std::runtime_error(QString("Wrong address: unable to parse address (%1)").arg(address).toStdString());
}
bool ok;
uint16_t port = parts[1].toUShort(&ok);
if (!ok)
{
throw std::runtime_error(QString("Wrong address: Unable to parse the port number (%1)").arg(parts[1]).toStdString());
}
_socket.connectToHost(parts[0], port);
if (!_socket.waitForConnected())
{
throw std::runtime_error("Unable to connect to host");
}
std::cout << "Connected to " << a << std::endl;
}
Connection::~Connection()
{
_socket.close();
}
bool Connection::setColor(QColor color, int priority, int duration)
{
std::cout << "Set color to " << color.red() << " " << color.green() << " " << color.blue() << std::endl;
// create command
Json::Value command;
command["command"] = "color";
command["priority"] = priority;
Json::Value & rgbValue = command["color"];
rgbValue[0] = color.red();
rgbValue[1] = color.green();
rgbValue[2] = color.blue();
if (duration > 0)
{
command["duration"] = duration;
}
// send command message
Json::Value reply = sendMessage(command);
// parse reply message
return parseReply(reply);
}
bool Connection::setImage(QImage image, int priority, int duration)
{
std::cout << "Set image has size: " << image.width() << "x" << image.height() << std::endl;
// ensure the image has RGB888 format
image = image.convertToFormat(QImage::Format_RGB888);
QByteArray binaryImage;
binaryImage.reserve(image.width() * image.height() * 3);
for (int i = 0; i < image.height(); ++i)
{
binaryImage.append(reinterpret_cast<const char *>(image.constScanLine(i)), image.width() * 3);
}
const QByteArray base64Image = binaryImage.toBase64();
// create command
Json::Value command;
command["command"] = "image";
command["priority"] = priority;
command["width"] = image.width();
command["height"] = image.height();
command["data"] = std::string(base64Image.data(), base64Image.size());
if (duration > 0)
{
command["duration"] = duration;
}
// send command message
Json::Value reply = sendMessage(command);
// parse reply message
return parseReply(reply);
}
bool Connection::listPriorities()
{
std::cout << "List priority channels" << std::endl;
return false;
}
bool Connection::clear(int priority)
{
std::cout << "Clear priority channel " << priority << std::endl;
return false;
}
bool Connection::clearAll()
{
std::cout << "Clear all priority channels" << std::endl;
return false;
}
bool Connection::setTransform(ColorTransformValues *threshold, ColorTransformValues *gamma, ColorTransformValues *blacklevel, ColorTransformValues *whitelevel)
{
std::cout << "Set color transforms" << std::endl;
return false;
}
Json::Value Connection::sendMessage(const Json::Value & message)
{
// print command if requested
if (_printJson)
{
std::cout << "Command: " << message << std::endl;
}
// serialize message
Json::FastWriter jsonWriter;
std::string serializedMessage = jsonWriter.write(message);
// write message
_socket.write(serializedMessage.c_str());
if (!_socket.waitForBytesWritten())
{
throw std::runtime_error("Error while writing data to host");
}
// receive reply
if (!_socket.waitForReadyRead())
{
throw std::runtime_error("Error while reading data from host");
}
char data[1024 * 100];
uint64_t count = _socket.read(data, sizeof(data));
std::string serializedReply(data, count);
Json::Reader jsonReader;
Json::Value reply;
if (!jsonReader.parse(serializedReply, reply))
{
throw std::runtime_error("Error while parsing reply: invalid json");
}
// print reply if requested
if (_printJson)
{
std::cout << "Reply:" << reply << std::endl;
}
return reply;
}
bool Connection::parseReply(const Json::Value &reply)
{
bool success = false;
std::string reason = "No error info";
try
{
success = reply.get("success", false).asBool();
if (!success)
reason = reply.get("error", reason).asString();
}
catch (const std::runtime_error &)
{
// Some json paring error: ignore and set parsing error
}
if (!success)
{
throw std::runtime_error("Error while paring reply: " + reason);
}
return success;
}

View File

@ -0,0 +1,53 @@
#pragma once
// stl includes
#include <string>
// Qt includes
#include <QColor>
#include <QImage>
#include <QTcpSocket>
// jsoncpp includes
#include <json/json.h>
// hyperion-remote includes
#include "ColorTransformValues.h"
/// Connection class to setup an connection to the hyperion server and execute commands
class Connection
{
public:
Connection(const std::string & address, bool printJson);
~Connection();
/// Set all leds to the specified color
bool setColor(QColor color, int priority, int duration);
/// Set the leds according to the given image (assume the image is stretched to the display size)
bool setImage(QImage image, int priority, int duration);
/// Retrieve a list of all occupied priority channels
bool listPriorities();
/// Clear the given priority channel
bool clear(int priority);
/// Clear all priority channels
bool clearAll();
/// Set the color transform of the leds
/// Note that providing a NULL will leave the settings on the server unchanged
bool setTransform(ColorTransformValues * threshold, ColorTransformValues * gamma, ColorTransformValues * blacklevel, ColorTransformValues * whitelevel);
private:
/// Send a json command message and receive its reply
Json::Value sendMessage(const Json::Value & message);
bool parseReply(const Json::Value & reply);
private:
bool _printJson;
QTcpSocket _socket;
};

View File

@ -0,0 +1,102 @@
#pragma once
// Qt includes
#include <QColor>
#include <QImage>
// getoptPlusPLus includes
#include <getoptPlusPlus/getoptpp.h>
// hyperion-remote includes
#include "ColorTransformValues.h"
typedef vlofgren::PODParameter<QColor> ColorParameter;
typedef vlofgren::PODParameter<QImage> ImageParameter;
typedef vlofgren::PODParameter<ColorTransformValues> TransformParameter;
namespace vlofgren {
template<>
QColor ColorParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
{
// Check if we can create the color by name
QColor color(s.c_str());
if (color.isValid())
{
return color;
}
// check if we can create the color by hex RRGGBB value
if (s.length() == 6 && isxdigit(s[0]) && isxdigit(s[1]) && isxdigit(s[2]) && isxdigit(s[3]) && isxdigit(s[4]) && isxdigit(s[5]))
{
bool ok = true;
int rgb[3];
for (int i = 0; i < 3 && ok; ++i)
{
QString colorComponent(s.substr(2*i, 2).c_str());
rgb[i] = colorComponent.toInt(&ok, 16);
}
// check if all components parsed succesfully
if (ok)
{
color.setRgb(rgb[0], rgb[1], rgb[2]);
return color;
}
}
std::stringstream errorMessage;
errorMessage << "Invalid color. A color is specified by a six lettered RRGGBB hex value or one of the following names:";
foreach (const QString & colorname, QColor::colorNames()) {
errorMessage << "\n " << colorname.toStdString();
}
throw Parameter::ParameterRejected(errorMessage.str());
return color;
}
template<>
QImage ImageParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
{
QImage image(s.c_str());
if (image.isNull())
{
std::stringstream errorMessage;
errorMessage << "File " << s << " could not be opened as an image";
throw Parameter::ParameterRejected(errorMessage.str());
}
return image;
}
template<>
ColorTransformValues TransformParameter::validate(const std::string& s) throw (Parameter::ParameterRejected)
{
ColorTransformValues transform;
// s should be split in 3 parts
// seperators are either a ',' or a space
QStringList components = QString(s.c_str()).split(" ", QString::SkipEmptyParts);
if (components.size() == 3)
{
bool ok1, ok2, ok3;
transform.valueRed = components[0].toDouble(&ok1);
transform.valueGreen = components[1].toDouble(&ok2);
transform.valueBlue = components[2].toDouble(&ok3);
if (ok1 && ok2 && ok3)
{
return transform;
}
}
std::stringstream errorMessage;
errorMessage << "Argument " << s << " can not be parsed to 3 double values";
throw Parameter::ParameterRejected(errorMessage.str());
return transform;
}
}

View File

@ -0,0 +1,137 @@
// stl includes
#include <initializer_list>
// Qt includes
#include <QCoreApplication>
// getoptPlusPLus includes
#include <getoptPlusPlus/getoptpp.h>
// hyperion-remote include
#include "CustomParameter.h"
#include "Connection.h"
using namespace vlofgren;
/// Count the number of true values in a list of booleans
int count(std::initializer_list<bool> values)
{
int count = 0;
for (bool value : values) {
if (value)
count++;
}
return count;
}
int main(int argc, char * argv[])
{
QCoreApplication app(argc, argv);
try
{
// some default settings
QString defaultServerAddress = "localhost:19444";
int defaultPriority = 100;
// create the option parser and initialize all parameters
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
ParameterSet & parameters = optionParser.getParameters();
StringParameter & argAddress = parameters.add<StringParameter> ('a', "address" , QString("Set the address of the hyperion server [default: %1]").arg(defaultServerAddress).toAscii().constData());
IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority" , QString("Use to the provided priority channel (the lower the number, the higher the priority) [default: %1]").arg(defaultPriority).toAscii().constData());
IntParameter & argDuration = parameters.add<IntParameter> ('d', "duration" , "Specify how long the leds should be switched on in millseconds [default: infinity]");
ColorParameter & argColor = parameters.add<ColorParameter> ('c', "color" , "Set all leds to a constant color (either RRGGBB hex value or a color name)");
ImageParameter & argImage = parameters.add<ImageParameter> ('i', "image" , "Set the leds to the colors according to the given image file");
SwitchParameter<> & argList = parameters.add<SwitchParameter<> >('l', "list" , "List all priority channels which are in use");
SwitchParameter<> & argClear = parameters.add<SwitchParameter<> >('x', "clear" , "Clear data for the priority channel provided by the -p option");
SwitchParameter<> & argClearAll = parameters.add<SwitchParameter<> >(0x0, "clear-all" , "Clear data for all priority channels");
TransformParameter & argGamma = parameters.add<TransformParameter>('g', "gamma" , "Set the gamma of the leds (requires 3 values)");
TransformParameter & argThreshold = parameters.add<TransformParameter>('t', "threshold" , "Set the threshold of the leds (requires 3 space seperated values between 0.0 and 1.0)");
TransformParameter & argBlacklevel = parameters.add<TransformParameter>('b', "blacklevel", "Set the blacklevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)");
TransformParameter & argWhitelevel = parameters.add<TransformParameter>('w', "whitelevel", "Set the whitelevel of the leds (requires 3 space seperated values which are normally between 0.0 and 1.0)");
SwitchParameter<> & argPrint = parameters.add<SwitchParameter<> >(0x0, "print" , "Print the json input and output messages on stdout");
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<> >('h', "help" , "Show this help message and exit");
// set the default values
argAddress.setDefault(defaultServerAddress.toStdString());
argPriority.setDefault(defaultPriority);
argDuration.setDefault(-1);
// parse all options
optionParser.parse(argc, const_cast<const char **>(argv));
// check if we need to display the usage. exit if we do.
if (argHelp.isSet())
{
optionParser.usage();
return 0;
}
// check if at least one of the available color transforms is set
bool colorTransform = argThreshold.isSet() || argGamma.isSet() || argBlacklevel.isSet() || argWhitelevel.isSet();
// check that exactly one command was given
int commandCount = count({argColor.isSet(), argImage.isSet(), argList.isSet(), argClear.isSet(), argClearAll.isSet(), colorTransform});
if (commandCount != 1)
{
std::cerr << (commandCount == 0 ? "No command found." : "Multiple commands found.") << " Provide exactly one of the following options:" << std::endl;
std::cerr << " " << argColor.usageLine() << std::endl;
std::cerr << " " << argImage.usageLine() << std::endl;
std::cerr << " " << argList.usageLine() << std::endl;
std::cerr << " " << argClear.usageLine() << std::endl;
std::cerr << " " << argClearAll.usageLine() << std::endl;
std::cerr << "or one or more of the available color transformations:" << std::endl;
std::cerr << " " << argThreshold.usageLine() << std::endl;
std::cerr << " " << argGamma.usageLine() << std::endl;
std::cerr << " " << argBlacklevel.usageLine() << std::endl;
std::cerr << " " << argWhitelevel.usageLine() << std::endl;
return 1;
}
// create the connection to the hyperion server
Connection connection(argAddress.getValue(), argPrint.isSet());
// now execute the given command
if (argColor.isSet())
{
connection.setColor(argColor.getValue(), argPriority.getValue(), argDuration.getValue());
}
else if (argImage.isSet())
{
connection.setImage(argImage.getValue(), argPriority.getValue(), argDuration.getValue());
}
else if (argList.isSet())
{
connection.listPriorities();
}
else if (argClear.isSet())
{
connection.clear(argPriority.getValue());
}
else if (argClearAll.isSet())
{
connection.clearAll();
}
else if (colorTransform)
{
ColorTransformValues threshold = argThreshold.getValue();
ColorTransformValues gamma = argGamma.getValue();
ColorTransformValues blacklevel = argBlacklevel.getValue();
ColorTransformValues whitelevel = argWhitelevel.getValue();
connection.setTransform(
argThreshold.isSet() ? &threshold : nullptr,
argGamma.isSet() ? &gamma : nullptr,
argBlacklevel.isSet() ? &blacklevel : nullptr,
argWhitelevel.isSet() ? &whitelevel : nullptr);
}
}
catch (const std::runtime_error & e)
{
// An error occured. Display error and quit
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}