API
indiCompRule Struct Referenceabstract

Virtual base-class for all rules. More...

#include <indiCompRules.hpp>

Inheritance diagram for indiCompRule:
Inheritance graph
Collaboration diagram for indiCompRule:
Collaboration graph

Public Types

typedef std::variant< bool, std::string > boolorerr_t
 In-band error reporting type. More...
 

Public Member Functions

bool isError (boolorerr_t rv)
 Check if returned value indicates an error. More...
 
virtual ~indiCompRule ()
 Virtual destructor. More...
 
void priority (const rulePriority &p)
 Set priority of this rule. More...
 
const rulePrioritypriority ()
 Get the rule priority. More...
 
void message (const std::string &m)
 Set the message. More...
 
const std::string & message ()
 Get the message. More...
 
void comparison (const ruleComparison &c)
 Set the comparison for this rule. More...
 
const ruleComparisoncomparison ()
 Get the rule comparison. More...
 
virtual boolorerr_t valid ()=0
 Report whether the rule is valid as configured. More...
 
virtual bool value ()=0
 Get the value of this rule. More...
 
boolorerr_t compTxt (const std::string &str1, const std::string &str2)
 Compare two strings. More...
 
boolorerr_t compSw (const pcf::IndiElement::SwitchStateType &sw1, const pcf::IndiElement::SwitchStateType &sw2)
 Compare two switches. More...
 
boolorerr_t compNum (const double &num1, const double &num2, const double &tol)
 Compare two numbers. More...
 
boolorerr_t compBool (const bool &b1, const bool &b2)
 Compare two booleans. More...
 

Protected Attributes

rulePriority m_priority {rulePriority::none}
 The reporting priority for this rule. More...
 
std::string m_message
 The message used for notifications. More...
 
ruleComparison m_comparison {ruleComparison::Eq}
 The comparison for this rule. More...
 

Detailed Description

Virtual base-class for all rules.

Provides error handling and comparison functions. Derived classes must implemented valid() and value().

Definition at line 137 of file indiCompRules.hpp.

Member Typedef Documentation

◆ boolorerr_t

typedef std::variant<bool, std::string> indiCompRule::boolorerr_t

In-band error reporting type.

Definition at line 142 of file indiCompRules.hpp.

Constructor & Destructor Documentation

◆ ~indiCompRule()

virtual indiCompRule::~indiCompRule ( )
inlinevirtual

Virtual destructor.

Definition at line 164 of file indiCompRules.hpp.

Member Function Documentation

◆ comparison() [1/2]

const ruleComparison& indiCompRule::comparison ( )
inline

Get the rule comparison.

Returns
the current rule comparison

Definition at line 208 of file indiCompRules.hpp.

◆ comparison() [2/2]

void indiCompRule::comparison ( const ruleComparison c)
inline

Set the comparison for this rule.

Parameters
[in]cthe new comparison

Definition at line 198 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ compBool()

boolorerr_t indiCompRule::compBool ( const bool &  b1,
const bool &  b2 
)
inline

Compare two booleans.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]b1the first bool to compare
[in]b2the second bool to compare

Definition at line 331 of file indiCompRules.hpp.

Referenced by ruleCompRule::value().

◆ compNum()

boolorerr_t indiCompRule::compNum ( const double &  num1,
const double &  num2,
const double &  tol 
)
inline

Compare two numbers.

The comparison is (num1 comp num2), e.g. (num1 < num2). A tolerance is included for floating point equality.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]num1the first number to compare
[in]num2the second number to compare
[in]tolthe tolerance for the comparison

Definition at line 289 of file indiCompRules.hpp.

Referenced by numValRule::value(), and elCompNumRule::value().

◆ compSw()

boolorerr_t indiCompRule::compSw ( const pcf::IndiElement::SwitchStateType &  sw1,
const pcf::IndiElement::SwitchStateType &  sw2 
)
inline

Compare two switches.

Switch comparison can only be Eq or Neq.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]sw1the first switch to compare
[in]sw2the first switch to compare

Definition at line 260 of file indiCompRules.hpp.

Referenced by swValRule::value(), and elCompSwRule::value().

◆ compTxt()

boolorerr_t indiCompRule::compTxt ( const std::string &  str1,
const std::string &  str2 
)
inline

Compare two strings.

String comparison can only be Eq or Neq.

Returns
true if the comparison is true
false if the comparison is false
std::string with error message if the comparison is not valid
Parameters
[in]str1the first string to compare
[in]str2the second string to compare

Definition at line 232 of file indiCompRules.hpp.

Referenced by txtValRule::value(), and elCompTxtRule::value().

◆ isError()

bool indiCompRule::isError ( boolorerr_t  rv)
inline

Check if returned value indicates an error.

Parameters
[in]rvthe return value to check

Definition at line 145 of file indiCompRules.hpp.

Referenced by ruleCompRule::valid(), numValRule::value(), txtValRule::value(), swValRule::value(), elCompNumRule::value(), elCompTxtRule::value(), elCompSwRule::value(), and ruleCompRule::value().

◆ message() [1/2]

const std::string& indiCompRule::message ( )
inline

Get the message.

Returns
the current message

Definition at line 192 of file indiCompRules.hpp.

◆ message() [2/2]

void indiCompRule::message ( const std::string &  m)
inline

Set the message.

Parameters
[in]mthe new message

Definition at line 183 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ priority() [1/2]

const rulePriority& indiCompRule::priority ( )
inline

Get the rule priority.

Returns
the current rule priority

Definition at line 177 of file indiCompRules.hpp.

◆ priority() [2/2]

void indiCompRule::priority ( const rulePriority p)
inline

Set priority of this rule.

Parameters
[in]pthe new priority

Definition at line 168 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ valid()

virtual boolorerr_t indiCompRule::valid ( )
pure virtual

Report whether the rule is valid as configured.

If not valid, the return value is a std::string with the reason. If valid, the return value is a bool set to true.

Implemented in ruleCompRule, twoPropRule, and onePropRule.

Referenced by ruleCompRule::valid().

◆ value()

virtual bool indiCompRule::value ( )
pure virtual

Get the value of this rule.

Returns
the result of the comparison defined by the rule

Implemented in ruleCompRule, elCompSwRule, elCompTxtRule, elCompNumRule, swValRule, txtValRule, and numValRule.

Referenced by audibleAlerts.personality.Operation::__str__(), audibleAlerts.personality.Transition::compare(), and ruleCompRule::value().

Member Data Documentation

◆ m_comparison

ruleComparison indiCompRule::m_comparison {ruleComparison::Eq}
protected

The comparison for this rule.

Definition at line 159 of file indiCompRules.hpp.

Referenced by comparison(), compBool(), compNum(), compSw(), and compTxt().

◆ m_message

std::string indiCompRule::m_message
protected

The message used for notifications.

Definition at line 156 of file indiCompRules.hpp.

Referenced by message().

◆ m_priority

rulePriority indiCompRule::m_priority {rulePriority::none}
protected

The reporting priority for this rule.

Definition at line 153 of file indiCompRules.hpp.

Referenced by priority().


The documentation for this struct was generated from the following file: