#ifndef BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ #define BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ #include "fsfw/returnvalues/HasReturnvaluesIF.h" #include #include #include class NVMParameterBase { public: virtual~ NVMParameterBase() {} NVMParameterBase(std::string fullName); bool getJsonFileExists(); /** * Returns RETURN_OK on successfull read and HasFileSystemIF::FILE_DOES_NOT_EXIST if * file does not exist yet. * @return */ virtual ReturnValue_t readJsonFile(); virtual ReturnValue_t writeJsonFile(); void setFullName(std::string fullName); std::string getFullName() const; template ReturnValue_t insertValue(std::string key, T value); template ReturnValue_t setValue(std::string key, T value); template T getValue(std::string key) const; void printKeys() const; void print() const; private: nlohmann::json json; std::vector keys; std::string fullName; }; template inline ReturnValue_t NVMParameterBase::insertValue(std::string key, T value) { // Check whether key already exists. If it does not, insert it if (std::find(keys.begin(), keys.end(), key) == keys.end()) { keys.push_back(key); } json[key] = value; return HasReturnvaluesIF::RETURN_OK; } template inline ReturnValue_t NVMParameterBase::setValue(std::string key, T value) { json[key] = value; return HasReturnvaluesIF::RETURN_OK; } template inline T NVMParameterBase::getValue(std::string key) const { return json[key]; } #endif /* BSP_Q7S_CORE_NVMPARAMS_NVMPARAMIF_H_ */