Build and compare a switch-name combination against a target switch vector. More...
#include <indiCompRules.hpp>


Public Types | |
| typedef std::variant< bool, std::string > | boolorerr_t |
| In-band error reporting type. | |
Public Member Functions | |
| multiSwitchComboRule () | |
| Default c'tor. | |
| virtual ruleComparison | defaultComparison () const |
| Get the default comparison for this rule type. | |
| void | ruleName (const std::string &ruleName) |
| Set the rule name used in diagnostics. | |
| const std::string & | ruleName () |
| Get the configured rule name. | |
| void | property (pcf::IndiProperty *property, const std::string &propertyKey) |
| Append one source switch property. | |
| const pcf::IndiProperty * | property (size_t n) |
| Get a source switch property by index. | |
| const std::string & | propertyKey (size_t n) |
| Get a source property key by index. | |
| size_t | numSwitches () |
| Get the number of configured source switch properties. | |
| void | format (const std::string &format) |
| Set the literal format string for the source switch names. | |
| const std::string & | format () |
| Get the literal format string. | |
| void | targetProperty (pcf::IndiProperty *property) |
| Set the target switch property. | |
| const pcf::IndiProperty * | targetProperty () |
| Get the target switch property. | |
| void | targetPropertyKey (const std::string &propertyKey) |
| Set the target property key used in diagnostics. | |
| const std::string & | targetPropertyKey () |
| Get the target property key used in diagnostics. | |
| virtual boolorerr_t | valid () |
| Check if this rule is valid as configured. | |
| virtual bool | value () |
| Get the value of this rule. | |
| virtual bool | popRuntimeDiagnostic (std::string &diagnostic) |
| Pop one pending runtime diagnostic, if any. | |
| bool | isError (boolorerr_t rv) |
| Check if returned value indicates an error. | |
| void | priority (const rulePriority &p, double delay=-1) |
| Set priority of this rule. | |
| const rulePriority & | priority () |
| Get the rule priority. | |
| void | message (const std::string &m) |
| Set the message. | |
| const std::string & | message (bool settime=false) |
| Get the message. | |
| const timespec & | lastMsg () |
| double | sinceLastMsg () |
| Get the time since the last message. | |
| bool | timeToSend () |
| Check if it's time to send a message. | |
| void | messageDelay (double md) |
| Set the message delay. | |
| double | messageDelay () |
| Get the message delay. | |
| void | messageCount (int mc) |
| Set the message count. | |
| int | messageCount () |
| Get the message count. | |
| int | incMessageCount () |
| Increment the message count. | |
| void | comparison (const ruleComparison &c) |
| Set the comparison for this rule. | |
| const ruleComparison & | comparison () |
| Get the rule comparison. | |
| boolorerr_t | compTxt (const std::string &str1, const std::string &str2) |
| Compare two strings. | |
| boolorerr_t | compSw (const pcf::IndiElement::SwitchStateType &sw1, const pcf::IndiElement::SwitchStateType &sw2) |
| Compare two switches. | |
| boolorerr_t | compNum (const double &num1, const double &num2, const double &tol) |
| Compare two numbers. | |
| boolorerr_t | compBool (const bool &b1, const bool &b2) |
| Compare two booleans. | |
Static Public Attributes | |
| static constexpr char | name [] = "multiSwitchCombo" |
| Name of this rule, used by config system. | |
| static constexpr double | default_info_msg_delay = 0 |
| static constexpr double | default_caution_msg_delay = 60 |
| static constexpr double | default_warning_msg_delay = 30 |
| static constexpr double | default_alert_msg_delay = 5 |
Protected Member Functions | |
| size_t | formatPlaceholders (bool &invalidBraces) const |
Count plain {} placeholders and reject any other brace usage. | |
| std::string | activeName (pcf::IndiProperty *property, const std::string &propertyKey, bool &multiOnLatched) |
| Resolve the active element name for a switch property. | |
| std::string | formatCombo (const std::vector< std::string > &values) const |
Apply literal {} substitution to build the comparison string. | |
Protected Attributes | |
| std::string | m_ruleName |
| The configuration-section name of this rule, used in diagnostics. | |
| std::vector< pcf::IndiProperty * > | m_properties |
| The source switch properties in format-substitution order. | |
| std::vector< std::string > | m_propertyKeys |
| The config keys for the source switch properties, used in diagnostics. | |
| std::vector< bool > | m_multiOn |
| Per-source latch state used to avoid repeated multi-On diagnostics. | |
| std::string | m_format |
| The literal format string used to combine source switch names. | |
| pcf::IndiProperty * | m_targetProperty { nullptr } |
| The target switch property whose active element name is compared. | |
| std::string | m_targetPropertyKey |
| The config key for the target property, used in diagnostics. | |
| bool | m_targetMultiOn { false } |
| Latch state used to avoid repeated target multi-On diagnostics. | |
| std::vector< std::string > | m_pendingDiagnostics |
| Runtime diagnostics that should be logged without failing evaluation. | |
| rulePriority | m_priority { rulePriority::none } |
| The reporting priority for this rule. | |
| std::string | m_message |
| The message used for notifications. | |
| timespec | m_lastMsg { 0, 0 } |
| Time the message was last sent. | |
| double | m_messageDelay { 0 } |
| Delay between sending messages. | |
| int | m_messageCount { 0 } |
| Number of times the message has been sent. | |
| ruleComparison | m_comparison { ruleComparison::Eq } |
| The comparison for this rule. | |
Build and compare a switch-name combination against a target switch vector.
This rule reads the currently active element name from each source switch property, combines those names with a literal {} placeholder format string, and compares the result against the currently active element name in a target switch property.
Definition at line 1307 of file indiCompRules.hpp.
|
inherited |
In-band error reporting type.
Definition at line 187 of file indiCompRules.hpp.
|
inline |
Default c'tor.
Changes the default comparison to Neq for mismatch detection.
Definition at line 1454 of file indiCompRules.hpp.
References indiCompRule::comparison(), and defaultComparison().
|
inlineprotected |
Resolve the active element name for a switch property.
| [in] | property | the property to inspect |
| [in] | propertyKey | the config key for diagnostics |
| multiOnLatched | [in/out] the multi-On diagnostic latch |
Definition at line 1374 of file indiCompRules.hpp.
References active, m_pendingDiagnostics, m_ruleName, propertyKey(), and ruleName().
Referenced by value().
|
inlineinherited |
Get the rule comparison.
Definition at line 387 of file indiCompRules.hpp.
References indiCompRule::m_comparison.
Referenced by multiSwitchComboRule(), and ruleCompRule::ruleCompRule().
|
inlineinherited |
Set the comparison for this rule.
| [in] | c | the new comparison |
Definition at line 377 of file indiCompRules.hpp.
References indiCompRule::m_comparison.
Referenced by libXWCTest::stateRuleEngineTest::SCENARIO(), SCENARIO(), SCENARIO(), SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().
|
inlineinherited |
Compare two booleans.
| [in] | b1 | the first bool to compare |
| [in] | b2 | the second bool to compare |
Definition at line 533 of file indiCompRules.hpp.
References And, Eq, Imply, indiCompRule::m_comparison, Nand, Neq, Nimply, Nor, and Or.
Referenced by ruleCompRule::value().
|
inlineinherited |
Compare two numbers.
The comparison is (num1 comp num2), e.g. (num1 < num2). A tolerance is included for floating point equality.
| [in] | num1 | the first number to compare |
| [in] | num2 | the second number to compare |
| [in] | tol | the tolerance for the comparison |
Definition at line 483 of file indiCompRules.hpp.
References Eq, Gt, GtEq, Lt, LtEq, indiCompRule::m_comparison, and Neq.
Referenced by numValRule::value(), timeDiffRule::value(), and elCompNumRule::value().
|
inlineinherited |
Compare two switches.
Switch comparison can only be Eq or Neq.
| [in] | sw1 | the first switch to compare |
| [in] | sw2 | the first switch to compare |
Definition at line 452 of file indiCompRules.hpp.
References Eq, indiCompRule::m_comparison, and Neq.
Referenced by swValRule::value(), and elCompSwRule::value().
|
inlineinherited |
Compare two strings.
String comparison can only be Eq or Neq.
| [in] | str1 | the first string to compare |
| [in] | str2 | the second string to compare |
Definition at line 422 of file indiCompRules.hpp.
References Eq, indiCompRule::m_comparison, and Neq.
Referenced by txtValRule::value(), elCompTxtRule::value(), and value().
|
inlinevirtual |
Get the default comparison for this rule type.
ruleComparison::Neq Reimplemented from indiCompRule.
Definition at line 1463 of file indiCompRules.hpp.
References Neq.
Referenced by multiSwitchComboRule().
|
inline |
Get the literal format string.
Definition at line 1550 of file indiCompRules.hpp.
References m_format.
Referenced by format().
|
inline |
Set the literal format string for the source switch names.
| [in] | format | the literal {} placeholder format string |
Definition at line 1541 of file indiCompRules.hpp.
References format(), and m_format.
Referenced by loadRuleConfig(), libXWCTest::stateRuleEngineTest::SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().
|
inlineprotected |
Apply literal {} substitution to build the comparison string.
| [in] | values | the source switch names in order |
Definition at line 1428 of file indiCompRules.hpp.
References m_format.
Referenced by value().
|
inlineprotected |
Count plain {} placeholders and reject any other brace usage.
| [out] | invalidBraces | true when unsupported brace syntax is present |
Definition at line 1343 of file indiCompRules.hpp.
References m_format.
Referenced by valid().
|
inlineinherited |
Increment the message count.
Definition at line 364 of file indiCompRules.hpp.
References indiCompRule::m_messageCount.
|
inlineinherited |
Check if returned value indicates an error.
| [in] | rv | the return value to check |
Definition at line 190 of file indiCompRules.hpp.
Referenced by loadRuleConfig(), ruleCompRule::valid(), numValRule::value(), txtValRule::value(), swValRule::value(), timeDiffRule::value(), elCompNumRule::value(), elCompTxtRule::value(), elCompSwRule::value(), value(), and ruleCompRule::value().
|
inlineinherited |
Definition at line 298 of file indiCompRules.hpp.
References indiCompRule::m_lastMsg.
|
inlineinherited |
Get the message.
Optionally sets the message time to now.
| settime | If true m_lastMsg is set to now |
Definition at line 285 of file indiCompRules.hpp.
References indiCompRule::m_lastMsg, and indiCompRule::m_message.
|
inlineinherited |
Set the message.
| [in] | m | the new message |
Definition at line 276 of file indiCompRules.hpp.
References indiCompRule::m_message.
Referenced by libXWCTest::stateRuleEngineTest::TEST_CASE().
|
inlineinherited |
Get the message count.
Definition at line 371 of file indiCompRules.hpp.
References indiCompRule::m_messageCount.
|
inlineinherited |
Set the message count.
| [in] | mc | the new message count |
Definition at line 358 of file indiCompRules.hpp.
References indiCompRule::m_messageCount.
Referenced by libXWCTest::stateRuleEngineTest::TEST_CASE().
|
inlineinherited |
Get the message delay.
Definition at line 352 of file indiCompRules.hpp.
References indiCompRule::m_messageDelay.
|
inlineinherited |
Set the message delay.
| [in] | md | the new message delay |
Definition at line 346 of file indiCompRules.hpp.
References indiCompRule::m_messageDelay.
|
inline |
Get the number of configured source switch properties.
Definition at line 1535 of file indiCompRules.hpp.
References m_properties.
Referenced by libXWCTest::stateRuleEngineTest::SCENARIO().
|
inlinevirtual |
Pop one pending runtime diagnostic, if any.
| [out] | diagnostic | the next pending diagnostic message |
Reimplemented from indiCompRule.
Definition at line 1704 of file indiCompRules.hpp.
References m_pendingDiagnostics.
Referenced by libXWCTest::stateRuleEngineTest::SCENARIO().
|
inlineinherited |
Get the rule priority.
Definition at line 270 of file indiCompRules.hpp.
References indiCompRule::m_priority.
|
inlineinherited |
Set priority of this rule.
Also sets the message delay, to default for priority if not set.
| [in] | p | the new priority |
| [in] | delay | [opt] the message delay, if < 0 the default is used |
Definition at line 234 of file indiCompRules.hpp.
References alert, caution, indiCompRule::default_alert_msg_delay, indiCompRule::default_caution_msg_delay, indiCompRule::default_info_msg_delay, indiCompRule::default_warning_msg_delay, info, indiCompRule::m_messageDelay, indiCompRule::m_priority, and warning.
Referenced by libXWCTest::stateRuleEngineTest::TEST_CASE().
|
inline |
Append one source switch property.
| [in] | property | the next source switch property |
| [in] | propertyKey | the config key for the source property |
Definition at line 1484 of file indiCompRules.hpp.
References m_multiOn, m_properties, m_propertyKeys, property(), and propertyKey().
Referenced by loadRuleConfig(), property(), libXWCTest::stateRuleEngineTest::SCENARIO(), libXWCTest::stateRuleEngineTest::SCENARIO(), and targetProperty().
|
inline |
Get a source switch property by index.
n | [in] | n | the zero-based source property index |
Definition at line 1507 of file indiCompRules.hpp.
References m_properties.
|
inline |
Get a source property key by index.
n | [in] | n | the zero-based source property index |
Definition at line 1521 of file indiCompRules.hpp.
References m_propertyKeys.
Referenced by activeName(), property(), libXWCTest::stateRuleEngineTest::SCENARIO(), and targetPropertyKey().
|
inline |
Get the configured rule name.
Definition at line 1478 of file indiCompRules.hpp.
References m_ruleName.
Referenced by activeName(), and ruleName().
|
inline |
Set the rule name used in diagnostics.
| [in] | ruleName | the config-section name of this rule |
Definition at line 1469 of file indiCompRules.hpp.
References m_ruleName, and ruleName().
Referenced by loadRuleConfig(), libXWCTest::stateRuleEngineTest::SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().
|
inlineinherited |
Get the time since the last message.
Definition at line 304 of file indiCompRules.hpp.
References indiCompRule::m_lastMsg.
Referenced by indiCompRule::timeToSend().
|
inline |
Get the target switch property.
Definition at line 1575 of file indiCompRules.hpp.
References m_targetProperty.
|
inline |
Set the target switch property.
| [in] | property | the target switch property |
Definition at line 1556 of file indiCompRules.hpp.
References m_targetProperty, and property().
Referenced by loadRuleConfig(), libXWCTest::stateRuleEngineTest::SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().
|
inline |
Get the target property key used in diagnostics.
Definition at line 1590 of file indiCompRules.hpp.
References m_targetPropertyKey.
|
inline |
Set the target property key used in diagnostics.
| [in] | propertyKey | the config key for the target property |
Definition at line 1581 of file indiCompRules.hpp.
References m_targetPropertyKey, and propertyKey().
Referenced by loadRuleConfig(), libXWCTest::stateRuleEngineTest::SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().
|
inlineinherited |
Check if it's time to send a message.
If the message delay is <= 0, this is based on message count (i.e. has it been sent). Otherwise it's based on the time since last sent
Definition at line 319 of file indiCompRules.hpp.
References indiCompRule::m_messageCount, indiCompRule::m_messageDelay, and indiCompRule::sinceLastMsg().
|
inlinevirtual |
Check if this rule is valid as configured.
Implements indiCompRule.
Definition at line 1596 of file indiCompRules.hpp.
References Eq, formatPlaceholders(), indiCompRule::m_comparison, m_multiOn, m_properties, m_propertyKeys, m_targetProperty, m_targetPropertyKey, and Neq.
Referenced by loadRuleConfig(), and value().
|
inlinevirtual |
Get the value of this rule.
First checks if the rule is currently valid. Then performs the combo-name comparison and returns the result.
| mx::err::invalidconfig | if the rule is not currently valid |
| mx::err::invalidconfig | on an error from the comparison |
Implements indiCompRule.
Definition at line 1671 of file indiCompRules.hpp.
References activeName(), indiCompRule::compTxt(), formatCombo(), indiCompRule::isError(), m_multiOn, m_properties, m_propertyKeys, m_targetMultiOn, m_targetProperty, m_targetPropertyKey, and valid().
Referenced by audibleAlerts.personality.Operation::__str__(), audibleAlerts.personality.Transition::compare(), libXWCTest::stateRuleEngineTest::SCENARIO(), and libXWCTest::stateRuleEngineTest::SCENARIO().
|
staticconstexprinherited |
Definition at line 198 of file indiCompRules.hpp.
Referenced by indiCompRule::priority().
|
staticconstexprinherited |
Definition at line 196 of file indiCompRules.hpp.
Referenced by indiCompRule::priority().
|
staticconstexprinherited |
Definition at line 195 of file indiCompRules.hpp.
Referenced by indiCompRule::priority().
|
staticconstexprinherited |
Definition at line 197 of file indiCompRules.hpp.
Referenced by indiCompRule::priority().
|
protectedinherited |
The comparison for this rule.
Definition at line 214 of file indiCompRules.hpp.
Referenced by indiCompRule::comparison(), indiCompRule::comparison(), indiCompRule::compBool(), indiCompRule::compNum(), indiCompRule::compSw(), indiCompRule::compTxt(), and valid().
|
protected |
The literal format string used to combine source switch names.
Definition at line 1328 of file indiCompRules.hpp.
Referenced by format(), format(), formatCombo(), and formatPlaceholders().
|
protectedinherited |
Time the message was last sent.
Definition at line 207 of file indiCompRules.hpp.
Referenced by indiCompRule::lastMsg(), indiCompRule::message(), and indiCompRule::sinceLastMsg().
|
protectedinherited |
The message used for notifications.
Definition at line 205 of file indiCompRules.hpp.
Referenced by indiCompRule::message(), and indiCompRule::message().
|
protectedinherited |
Number of times the message has been sent.
Definition at line 211 of file indiCompRules.hpp.
Referenced by indiCompRule::incMessageCount(), indiCompRule::messageCount(), indiCompRule::messageCount(), and indiCompRule::timeToSend().
|
protectedinherited |
Delay between sending messages.
Definition at line 209 of file indiCompRules.hpp.
Referenced by indiCompRule::messageDelay(), indiCompRule::messageDelay(), indiCompRule::priority(), and indiCompRule::timeToSend().
|
protected |
Per-source latch state used to avoid repeated multi-On diagnostics.
Definition at line 1325 of file indiCompRules.hpp.
Referenced by property(), valid(), and value().
|
protected |
Runtime diagnostics that should be logged without failing evaluation.
Definition at line 1340 of file indiCompRules.hpp.
Referenced by activeName(), and popRuntimeDiagnostic().
|
protectedinherited |
The reporting priority for this rule.
Definition at line 202 of file indiCompRules.hpp.
Referenced by indiCompRule::priority(), and indiCompRule::priority().
|
protected |
The source switch properties in format-substitution order.
Definition at line 1319 of file indiCompRules.hpp.
Referenced by numSwitches(), property(), property(), valid(), and value().
|
protected |
The config keys for the source switch properties, used in diagnostics.
Definition at line 1322 of file indiCompRules.hpp.
Referenced by property(), propertyKey(), valid(), and value().
|
protected |
The configuration-section name of this rule, used in diagnostics.
Definition at line 1316 of file indiCompRules.hpp.
Referenced by activeName(), ruleName(), and ruleName().
|
protected |
Latch state used to avoid repeated target multi-On diagnostics.
Definition at line 1337 of file indiCompRules.hpp.
Referenced by value().
|
protected |
The target switch property whose active element name is compared.
Definition at line 1331 of file indiCompRules.hpp.
Referenced by targetProperty(), targetProperty(), valid(), and value().
|
protected |
The config key for the target property, used in diagnostics.
Definition at line 1334 of file indiCompRules.hpp.
Referenced by targetPropertyKey(), targetPropertyKey(), valid(), and value().
|
staticconstexpr |
Name of this rule, used by config system.
Definition at line 1312 of file indiCompRules.hpp.
Referenced by loadRuleConfig().