10#include <unordered_map>
24std::vector<RuleConfig>
loadRules(
const std::string& file_path);
43 auto validRules =
decltype(rules){};
45 for (
const auto& cfg : rules) {
47 ruleMap[cfg.rule_id] = factory.create(cfg.type, cfg);
48 validRules.push_back(cfg);
49 }
catch (
const std::exception& e) {
50 std::cerr <<
"Error creating rule " << cfg.rule_id
51 <<
": " << e.what() << std::endl;
67 const std::unordered_map<std::string, std::shared_ptr<RuleStrategy>>&
72 static std::once_flag flag;
73 std::call_once(flag, []() {
75 factory.add(
"simple", [](
const RuleConfig& cfg) {
return std::make_unique<SimpleRule>(cfg); });
76 factory.add(
"correlation", [](
const RuleConfig& cfg) {
return std::make_unique<CorrelationRule>(cfg); });
77 factory.add(
"stateful", [](
const RuleConfig& cfg) {
return std::make_unique<StatefulRule>(cfg); });
78 factory.add(
"step_difference", [](
const RuleConfig& cfg) {
return std::make_unique<StepDifferenceRule>(cfg); });
82 std::unordered_map<std::string, std::shared_ptr<RuleStrategy>>
ruleMap;
EvaluationPipeline buildPipeline(const std::unordered_map< std::string, std::shared_ptr< RuleStrategy > > &ruleMap, const std::vector< RuleConfig > &configs)
Builds an evaluation pipeline by organizing and sorting rules.
Definition RuleOrdering.cpp:18
Defines the structure of the evaluation pipeline and the function to build it based on the provided r...
std::string Identifier
Definition RulesFactory.hpp:13
std::vector< RuleConfig > loadRules(const std::string &file_path)
Loads rule configurations from a JSON file.
Definition RulesFactory.cpp:11
std::function< std::unique_ptr< RuleStrategy >(const RuleConfig &)> Builder
Definition RulesFactory.hpp:14
Contains the implementation of the different rules.
A generic object factory.
Definition GenericFactory.hpp:42
static Factory & Instance()
Definition GenericFactory.hpp:133
Instantiates rule objects from a JSON config and assembles them into an EvaluationPipeline.
Definition RulesFactory.hpp:33
EvaluationPipeline pipeline
Definition RulesFactory.hpp:83
static void loadFactory()
Definition RulesFactory.hpp:71
const std::unordered_map< std::string, std::shared_ptr< RuleStrategy > > & getRuleMap() const
Returns the map of rule ID to its instantiated rule strategy.
Definition RulesFactory.hpp:68
std::unordered_map< std::string, std::shared_ptr< RuleStrategy > > ruleMap
Definition RulesFactory.hpp:82
EvaluationPipeline & getPipeline()
Returns the evaluation pipeline (primary rules per sensor plus correlation rules).
Definition RulesFactory.hpp:61
RulesFactory(const std::string &rules_path)
Builds the rule map and evaluation pipeline from a rules JSON file.
Definition RulesFactory.hpp:39
Holds the categorized and organized rules ready for execution.
Definition RuleOrdering.hpp:17
A configuration structure used to instantiate any type of RuleStrategy.
Definition Strategy.hpp:107