API
elCompNumRule Struct Reference

Compare two elements based on their numeric values. More...

#include <indiCompRules.hpp>

Inheritance diagram for elCompNumRule:
Inheritance graph
Collaboration diagram for elCompNumRule:
Collaboration graph

Public Types

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

Public Member Functions

 elCompNumRule ()
 Default c'tor. More...
 
void tol (const double &t)
 Set the tolerance. More...
 
const double & tol ()
 Get the tolerance. More...
 
virtual bool value ()
 Get the value of this rule. More...
 
void property1 (pcf::IndiProperty *property)
 Set the first property pointer. More...
 
const pcf::IndiProperty * property1 ()
 Get the first property pointer. More...
 
void element1 (const std::string &el)
 Set the first element name. More...
 
const std::string & element1 ()
 Get the first element name. More...
 
void property2 (pcf::IndiProperty *property)
 Set the second property pointer. More...
 
const pcf::IndiProperty * property2 ()
 Get the second property pointer. More...
 
void element2 (const std::string &el)
 Set the second element name. More...
 
const std::string & element2 ()
 Get the second element name. More...
 
virtual boolorerr_t valid ()
 Check if this rule is valid. More...
 
bool isError (boolorerr_t rv)
 Check if returned value indicates an error. 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...
 
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...
 

Static Public Attributes

static constexpr char name [] = "elCompNum"
 Name of this rule, used by config system. More...
 

Protected Attributes

double m_tol {1e-6}
 The tolerance for the comparison. More...
 
int m_type
 The property type, from pcf::IndiProperty::Type. More...
 
pcf::IndiProperty * m_property1 {nullptr}
 Pointer to the first property. More...
 
std::string m_element1
 The element name within the first property. More...
 
pcf::IndiProperty * m_property2 {nullptr}
 Pointer to the second property. More...
 
std::string m_element2
 The element name within the second property. More...
 
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

Compare two elements based on their numeric values.

Definition at line 848 of file indiCompRules.hpp.

Member Typedef Documentation

◆ boolorerr_t

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

In-band error reporting type.

Definition at line 142 of file indiCompRules.hpp.

Constructor & Destructor Documentation

◆ elCompNumRule()

elCompNumRule::elCompNumRule ( )
inline

Default c'tor.

Definition at line 862 of file indiCompRules.hpp.

Member Function Documentation

◆ comparison() [1/2]

const ruleComparison& indiCompRule::comparison ( )
inlineinherited

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)
inlineinherited

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 
)
inlineinherited

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 
)
inlineinherited

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 value().

◆ compSw()

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

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 
)
inlineinherited

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().

◆ element1() [1/2]

const std::string& twoPropRule::element1 ( )
inlineinherited

Get the first element name.

Returns
the current value of m_element1

Definition at line 521 of file indiCompRules.hpp.

◆ element1() [2/2]

void twoPropRule::element1 ( const std::string &  el)
inlineinherited

Set the first element name.

Parameters
[in]elthe new element name

Definition at line 512 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ element2() [1/2]

const std::string& twoPropRule::element2 ( )
inlineinherited

Get the second element name.

Returns
the current value of m_element2

Definition at line 565 of file indiCompRules.hpp.

◆ element2() [2/2]

void twoPropRule::element2 ( const std::string &  el)
inlineinherited

Set the second element name.

Parameters
[in]elthe new element name

Definition at line 556 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ isError()

bool indiCompRule::isError ( boolorerr_t  rv)
inlineinherited

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(), value(), elCompTxtRule::value(), elCompSwRule::value(), and ruleCompRule::value().

◆ message() [1/2]

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

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)
inlineinherited

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 ( )
inlineinherited

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)
inlineinherited

Set priority of this rule.

Parameters
[in]pthe new priority

Definition at line 168 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ property1() [1/2]

const pcf::IndiProperty* twoPropRule::property1 ( )
inlineinherited

Get the first property pointer.

Returns
the current value of m_property1

Definition at line 506 of file indiCompRules.hpp.

◆ property1() [2/2]

void twoPropRule::property1 ( pcf::IndiProperty *  property)
inlineinherited

Set the first property pointer.

Exceptions
mx::err::invalidargif property is nullptr
mx::err::invalidconfigif the supplied property has the wrong type
Parameters
[in]propertythe new property pointer

Definition at line 487 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ property2() [1/2]

