Ulrich Mohr
753d587b69
Some checks failed
fsfw/fsfw/pipeline/head There was a failure building this commit
128 lines
2.8 KiB
C++
128 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "Dataset.h"
|
|
#include "DatasetEntryIF.h"
|
|
|
|
template <typename T>
|
|
class DatasetEntry : public DatasetEntryIF {
|
|
protected:
|
|
#ifdef FSFW_INTROSPECTION
|
|
DatasetEntry(Dataset* set, const char* name) : name(name) {
|
|
#else
|
|
DatasetEntry(Dataset* set) {
|
|
#endif
|
|
allocated = set->registerEntry(this);
|
|
if (!allocated) {
|
|
return;
|
|
}
|
|
storedValue = new T();
|
|
storedValid = new bool;
|
|
}
|
|
|
|
public:
|
|
|
|
#ifdef FSFW_INTROSPECTION
|
|
Types::ParameterType getType() override {
|
|
return enumHelper<std::is_base_of<EnumIF, T>::value>::template getType<T>();
|
|
}
|
|
#endif
|
|
|
|
|
|
#ifdef FSFW_INTROSPECTION
|
|
static DatasetEntry createEntry(Dataset* set, const char *name) {
|
|
return DatasetEntry(set, name);
|
|
}
|
|
#else
|
|
static DatasetEntry createEntry(Dataset* set) { return DatasetEntry(set); }
|
|
#endif
|
|
|
|
~DatasetEntry() {
|
|
if (allocated) {
|
|
delete storedValue;
|
|
delete storedValid;
|
|
}
|
|
}
|
|
|
|
operator T() {
|
|
return value;
|
|
}
|
|
|
|
DatasetEntry &operator=(T newValue){
|
|
value = newValue;
|
|
return *this;
|
|
}
|
|
|
|
void setValid(bool isValid) override { valid = isValid; }
|
|
|
|
bool getValid() override { return valid; }
|
|
|
|
// TODO this is generic with the action parameter
|
|
#ifdef FSFW_INTROSPECTION
|
|
double getFloating() override { return (double)value; }
|
|
int64_t getSigned() override { return (int64_t)value; }
|
|
|
|
bool setFloating(double value) override {
|
|
if (getType() != Types::FLOATING) {
|
|
return false;
|
|
}
|
|
this->value = value;
|
|
return true;
|
|
}
|
|
|
|
bool setSigned(int64_t value) override {
|
|
if ((getType() != Types::SIGNED) && (getType() != Types::ENUM)) {
|
|
return false;
|
|
}
|
|
this->value = value;
|
|
return true;
|
|
}
|
|
|
|
std::vector<int64_t> getEnumValues() override {
|
|
return enumHelper<std::is_base_of<EnumIF, T>::value>::getEnumValues(&value);
|
|
}
|
|
const char* const* getEnumDescriptions() override {
|
|
return enumHelper<std::is_base_of<EnumIF, T>::value>::getEnumDescriptions(&value);
|
|
}
|
|
|
|
const char* getName() override { return name; }
|
|
|
|
private:
|
|
const char* name;
|
|
#endif
|
|
|
|
protected:
|
|
void commit() override {
|
|
*storedValue = value;
|
|
*storedValid = valid;
|
|
}
|
|
|
|
void read() override {
|
|
value = *storedValue;
|
|
valid = *storedValid;
|
|
}
|
|
|
|
void connect(DatasetEntryIF* entry) override {
|
|
DatasetEntry<T>* theOther = dynamic_cast<DatasetEntry<T>*>(entry);
|
|
if (theOther == nullptr) {
|
|
// Configuration error
|
|
return;
|
|
}
|
|
this->storedValue = theOther->storedValue;
|
|
this->storedValid = theOther->storedValid;
|
|
}
|
|
|
|
bool changed() override { return ((value != *storedValue) || (valid != *storedValid)); }
|
|
|
|
private:
|
|
T value;
|
|
T* storedValue;
|
|
bool* storedValid;
|
|
bool valid;
|
|
bool allocated;
|
|
};
|
|
|
|
#ifdef FSFW_INTROSPECTION
|
|
#define createEntry(p1, p2) createEntry(p1, p2)
|
|
#else
|
|
#define createEntry(p1, p2) createEntry(p1)
|
|
#endif |