Skip to content
Snippets Groups Projects
Unverified Commit 7bcc4a9f authored by Grigoris Pavlakis's avatar Grigoris Pavlakis
Browse files

Move template definitions in the header file to avoid link errors

parent 96afef6b
No related branches found
No related tags found
No related merge requests found
...@@ -59,29 +59,57 @@ typedef etl::bitset<NUM_OF_FLAGS> Flags; ...@@ -59,29 +59,57 @@ typedef etl::bitset<NUM_OF_FLAGS> Flags;
*/ */
class ParameterBase { class ParameterBase {
protected: protected:
uint8_t ptc; uint8_t ptc;
uint8_t pfc; uint8_t pfc;
uint8_t sizeInBytes; uint8_t sizeInBytes;
void* valuePtr; void* valuePtr;
Flags flags; Flags flags;
public: public:
uint8_t getPTC(); uint8_t getPTC();
void setFlags(const char* flags);
uint8_t getPFC(); void setFlags(const char* flags);
virtual String<MAX_STRING_LENGTH> getValueAsString() = 0;
template <typename ValueType> void setCurrentValue(ValueType newVal); uint8_t getPFC();
virtual String<MAX_STRING_LENGTH> getValueAsString() = 0;
template <typename ValueType>
void setCurrentValue(ValueType newVal) {
// set the value only if the parameter can be updated manually
if (flags[1]) {
*reinterpret_cast<ValueType*>(valuePtr) = newVal;
}
}
}; };
template <typename ValueType> template <typename ValueType>
class Parameter : public ParameterBase { class Parameter : public ParameterBase {
void(*ptr)(ValueType*); void (* ptr)(ValueType*);
ValueType currentValue; ValueType currentValue;
public: public:
Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue = 0, void(*newPtr) Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue = 0, void(* newPtr)(ValueType*) = nullptr) {
(ValueType*) = nullptr); ptc = newPtc;
String<MAX_STRING_LENGTH> getValueAsString() override; pfc = newPfc;
ptr = newPtr;
sizeInBytes = sizeof(initialValue);
valuePtr = static_cast<void*>(&currentValue);
// see Parameter.hpp for explanation on flags
// by default: no update priority, manual and automatic update available
if (ptr != nullptr) {
(*ptr)(&currentValue); // call the update function for the initial value
} else {
currentValue = initialValue;
}
}
String<MAX_STRING_LENGTH> getValueAsString() override {
String<MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(&currentValue), sizeInBytes);
return contents;
}
}; };
......
#include "Services/Parameter.hpp" #include "Services/Parameter.hpp"
template <typename ValueType>
Parameter<ValueType>::Parameter(uint8_t newPtc, uint8_t newPfc, ValueType initialValue, void (*
newPtr)(ValueType*)) {
ptc = newPtc;
pfc = newPfc;
ptr = newPtr;
sizeInBytes = sizeof(initialValue);
valuePtr = static_cast<void *>(&currentValue);
// see Parameter.hpp for explanation on flags
// by default: no update priority, manual and automatic update available
if (ptr != nullptr) {
(*ptr)(&currentValue); // call the update function for the initial value
} else {
currentValue = initialValue;
}
}
template <typename ValueType>
void ParameterBase::setCurrentValue(ValueType newVal) {
// set the value only if the parameter can be updated manually
if (flags[1]) {
*reinterpret_cast<ValueType>(valuePtr) = newVal;
}
}
template <typename ValueType>
String<MAX_STRING_LENGTH> Parameter<ValueType>::getValueAsString() {
String<MAX_STRING_LENGTH> contents(reinterpret_cast<uint8_t*>(&currentValue), sizeInBytes);
return contents;
}
uint8_t ParameterBase::getPTC() { uint8_t ParameterBase::getPTC() {
return ptc; return ptc;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment