Line data Source code
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 "CapabilityUtils.h" 13 : 14 : #ifdef MOOSE_UNIT_TEST 15 : // forward declare unit tests 16 : #include "gtest/gtest.h" 17 : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, boolTest); 18 : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, intTest); 19 : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, stringTest); 20 : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, versionTest); 21 : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, multipleTest); 22 : class GTEST_TEST_CLASS_NAME_(CapabilitiesTest, parseFail); 23 : #endif 24 : 25 : namespace Moose 26 : { 27 : 28 : /** 29 : * This singleton class holds a registry for capabilities supported by the current app. 30 : * A capability can refer to an optional library or optional functionality. Capabilities 31 : * can either be registered as boolean values (present or not), an integer quantity (like 32 : * the AD backing store size), a string (like the compiler used to build the executable), 33 : * or a version number (numbers separated by dots, e.g. the petsc version). 34 : */ 35 : class Capabilities 36 : { 37 : public: 38 6 : virtual ~Capabilities() {} 39 : 40 : static Capabilities & getCapabilityRegistry(); 41 : 42 : /// register a new capability 43 : void add(const std::string & capability, CapabilityUtils::Type value, const std::string & doc); 44 : void add(const std::string & capability, const char * value, const char * doc); 45 : 46 : /// create a JSON dump of the capabilities registry 47 : std::string dump() const; 48 : 49 : /// check if the given required capabilities are fulfilled, returns a bool, a reason, and a verbose documentation 50 : CapabilityUtils::Result check(const std::string & requested_capabilities) const; 51 : 52 : ///@{ Don't allow creation through copy/move construction or assignment 53 : Capabilities(Capabilities const &) = delete; 54 : Capabilities & operator=(Capabilities const &) = delete; 55 : 56 : Capabilities(Capabilities &&) = delete; 57 : Capabilities & operator=(Capabilities &&) = delete; 58 : ///@} 59 : 60 : protected: 61 : /** 62 : * Capability registry. The capabilities registered here can be dumped using the 63 : * --show-capabilities command line option. Capabilities are used by the test harness 64 : * to conditionally enable/disable tests that rely on optional capabilities. 65 : */ 66 : std::map<std::string, std::pair<CapabilityUtils::Type, std::string>> _capability_registry; 67 : 68 : private: 69 : // Private constructor for singleton pattern 70 51214 : Capabilities() {} 71 : 72 : #ifdef MOOSE_UNIT_TEST 73 : FRIEND_TEST(::CapabilitiesTest, boolTest); 74 : FRIEND_TEST(::CapabilitiesTest, intTest); 75 : FRIEND_TEST(::CapabilitiesTest, stringTest); 76 : FRIEND_TEST(::CapabilitiesTest, versionTest); 77 : FRIEND_TEST(::CapabilitiesTest, multipleTest); 78 : FRIEND_TEST(::CapabilitiesTest, parseFail); 79 : #endif 80 : }; 81 : 82 : } // namespace Moose