const pcf::IndiProperty* twoPropRule::property2 ( )
inlineinherited

Get the second property pointer.

Returns
the current value of m_property2

Definition at line 550 of file indiCompRules.hpp.

◆ property2() [2/2]

void twoPropRule::property2 ( pcf::IndiProperty *  property)
inlineinherited

Set the second property pointer.

Exceptions
mx::err::invalidargif property is nullptr
mx::err::invalidconfigif the supplied property has the wrong type
Parameters
[in]propertythe new property pointer

Definition at line 531 of file indiCompRules.hpp.

Referenced by loadRuleConfig().

◆ tol() [1/2]

const double& elCompNumRule::tol ( )
inline

Get the tolerance.

Returns
the current value of m_tol

Definition at line 885 of file indiCompRules.hpp.

◆ tol() [2/2]

void elCompNumRule::tol ( const double &  t)
inline

Set the tolerance.

This is used for equality comparison to allow for floating point precision and text conversions in INDI. Set to 0 for strict comparison.

Exceptions
mx::err:invalidargif the new value is negative
Parameters
[in]tthe new tolerance

Definition at line 871 of file indiCompRules.hpp.

◆ valid()

virtual boolorerr_t twoPropRule::valid ( )
inlinevirtualinherited

Check if this rule is valid.

The rule is valid if both property pointers are not null, and the elements are contained within their respective properties.

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

Implements indiCompRule.

Definition at line 577 of file indiCompRules.hpp.

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

◆ value()

virtual bool elCompNumRule::value ( )
inlinevirtual

Get the value of this rule.

First checks if the rule is currently valid. The performs the comparison and returns the result.

Returns
the value of the comparison, true or false
Exceptions
mx::err::invalidconfigif the rule is not currently valid
mx::err::invalidconfigon an error from the comparison

Implements indiCompRule.

Definition at line 899 of file indiCompRules.hpp.

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

Member Data Documentation

◆ m_comparison

ruleComparison indiCompRule::m_comparison {ruleComparison::Eq}
protectedinherited

◆ m_element1

std::string twoPropRule::m_element1
protectedinherited

The element name within the first property.

Definition at line 467 of file indiCompRules.hpp.

Referenced by twoPropRule::element1(), twoPropRule::valid(), value(), elCompTxtRule::value(), and elCompSwRule::value().

◆ m_element2

std::string twoPropRule::m_element2
protectedinherited

The element name within the second property.

Definition at line 471 of file indiCompRules.hpp.

Referenced by twoPropRule::element2(), twoPropRule::valid(), value(), elCompTxtRule::value(), and elCompSwRule::value().

◆ m_message

std::string indiCompRule::m_message
protectedinherited

The message used for notifications.

Definition at line 156 of file indiCompRules.hpp.

Referenced by indiCompRule::message().

◆ m_priority

rulePriority indiCompRule::m_priority {rulePriority::none}
protectedinherited

The reporting priority for this rule.

Definition at line 153 of file indiCompRules.hpp.

Referenced by indiCompRule::priority().

◆ m_property1

pcf::IndiProperty* twoPropRule::m_property1 {nullptr}
protectedinherited

Pointer to the first property.

Definition at line 465 of file indiCompRules.hpp.

Referenced by twoPropRule::property1(), twoPropRule::valid(), value(), elCompTxtRule::value(), and elCompSwRule::value().

◆ m_property2

pcf::IndiProperty* twoPropRule::m_property2 {nullptr}
protectedinherited

Pointer to the second property.

Definition at line 469 of file indiCompRules.hpp.

Referenced by twoPropRule::property2(), twoPropRule::valid(), value(), elCompTxtRule::value(), and elCompSwRule::value().

◆ m_tol

double elCompNumRule::m_tol {1e-6}
protected

The tolerance for the comparison.

Definition at line 857 of file indiCompRules.hpp.

Referenced by tol(), and value().

◆ m_type

int twoPropRule::m_type
protectedinherited

The property type, from pcf::IndiProperty::Type.

Definition at line 463 of file indiCompRules.hpp.

Referenced by twoPropRule::property1(), and twoPropRule::property2().

◆ name

constexpr char elCompNumRule::name[] = "elCompNum"
staticconstexpr

Name of this rule, used by config system.

Definition at line 854 of file indiCompRules.hpp.

Referenced by loadRuleConfig().


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