#pragma once #include #include #include #include #include "Dataset.h" #include "DatasetEntryIF.h" // TODO: ifdef introspection stuff template class DatasetEntry : public Parameter, public DatasetEntryIF { protected: #ifdef FSFW_INTROSPECTION DatasetEntry(Dataset *owner, const char *name) : Parameter(owner, name) #else DatasetEntry(Dataset *owner) : Parameter(owner) #endif { allocated = owner->registerEntry(this); if (!allocated) { return; } storedValue = new T(); storedValid = new bool; } public: #ifdef FSFW_INTROSPECTION static DatasetEntry createDatasetEntry(Dataset *owner, const char *name) { return DatasetEntry(owner, name); } #else static DatasetEntry createDatasetEntry(Dataset *owner) { return DatasetEntry(owner); } #endif ~DatasetEntry() { if (allocated) { delete storedValue; delete storedValid; } } virtual void setValid(bool isValid) { valid = isValid; } virtual bool getValid() { return valid; } //T value; //TODO can this be private? protected: virtual void commit() { *storedValue = Parameter::value; *storedValid = valid; } virtual void read() { Parameter::value = *storedValue; valid = *storedValid; } virtual void connect(DatasetEntryIF *entry) { DatasetEntry *theOther = dynamic_cast *>(entry); if (theOther == nullptr) { // Configuration error return; } this->storedValue = theOther->storedValue; this->storedValid = theOther->storedValid; } virtual bool changed() { return ((Parameter::value != *storedValue) || (valid != *storedValid)); } private: T *storedValue; bool *storedValid; bool valid; bool allocated; }; #ifdef FSFW_INTROSPECTION #define createDatasetEntry(p1, p2) createDatasetEntry(p1, p2) #else #define createDatasetEntry(p1, p2) createDatasetEntry(p1) #endif