Commit a0023fa3 authored by Leander Schulten's avatar Leander Schulten
Browse files

Move to namespace and define interface for modules

parent 86f6d0d5
......@@ -100,6 +100,7 @@ HEADERS += \
programms/loopprogramm.h \
programms/dmxconsumer.h \
programms/consumer.h \
programms/module.h \
test/testloopprogramm.h
......
......@@ -3,14 +3,16 @@
#include "types.h"
class Consumer{
namespace Modules{
public:
virtual ValueType getInputValueType()=0;
virtual void setInputSize(unsigned int)=0;
virtual void start()=0;
virtual void show(void * data) = 0;
virtual ~Consumer() = default;
};
class Consumer{
public:
virtual ValueType getInputValueType()=0;
virtual void setInputSize(unsigned int)=0;
virtual void start()=0;
virtual void show(void * data) = 0;
virtual ~Consumer() = default;
};
}
#endif // COMSUMER_H
......@@ -4,7 +4,7 @@
#include "consumer.h"
#include <vector>
class DMXConsumer : public Consumer
class DMXConsumer : public Modules::Consumer
{
std::vector<short> channel;
public:
......
......@@ -3,13 +3,16 @@
#include "types.h"
class Filter : public PropertyBase{
public:
void setInputLength(int length);
int getOutputLength();
ValueType getInputType();
ValueType getOutputType();
void filter(void * inputData, void * outputData);
};
namespace Modules {
class Filter : public PropertyBase{
public:
void setInputLength(int length);
int getOutputLength();
ValueType getInputType();
ValueType getOutputType();
void filter(void * inputData, void * outputData);
};
}
#endif // FILTER_H
#ifndef MODULE_GLOBAL_H
#define MODULE_GLOBAL_H
// define one of the following if your module have the type
#define HAVE_PROGRAM
#define HAVE_LOOP_PROGRAMM
#define HAVE_FILTER
#define HAVE_CONSUMER
#ifdef HAVE_PROGRAM
#include "programm.h"
#endif
#ifdef HAVE_FILTER
#include "filter.h"
#endif
#ifdef HAVE_CONSUMER
#include "consumer.h"
#endif
#include <string>
#define MODULE_LIBRARY
#if defined(MODULE_LIBRARY)
# define MODULE_EXPORT __declspec(dllexport)
#else
# define MODULE_EXPORT __declspec(dllimport)
#endif
enum MODUL_TYPE{Programm, LoopProgramm,Filter,Consumer};
inline MODULE_EXPORT bool have(MODUL_TYPE t){
switch (t) {
case Programm:
#ifdef HAVE_PROGRAM
return true;
#else
return false;
#endif
case LoopProgramm:
#ifdef HAVE_LOOP_PROGRAMM
return true;
#else
return false;
#endif
case Filter:
#ifdef HAVE_FILTER
return true;
#else
return false;
#endif
case Consumer:
#ifdef HAVE_CONSUMER
return true;
#else
return false;
#endif
}
}
#ifdef HAVE_PROGRAM
MODULE_EXPORT unsigned int getNumberOfProgramms();
MODULE_EXPORT std::string getNameOfProgramm(unsigned int index);
MODULE_EXPORT Modules::Programm * createProgramm(unsigned int index);
MODULE_EXPORT std::string getDescriptionOfProgramm(unsigned int index);
#endif
#ifdef HAVE_FILTER
MODULE_EXPORT unsigned int getNumberOfFilter();
MODULE_EXPORT std::string getNameOfFilter(unsigned int index);
MODULE_EXPORT std::string getDescriptionOfFilter(unsigned int index);
MODULE_EXPORT Modules::Filter * createFilter(unsigned int index);
#endif
#ifdef HAVE_CONSUMER
MODULE_EXPORT unsigned int getNumberOfComsumer();
MODULE_EXPORT std::string getNameOfConsumer(unsigned int index);
MODULE_EXPORT std::string getDescriptionOfConsumer(unsigned int index);
MODULE_EXPORT Modules::Consumer * createConsumer(unsigned int index);
#endif
#endif // MODULES_GLOBAL_H
......@@ -4,83 +4,87 @@
#include <string>
#include <stdexcept>
union ValueUnion{
float floatValue;
int intValue;
ValueUnion(float f):floatValue(f){}
ValueUnion(int i):intValue(i){}
};
namespace Modules {
template<typename ValueType>
class TypedProperty;
union ValueUnion{
float floatValue;
int intValue;
ValueUnion(float f):floatValue(f){}
ValueUnion(int i):intValue(i){}
};
class Property
{
protected:
ValueUnion min;
ValueUnion max;
ValueUnion value;
private:
std::string name;
std::string description;
public:
const enum {Int, Float} Type;
Property(int min, int max, int value):min(min),max(max),value(value),Type(Int){}
Property(float min, float max, float value):min(min),max(max),value(value),Type(Float){}
template<typename ValueType>
class TypedProperty;
void setName( const std::string _name){
name = _name;
}
std::string getName() const {
return name;
}
class Property
{
protected:
ValueUnion min;
ValueUnion max;
ValueUnion value;
private:
std::string name;
std::string description;
public:
const enum {Int, Float} Type;
Property(int min, int max, int value):min(min),max(max),value(value),Type(Int){}
Property(float min, float max, float value):min(min),max(max),value(value),Type(Float){}
void setDescription( const std::string _description){
description = _description;
}
std::string getDescription() const {
return description;
}
void setName( const std::string _name){
name = _name;
}
std::string getName() const {
return name;
}
template<typename asType>
TypedProperty<asType> * as(){
if(std::is_same<asType,int>::value){
if(Type == Int){
return static_cast<TypedProperty<asType>*>(this);
}
}else if(std::is_same<asType,float>::value){
if(Type==Float){
return static_cast<TypedProperty<asType>*>(this);
void setDescription( const std::string _description){
description = _description;
}
std::string getDescription() const {
return description;
}
template<typename asType>
TypedProperty<asType> * as(){
if(std::is_same<asType,int>::value){
if(Type == Int){
return static_cast<TypedProperty<asType>*>(this);
}
}else if(std::is_same<asType,float>::value){
if(Type==Float){
return static_cast<TypedProperty<asType>*>(this);
}
}
throw std::runtime_error ("Bad Type.");
}
throw std::runtime_error ("Bad Type.");
}
};
};
template<typename ValueType>
class TypedProperty : public Property{
static_assert (std::is_same<ValueType,float>::value||std::is_same<ValueType,int>::value,"Wrong Type. Con be only int or float");
public:
void setValue( const ValueType _value){
value = std::min(getMax(),std::max(_value,getMin()));
}
ValueType getValue() const {
return value;
}
template<typename ValueType>
class TypedProperty : public Property{
static_assert (std::is_same<ValueType,float>::value||std::is_same<ValueType,int>::value,"Wrong Type. Con be only int or float");
public:
void setValue( const ValueType _value){
value = std::min(getMax(),std::max(_value,getMin()));
}
ValueType getValue() const {
return value;
}
void setMin( const ValueType _min){
min = _min;
}
ValueType getMin() const {
return min;
}
void setMin( const ValueType _min){
min = _min;
}
ValueType getMin() const {
return min;
}
void setMax( const ValueType _max){
max = _max;
}
ValueType getMax() const {
return max;
}
};
void setMax( const ValueType _max){
max = _max;
}
ValueType getMax() const {
return max;
}
};
}
#endif // VARIABLE_H
......@@ -4,33 +4,37 @@
#include "property.h"
#include <vector>
enum ValueType{Brightness, RGB};
namespace Modules {
typedef int time_diff_t;
typedef unsigned char brightness_t;
static_assert (sizeof (brightness_t)==1, "size of unsigned char is not 1");
enum ValueType{Brightness, RGB};
struct rgb_t{
union{
brightness_t r;
brightness_t red;
};
union{
brightness_t g;
brightness_t green;
};
union{
brightness_t b;
brightness_t blue;
typedef int time_diff_t;
typedef unsigned char brightness_t;
static_assert (sizeof (brightness_t)==1, "size of unsigned char is not 1");
struct rgb_t{
union{
brightness_t r;
brightness_t red;
};
union{
brightness_t g;
brightness_t green;
};
union{
brightness_t b;
brightness_t blue;
};
};
};
class PropertyBase{
protected:
std::vector<Property> properties;
public:
const std::vector<Property>& getProperties()const{return properties;}
};
class PropertyBase{
protected:
std::vector<Property> properties;
public:
const std::vector<Property>& getProperties()const{return properties;}
};
}
#endif // TYPES_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment