https://mooseframework.inl.gov
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Moose::Capabilities Class Reference

This singleton class holds a registry for capabilities supported by the current app. More...

#include <Capabilities.h>

Public Member Functions

virtual ~Capabilities ()
 
void add (const std::string &capability, CapabilityUtils::Type value, const std::string &doc)
 register a new capability More...
 
void add (const std::string &capability, const char *value, const char *doc)
 
std::string dump () const
 create a JSON dump of the capabilities registry More...
 
CapabilityUtils::Result check (const std::string &requested_capabilities) const
 check if the given required capabilities are fulfilled, returns a bool, a reason, and a verbose documentation More...
 
 Capabilities (Capabilities const &)=delete
 Don't allow creation through copy/move construction or assignment. More...
 
Capabilitiesoperator= (Capabilities const &)=delete
 
 Capabilities (Capabilities &&)=delete
 
Capabilitiesoperator= (Capabilities &&)=delete
 

Static Public Member Functions

static CapabilitiesgetCapabilityRegistry ()
 

Protected Attributes

std::map< std::string, std::pair< CapabilityUtils::Type, std::string > > _capability_registry
 Capability registry. More...
 

Private Member Functions

 Capabilities ()
 
 FRIEND_TEST (::CapabilitiesTest, boolTest)
 
 FRIEND_TEST (::CapabilitiesTest, intTest)
 
 FRIEND_TEST (::CapabilitiesTest, stringTest)
 
 FRIEND_TEST (::CapabilitiesTest, versionTest)
 
 FRIEND_TEST (::CapabilitiesTest, multipleTest)
 
 FRIEND_TEST (::CapabilitiesTest, parseFail)
 

Detailed Description

This singleton class holds a registry for capabilities supported by the current app.

A capability can refer to an optional library or optional functionality. Capabilities can either be registered as boolean values (present or not), an integer quantity (like the AD backing store size), a string (like the compiler used to build the executable), or a version number (numbers separated by dots, e.g. the petsc version).

Definition at line 35 of file Capabilities.h.

Constructor & Destructor Documentation

◆ ~Capabilities()

virtual Moose::Capabilities::~Capabilities ( )
inlinevirtual

Definition at line 38 of file Capabilities.h.

38 {}

◆ Capabilities() [1/3]

Moose::Capabilities::Capabilities ( Capabilities const &  )
delete

Don't allow creation through copy/move construction or assignment.

◆ Capabilities() [2/3]

Moose::Capabilities::Capabilities ( Capabilities &&  )
delete

◆ Capabilities() [3/3]

Moose::Capabilities::Capabilities ( )
inlineprivate

Definition at line 70 of file Capabilities.h.

Referenced by getCapabilityRegistry().

70 {}

Member Function Documentation

◆ add() [1/2]

void Moose::Capabilities::add ( const std::string &  capability,
CapabilityUtils::Type  value,
const std::string &  doc 
)

register a new capability

Definition at line 33 of file Capabilities.C.

Referenced by add(), MooseApp::addCapability(), and AppFactory::reg().

36 {
37  const auto capability = MooseUtils::toLower(raw_capability);
38  if (std::holds_alternative<std::string>(value))
39  value = MooseUtils::toLower(std::get<std::string>(value));
40 
41  auto it_pair = _capability_registry.lower_bound(capability);
42  if (it_pair == _capability_registry.end() || it_pair->first != capability ||
43  it_pair->second.first == value)
44  _capability_registry.emplace_hint(it_pair, capability, std::make_pair(value, doc));
45  else
46  mooseError("Capability '",
47  capability,
48  "' was already registered with a different value. ('",
49  Moose::stringify(it_pair->second.first),
50  "' instead of '",
51  Moose::stringify(value),
52  "')");
53 }
std::string toLower(const std::string &name)
Convert supplied string to lower case.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
std::map< std::string, std::pair< CapabilityUtils::Type, std::string > > _capability_registry
Capability registry.
Definition: Capabilities.h:66

◆ add() [2/2]

void Moose::Capabilities::add ( const std::string &  capability,
const char *  value,
const char *  doc 
)

Definition at line 56 of file Capabilities.C.

57 {
58  add(capability, std::string(value), std::string(doc));
59 }
void add(const std::string &capability, CapabilityUtils::Type value, const std::string &doc)
register a new capability
Definition: Capabilities.C:33

◆ check()

CapabilityUtils::Result Moose::Capabilities::check ( const std::string &  requested_capabilities) const

check if the given required capabilities are fulfilled, returns a bool, a reason, and a verbose documentation

Definition at line 82 of file Capabilities.C.

Referenced by MooseApp::setupOptions().

83 {
84  const auto result = CapabilityUtils::check(requested_capabilities, _capability_registry);
85  return result;
86 }
Result check(std::string requirements, const Registry &capabilities)
Checks if a set of requirements is satisified by the given capability registry.
std::map< std::string, std::pair< CapabilityUtils::Type, std::string > > _capability_registry
Capability registry.
Definition: Capabilities.h:66

◆ dump()

std::string Moose::Capabilities::dump ( ) const

create a JSON dump of the capabilities registry

Definition at line 62 of file Capabilities.C.

63 {
64  nlohmann::json root;
65  for (const auto & [capability, value_doc] : _capability_registry)
66  {
67  const auto & value = value_doc.first;
68  const auto & doc = value_doc.second;
69  if (std::holds_alternative<bool>(value))
70  root[capability] = {std::get<bool>(value), doc};
71  else if (std::holds_alternative<int>(value))
72  root[capability] = {std::get<int>(value), doc};
73  else if (std::holds_alternative<std::string>(value))
74  root[capability] = {std::get<std::string>(value), doc};
75  else
76  mooseError("Unknown type in capabilities registry");
77  }
78  return root.dump(2);
79 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::map< std::string, std::pair< CapabilityUtils::Type, std::string > > _capability_registry
Capability registry.
Definition: Capabilities.h:66

◆ FRIEND_TEST() [1/6]

Moose::Capabilities::FRIEND_TEST ( ::CapabilitiesTest  ,
boolTest   
)
private

◆ FRIEND_TEST() [2/6]

Moose::Capabilities::FRIEND_TEST ( ::CapabilitiesTest  ,
intTest   
)
private

◆ FRIEND_TEST() [3/6]

Moose::Capabilities::FRIEND_TEST ( ::CapabilitiesTest  ,
stringTest   
)
private

◆ FRIEND_TEST() [4/6]

Moose::Capabilities::FRIEND_TEST ( ::CapabilitiesTest  ,
versionTest   
)
private

◆ FRIEND_TEST() [5/6]

Moose::Capabilities::FRIEND_TEST ( ::CapabilitiesTest  ,
multipleTest   
)
private

◆ FRIEND_TEST() [6/6]

Moose::Capabilities::FRIEND_TEST ( ::CapabilitiesTest  ,
parseFail   
)
private

◆ getCapabilityRegistry()

Capabilities & Moose::Capabilities::getCapabilityRegistry ( )
static

Definition at line 22 of file Capabilities.C.

Referenced by MooseApp::addCapability(), AppFactory::reg(), and MooseApp::setupOptions().

23 {
24  // We need a naked new here (_not_ a smart pointer or object instance) due to what seems like a
25  // bug in clang's static object destruction when using dynamic library loading.
26  static Capabilities * capability_registry = nullptr;
27  if (!capability_registry)
28  capability_registry = new Capabilities();
29  return *capability_registry;
30 }

◆ operator=() [1/2]

Capabilities& Moose::Capabilities::operator= ( Capabilities const &  )
delete

◆ operator=() [2/2]

Capabilities& Moose::Capabilities::operator= ( Capabilities &&  )
delete

Member Data Documentation

◆ _capability_registry

std::map<std::string, std::pair<CapabilityUtils::Type, std::string> > Moose::Capabilities::_capability_registry
protected

Capability registry.

The capabilities registered here can be dumped using the –show-capabilities command line option. Capabilities are used by the test harness to conditionally enable/disable tests that rely on optional capabilities.

Definition at line 66 of file Capabilities.h.

Referenced by add(), check(), and dump().


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