https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Moose::Capability Class Reference

An entry for a single capability. More...

#include <Capability.h>

Public Types

using Value = std::variant< bool, int, std::string >
 A capability can have a bool, int, or string value.
 

Public Member Functions

 Capability ()=delete
 
 Capability (const std::string_view name, const Capability::Value &value, const std::string_view doc)
 
const std::string & getName () const
 
const std::string & getDoc () const
 
const Capability::ValuegetValue () const
 
bool getExplicit () const
 
const std::optional< std::set< std::string > > & queryEnumeration () const
 
const std::set< std::string > & getEnumeration () const
 
bool hasEnumeration (const std::string &value) const
 
CapabilitysetExplicit ()
 Set the capability to be explicit.
 
CapabilitysetEnumeration (const std::set< std::string > &enumeration)
 Set the enumeration (allowed values) for the capability.
 
void negateValue ()
 Negate a Capability value.
 
const bool * queryBoolValue () const
 
const intqueryIntValue () const
 
const std::string * queryStringValue () const
 
bool hasBoolValue () const
 
bool hasIntValue () const
 
bool hasStringValue () const
 
bool getBoolValue () const
 
int getIntValue () const
 
const std::string & getStringValue () const
 
std::string valueToString () const
 
std::string toString () const
 
std::string enumerationToString () const
 

Private Member Functions

 FRIEND_TEST (::CapabilityTest, negateValue)
 
 FRIEND_TEST (::CapabilitiesTest, isInstallationType)
 

Private Attributes

std::string _name
 The name of capability.
 
std::string _doc
 Description for the capability.
 
Capability::Value _value
 The value the capability is set to.
 
bool _explicit
 Whether or not this capability must be compared explicitly (not as a boolean check)
 
std::optional< std::set< std::string > > _enumeration
 Possible enumeration for the capability, if any (string capabilities only)
 

Detailed Description

An entry for a single capability.

Definition at line 29 of file Capability.h.

Member Typedef Documentation

◆ Value

using Moose::Capability::Value = std::variant<bool, int, std::string>

A capability can have a bool, int, or string value.

Definition at line 33 of file Capability.h.

Constructor & Destructor Documentation

◆ Capability() [1/2]

Moose::Capability::Capability ( )
delete

◆ Capability() [2/2]

Moose::Capability::Capability ( const std::string_view  name,
const Capability::Value value,
const std::string_view  doc 
)

Definition at line 19 of file Capability.C.

22 : _name(name), _doc(doc), _value(value), _explicit(false)
23{
24 // Check name validity
25 if (getName().empty())
26 throw CapabilityException("Capability has empty name");
27 if (!std::regex_match(getName(), std::regex("[a-z0-9_-]+")))
28 throw CapabilityException(
29 "Capability '" + getName() +
30 "': Name has unallowed characters; allowed characters = 'a-z, 0-9, _, -'");
31
32 // String value validity
33 if (const auto string_ptr = queryStringValue())
34 {
35 const std::regex string_regex("[a-z0-9_.-]+");
36 if (!std::regex_match(*string_ptr, string_regex))
37 throw CapabilityException(
38 "String capability '" + getName() + "': value '" + *string_ptr +
39 "' has unallowed characters; allowed characters = 'a-z, 0-9, _, ., -'");
40 }
41}
const std::string & getName() const
Definition Capability.h:43
std::string _name
The name of capability.
Definition Capability.h:185
std::string _doc
Description for the capability.
Definition Capability.h:187
bool _explicit
Whether or not this capability must be compared explicitly (not as a boolean check)
Definition Capability.h:192
Capability::Value _value
The value the capability is set to.
Definition Capability.h:189
const std::string * queryStringValue() const
Definition Capability.h:125

Member Function Documentation

◆ enumerationToString()

std::string Moose::Capability::enumerationToString ( ) const
Returns
The enumeration as a string of comma separated values.

This is only valid for a capability that has an enumeration.

Definition at line 150 of file Capability.C.

151{
152 if (_enumeration)
154 std::vector<std::string>(_enumeration->begin(), _enumeration->end()), ", ");
155 throw CapabilityException("Capability::enumerationToString(): Capability '",
156 getName(),
157 "' does not have an enumeration");
158}
std::optional< std::set< std::string > > _enumeration
Possible enumeration for the capability, if any (string capabilities only)
Definition Capability.h:194
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
Concatenates value into a single string separated by separator.

◆ FRIEND_TEST() [1/2]

Moose::Capability::FRIEND_TEST ( ::CapabilitiesTest  ,
isInstallationType   
)
private

◆ FRIEND_TEST() [2/2]

Moose::Capability::FRIEND_TEST ( ::CapabilityTest  ,
negateValue   
)
private

◆ getBoolValue()

