2016-06-15 23:48:41 +02:00
|
|
|
#ifndef PARAMETERWRAPPER_H_
|
|
|
|
#define PARAMETERWRAPPER_H_
|
|
|
|
|
|
|
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
#include <framework/serialize/SerializeIF.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <framework/globalfunctions/Type.h>
|
|
|
|
|
|
|
|
class ParameterWrapper: public SerializeIF {
|
2018-07-12 16:29:32 +02:00
|
|
|
friend class DataPoolParameterWrapper;
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2018-07-12 16:29:32 +02:00
|
|
|
static const uint8_t INTERFACE_ID = CLASS_ID::PARAMETER_WRAPPER;
|
2016-06-15 23:48:41 +02:00
|
|
|
static const ReturnValue_t UNKNOW_DATATYPE = MAKE_RETURN_CODE(0x01);
|
|
|
|
static const ReturnValue_t DATATYPE_MISSMATCH = MAKE_RETURN_CODE(0x02);
|
|
|
|
static const ReturnValue_t READONLY = MAKE_RETURN_CODE(0x03);
|
|
|
|
static const ReturnValue_t TOO_BIG = MAKE_RETURN_CODE(0x04);
|
|
|
|
static const ReturnValue_t SOURCE_NOT_SET = MAKE_RETURN_CODE(0x05);
|
|
|
|
static const ReturnValue_t OUT_OF_BOUNDS = MAKE_RETURN_CODE(0x06);
|
|
|
|
static const ReturnValue_t NOT_SET = MAKE_RETURN_CODE(0x07);
|
|
|
|
|
|
|
|
ParameterWrapper();
|
|
|
|
ParameterWrapper(Type type, uint8_t rows, uint8_t columns, void *data);
|
|
|
|
ParameterWrapper(Type type, uint8_t rows, uint8_t columns,
|
|
|
|
const void *data);
|
|
|
|
virtual ~ParameterWrapper();
|
|
|
|
|
2020-04-05 17:58:39 +02:00
|
|
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
|
|
const size_t max_size, bool bigEndian) const;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-04-05 21:54:11 +02:00
|
|
|
virtual size_t getSerializedSize() const;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
|
|
|
bool bigEndian);
|
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
|
|
|
bool bigEndian, uint16_t startWritingAtIndex = 0);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
ReturnValue_t getElement(T *value, uint8_t row = 0, uint8_t column = 0) const {
|
|
|
|
if (readonlyData == NULL){
|
|
|
|
return NOT_SET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PodTypeConversion<T>::type != type) {
|
|
|
|
return DATATYPE_MISSMATCH;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
if ((row >= rows) || (column >= columns)) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return OUT_OF_BOUNDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pointsToStream) {
|
|
|
|
const uint8_t *streamWithtype = (const uint8_t *) readonlyData;
|
|
|
|
streamWithtype += (row * columns + column) * type.getSize();
|
|
|
|
int32_t size = type.getSize();
|
|
|
|
return SerializeAdapter<T>::deSerialize(value, &streamWithtype,
|
|
|
|
&size, true);
|
|
|
|
} else {
|
|
|
|
const T *dataWithType = (const T *) readonlyData;
|
|
|
|
*value = dataWithType[row * columns + column];
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void set(T *data, uint8_t rows, uint8_t columns) {
|
|
|
|
this->data = data;
|
|
|
|
this->readonlyData = data;
|
|
|
|
this->type = PodTypeConversion<T>::type;
|
|
|
|
this->rows = rows;
|
|
|
|
this->columns = columns;
|
|
|
|
this->pointsToStream = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void set(const T *readonlyData, uint8_t rows, uint8_t columns) {
|
|
|
|
this->data = NULL;
|
|
|
|
this->readonlyData = readonlyData;
|
|
|
|
this->type = PodTypeConversion<T>::type;
|
|
|
|
this->rows = rows;
|
|
|
|
this->columns = columns;
|
|
|
|
this->pointsToStream = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void set(T& member) {
|
|
|
|
this->set(&member, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void set(const T& readonlyMember) {
|
|
|
|
this->set(&readonlyMember, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void setVector(T& member) {
|
2018-07-12 16:29:32 +02:00
|
|
|
this->set(member, sizeof(member)/sizeof(member[0]), 1);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void setVector(const T& member) {
|
|
|
|
this->set(member, 1, sizeof(member)/sizeof(member[0]));
|
|
|
|
}
|
|
|
|
template<typename T>
|
|
|
|
void setMatrix(T& member) {
|
|
|
|
this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void setMatrix(const T& member) {
|
|
|
|
this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0]));
|
|
|
|
}
|
|
|
|
ReturnValue_t set(const uint8_t *stream, int32_t streamSize,
|
|
|
|
const uint8_t **remainingStream = NULL, int32_t *remainingSize =
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ReturnValue_t copyFrom(const ParameterWrapper *from,
|
|
|
|
uint16_t startWritingAtIndex);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool pointsToStream;
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
uint8_t rows;
|
|
|
|
uint8_t columns;
|
|
|
|
void *data;
|
|
|
|
const void *readonlyData;
|
|
|
|
|
|
|
|
template<typename T>
|
2020-04-05 17:58:39 +02:00
|
|
|
ReturnValue_t serializeData(uint8_t** buffer, size_t* size,
|
|
|
|
const size_t max_size, bool bigEndian) const;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
ReturnValue_t deSerializeData(uint8_t startingRow, uint8_t startingColumn,
|
|
|
|
const void *from, uint8_t fromRows, uint8_t fromColumns);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* PARAMETERWRAPPER_H_ */
|