https://mooseframework.inl.gov
CapabilityUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "StreamArguments.h"
13 
14 #include <exception>
15 #include <variant>
16 #include <string>
17 #include <sstream>
18 #include <tuple>
19 #include <map>
20 
24 namespace CapabilityUtils
25 {
26 
27 class CapabilityException : public std::runtime_error
28 {
29 public:
30  CapabilityException(const CapabilityException &) = default;
31 
32  template <typename... Args>
33  static std::string stringify(Args &&... args)
34  {
35  std::ostringstream ss;
36  streamArguments(ss, args...);
37  return ss.str();
38  }
39 
40  template <typename... Args>
41  explicit CapabilityException(Args &&... args) : std::runtime_error(stringify(args...))
42  {
43  }
44 
45  ~CapabilityException() throw() {}
46 };
47 
65 {
68  UNKNOWN = 2,
72 };
73 
75 typedef std::variant<bool, int, std::string> Type;
77 typedef std::tuple<CheckState, std::string, std::string> Result;
79 typedef std::map<std::string, std::pair<Type, std::string>> Registry;
80 
108 Result check(std::string requirements, const Registry & capabilities);
109 
110 } // namespace CapabilityUtils
void streamArguments(StreamType &)
CheckState
Return state for check.
CapabilityException(const CapabilityException &)=default
std::tuple< CheckState, std::string, std::string > Result
Result from a capability check: the state, the reason, and the documentation.
std::map< std::string, std::pair< Type, std::string > > Registry
The registry that stores the registered capabilities.
std::variant< bool, int, std::string > Type
A capability can have a bool, int, or string value.
static std::string stringify(Args &&... args)
The registry is used as a global singleton to collect information on all available MooseObject and Ac...
Definition: Registry.h:161
Result check(std::string requirements, const Registry &capabilities)
Checks if a set of requirements is satisified by the given capability registry.
Shared code for the Capabilities Registry and the python bindings to the Capabilities system...