bool Moose::Capability::getBoolValue ( ) const
Returns
The boolean capability value.

Will error if the value is not a boolean.

Definition at line 105 of file Capability.C.

106{
107 if (const auto bool_ptr = queryBoolValue())
108 return *bool_ptr;
109 throw CapabilityException("Capability::getBoolValue(): Capability " + toString() +
110 " is not a bool");
111}
std::string toString() const
Definition Capability.C:144
const bool * queryBoolValue() const
Definition Capability.h:117

◆ getDoc()

const std::string & Moose::Capability::getDoc ( ) const
inline
Returns
The documentation string.

Definition at line 48 of file Capability.h.

48{ return _doc; }

◆ getEnumeration()

const std::set< std::string > & Moose::Capability::getEnumeration ( ) const
Returns
The enumeration.

Will error if the capability does not have an enumeration.

Only string-valued capabilites can have an enumeration.

Definition at line 50 of file Capability.C.

51{
52 if (!_enumeration)
53 throw CapabilityException("Capability::getEnumeration(): Capability '" + getName() +
54 "' does not have an enumeration");
55 return *_enumeration;
56}

◆ getExplicit()

bool Moose::Capability::getExplicit ( ) const
inline
Returns
Whether or not the capability is explicit.

Explicit implies that the capability cannot be compared as a boolean.

Definition at line 60 of file Capability.h.

60{ return _explicit; }

◆ getIntValue()

int Moose::Capability::getIntValue ( ) const
Returns
The boolean capability value.

Will error if the value is not an integer.

Definition at line 114 of file Capability.C.

115{
116 if (const auto int_ptr = queryIntValue())
117 return *int_ptr;
118 throw CapabilityException("Capability::getIntValue(): Capability " + toString() +
119 " is not an integer");
120}
const int * queryIntValue() const
Definition Capability.h:121

◆ getName()

const std::string & Moose::Capability::getName ( ) const
inline
Returns
The name of the capability.

Definition at line 43 of file Capability.h.

43{ return _name; }

Referenced by Capability(), enumerationToString(), getEnumeration(), setEnumeration(), setExplicit(), and toString().

◆ getStringValue()

const std::string & Moose::Capability::getStringValue ( ) const
Returns
The string capability value.

Will error if the value is not a string.

Definition at line 123 of file Capability.C.

124{
125 if (const auto string_ptr = queryStringValue())
126 return *string_ptr;
127 throw CapabilityException("Capability::getStringValue(): Capability " + toString() +
128 " is not a string");
129}

◆ getValue()

const Capability::Value & Moose::Capability::getValue ( ) const
inline
Returns
The capability value.

Definition at line 53 of file Capability.h.

53{ return _value; }

◆ hasBoolValue()

bool Moose::Capability::hasBoolValue ( ) const
inline
Returns
Whether or not the capability value is a boolean.

Definition at line 130 of file Capability.h.

130{ return std::holds_alternative<bool>(_value); }

Referenced by setExplicit().

◆ hasEnumeration()

bool Moose::Capability::hasEnumeration ( const std::string &  value) const
Returns
Whether or not the capability has the given enumeration value.

This is only valid for string-valued capabilities.

If the capability has no enumerations, this will always return true.

Definition at line 44 of file Capability.C.

45{
46 return _enumeration ? _enumeration->count(value) : true;
47}

Referenced by setEnumeration().

◆ hasIntValue()

bool Moose::Capability::hasIntValue ( ) const
inline
Returns
Whether or not the capability value is an integer.

Definition at line 135 of file Capability.h.

135{ return std::holds_alternative<int>(_value); }

◆ hasStringValue()

bool Moose::Capability::hasStringValue ( ) const
inline
Returns
Whether or not the capability value is a string.

Definition at line 140 of file Capability.h.

140{ return std::holds_alternative<std::string>(_value); }

◆ negateValue()

void Moose::Capability::negateValue ( )
inline

Negate a Capability value.

This should only be used by pycapabilities via the TestHarness when it needs to augment capabilities to check on if a check depeneds on a capability or not.

Definition at line 199 of file Capability.h.

200{
201 _explicit = false;
202 _enumeration.reset();
203 _value = false;
204}

◆ queryBoolValue()

const bool * Moose::Capability::queryBoolValue ( ) const
inline
Returns
The boolean capability value if it is a boolean.

Definition at line 117 of file Capability.h.

117{ return std::get_if<bool>(&_value); }

Referenced by getBoolValue(), and valueToString().

◆ queryEnumeration()

const std::optional< std::set< std::string > > & Moose::Capability::queryEnumeration ( ) const
inline
Returns
The enumeration, if set.

Only string-valued capabilites can have an enumeration.

Definition at line 67 of file Capability.h.

67{ return _enumeration; }

◆ queryIntValue()

