Files
data-collection-terminal/opcua-exporter/fault-simulation-algorithm/include/algorithm.hpp
2024-09-04 10:25:47 +08:00

34 lines
775 B
C++

//
// Created by fly on 2022/4/6.
//
#ifndef FAULT_SIMULATION_ALGORITHM_ALGORITHM_HPP
#define FAULT_SIMULATION_ALGORITHM_ALGORITHM_HPP
#include <nlohmann/json.hpp>
class algorithm {
public:
virtual void set_config(nlohmann::json const &config) = 0;
virtual nlohmann::json config() = 0;
virtual double eval(double value) = 0;
protected:
double jsonValue(nlohmann::json const &j, std::string const &key) {
if (j.contains(key)) {
if (j[key].is_string()) {
return std::atof(j[key].get<std::string>().c_str());
}
if (j[key].is_number()) {
return j[key].get<double>();
}
}
return std::nan("");
}
};
#endif //FAULT_SIMULATION_ALGORITHM_ALGORITHM_HPP