@@ -35,7 +35,7 @@ namespace variables {
3535class Rule_DictElement : public VariableDictElement { \
3636 public:
3737 explicit Rule_DictElement (const std::string &dictElement)
38- : VariableDictElement(std::string( " RULE " ) , dictElement) { }
38+ : VariableDictElement(m_rule , dictElement) { }
3939
4040 static void id (Transaction *t,
4141 RuleWithActions *rule,
@@ -49,13 +49,8 @@ class Rule_DictElement : public VariableDictElement { \
4949 if (!r || r->m_ruleId == 0 ) {
5050 return ;
5151 }
52- std::string *a = new std::string (std::to_string (r->m_ruleId ));
53- VariableValue *var = new VariableValue (&m_rule, &m_rule_id,
54- a
55- );
56- delete a;
57- var->addOrigin ();
58- l->push_back (var);
52+
53+ addVariableOrigin (m_rule_id, std::to_string (r->m_ruleId ), l);
5954 }
6055
6156
@@ -72,13 +67,7 @@ class Rule_DictElement : public VariableDictElement { \
7267 return ;
7368 }
7469
75- std::string *a = new std::string (r->m_rev );
76- VariableValue *var = new VariableValue (&m_rule, &m_rule_rev,
77- a
78- );
79- delete a;
80- var->addOrigin ();
81- l->push_back (var);
70+ addVariableOrigin (m_rule_rev, r->m_rev , l);
8271 }
8372
8473
@@ -92,13 +81,7 @@ class Rule_DictElement : public VariableDictElement { \
9281 }
9382
9483 if (r && r->hasSeverity ()) {
95- std::string *a = new std::string (std::to_string (r->severity ()));
96- VariableValue *var = new VariableValue (&m_rule, &m_rule_severity,
97- a
98- );
99- delete a;
100- var->addOrigin ();
101- l->push_back (var);
84+ addVariableOrigin (m_rule_severity, std::to_string (r->severity ()), l);
10285 }
10386 }
10487
@@ -113,13 +96,7 @@ class Rule_DictElement : public VariableDictElement { \
11396 }
11497
11598 if (r && r->hasLogData ()) {
116- std::string *a = new std::string (r->logData (t));
117- VariableValue *var = new VariableValue (&m_rule, &m_rule_logdata,
118- a
119- );
120- delete a;
121- var->addOrigin ();
122- l->push_back (var);
99+ addVariableOrigin (m_rule_logdata, r->logData (t), l);
123100 }
124101 }
125102
@@ -133,36 +110,30 @@ class Rule_DictElement : public VariableDictElement { \
133110 }
134111
135112 if (r && r->hasMsg ()) {
136- std::string *a = new std::string (r->msg (t));
137- VariableValue *var = new VariableValue (&m_rule, &m_rule_msg,
138- a
139- );
140- delete a;
141- var->addOrigin ();
142- l->push_back (var);
113+ addVariableOrigin (m_rule_msg, r->msg (t), l);
143114 }
144115 }
145116
146117 void evaluate (Transaction *t,
147118 RuleWithActions *rule,
148119 std::vector<const VariableValue *> *l) override {
149- if (m_dictElement == " id " ) {
120+ if (m_dictElement == m_rule_id ) {
150121 id (t, rule, l);
151122 return ;
152123 }
153- if (rule && m_dictElement == " rev " ) {
124+ if (rule && m_dictElement == m_rule_rev ) {
154125 rev (t, rule, l);
155126 return ;
156127 }
157- if (rule && m_dictElement == " severity " ) {
128+ if (rule && m_dictElement == m_rule_severity ) {
158129 severity (t, rule, l);
159130 return ;
160131 }
161- if (m_dictElement == " logdata " ) {
132+ if (m_dictElement == m_rule_logdata ) {
162133 logData (t, rule, l);
163134 return ;
164135 }
165- if (m_dictElement == " msg " ) {
136+ if (m_dictElement == m_rule_msg ) {
166137 msg (t, rule, l);
167138 return ;
168139 }
@@ -174,6 +145,18 @@ class Rule_DictElement : public VariableDictElement { \
174145 static const std::string m_rule_severity;
175146 static const std::string m_rule_logdata;
176147 static const std::string m_rule_msg;
148+
149+ private:
150+
151+ static inline void addVariableOrigin (const std::string &key,
152+ const std::string &value,
153+ std::vector<const VariableValue *> *l) {
154+ auto var = new VariableValue (&m_rule, &key,
155+ &value
156+ );
157+ var->addOrigin ();
158+ l->push_back (var);
159+ }
177160};
178161
179162
0 commit comments