const int * Moose::Capability::queryIntValue ( ) const
inline
Returns
The integer capability value if it is an integer.

Definition at line 121 of file Capability.h.

121{ return std::get_if<int>(&_value); }

Referenced by getIntValue(), and valueToString().

◆ queryStringValue()

const std::string * Moose::Capability::queryStringValue ( ) const
inline
Returns
The string capability value if it is a string.

Definition at line 125 of file Capability.h.

125{ return std::get_if<std::string>(&_value); }

Referenced by Capability(), getStringValue(), setEnumeration(), and valueToString().

◆ setEnumeration()

Capability & Moose::Capability::setEnumeration ( const std::set< std::string > &  enumeration)

Set the enumeration (allowed values) for the capability.

This is only valid for string-valued capabilities.

Definition at line 69 of file Capability.C.

70{
71 static const std::string error_prefix = "Capability::setEnumeration(): ";
72
73 const auto string_ptr = queryStringValue();
74 if (!string_ptr)
75 throw CapabilityException(error_prefix + "Capability '" + getName() +
76 "' is not string-valued and cannot have an enumeration");
77
78 if (_enumeration)
79 {
80 if (*_enumeration == enumeration)
81 return *this;
82 throw CapabilityException(error_prefix + "Capability '" + getName() +
83 "' already has an enumeration set");
84 }
85
86 if (enumeration.empty())
87 throw CapabilityException(error_prefix + "Enumeration is empty for '" + getName() + "'");
88
89 for (const auto & value : enumeration)
90 if (!std::regex_match(value, std::regex("[a-z0-9_-]+")))
91 throw CapabilityException(error_prefix + "Enumeration value '" + value +
92 "' for capability '" + getName() + "'" +
93 " has unallowed characters; allowed characters = 'a-z, 0-9, _, -'");
94
95 _enumeration = enumeration;
96
97 if (!hasEnumeration(*string_ptr))
98 throw CapabilityException(error_prefix + "Capability " + toString() +
99 " value not within enumeration");
100
101 return *this;
102}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
bool hasEnumeration(const std::string &value) const
Definition Capability.C:44
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ setExplicit()

Capability & Moose::Capability::setExplicit ( )

Set the capability to be explicit.

Explicit implies that the capability cannot be compared as a boolean.

This is only valid for non-bool valued capabilities.

Definition at line 59 of file Capability.C.

60{
61 if (hasBoolValue())
62 throw CapabilityException("Capability::setExplicit(): Capability '" + getName() +
63 "' is bool-valued and cannot be set as explicit");
64 _explicit = true;
65 return *this;
66}
bool hasBoolValue() const
Definition Capability.h:130

◆ toString()

std::string Moose::Capability::toString ( ) const
Returns
The capability as a string in the form of "name=value".

Definition at line 144 of file Capability.C.

145{
146 return getName() + "=" + valueToString();
147}
std::string valueToString() const
Definition Capability.C:132

Referenced by getBoolValue(), getIntValue(), getStringValue(), and setEnumeration().

◆ valueToString()

std::string Moose::Capability::valueToString ( ) const
Returns
The capability value as a string.

Definition at line 132 of file Capability.C.

133{
134 if (const auto bool_ptr = queryBoolValue())
135 return *bool_ptr ? "true" : "false";
136 if (const auto string_ptr = queryStringValue())
137 return *string_ptr;
138 if (const auto int_ptr = queryIntValue())
139 return std::to_string(*int_ptr);
140 throw CapabilityException("Capability::valueToString(): Invalid type");
141}

Referenced by toString().

Member Data Documentation

◆ _doc

std::string Moose::Capability::_doc
private

Description for the capability.

Definition at line 187 of file Capability.h.

Referenced by getDoc().

◆ _enumeration

std::optional<std::set<std::string> > Moose::Capability::_enumeration
private

Possible enumeration for the capability, if any (string capabilities only)

Definition at line 194 of file Capability.h.

Referenced by enumerationToString(), getEnumeration(), hasEnumeration(), negateValue(), queryEnumeration(), and setEnumeration().

◆ _explicit

bool Moose::Capability::_explicit
private

Whether or not this capability must be compared explicitly (not as a boolean check)

Definition at line 192 of file Capability.h.

Referenced by getExplicit(), negateValue(), and setExplicit().

◆ _name

std::string Moose::Capability::_name
private

The name of capability.

Definition at line 185 of file Capability.h.

Referenced by getName().

◆ _value

Capability::Value Moose::Capability::_value
private

The value the capability is set to.

Definition at line 189 of file Capability.h.

Referenced by getValue(), hasBoolValue(), hasIntValue(), hasStringValue(), negateValue(), queryBoolValue(), queryIntValue(), and queryStringValue().


The documentation for this class was generated from the following files: