Storm 2.0.0.3
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
DdBackends.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <string_view>
5#include <type_traits>
6#include <utility>
7
8#include "storm/dd/DdType.h"
12
13namespace storm {
14namespace dd {
15
19template<DdType... Types>
20struct DdTypeList {
21 static constexpr std::size_t size = sizeof...(Types);
22 static constexpr DdType values[sizeof...(Types)] = {Types...};
24 static constexpr DdType first = values[0];
25
26 template<typename F>
27 static constexpr void forEach(F&& f) {
28 (f(std::integral_constant<DdType, Types>{}), ...);
29 }
30};
31
34
38inline std::string_view ddLibraryName(DdType type) {
39 std::string_view name = "unknown";
40 RegisteredDdTypes::forEach([&](auto tag) {
41 if (type == decltype(tag)::value) {
42 name = BackendTraits<decltype(tag)::value>::name;
43 }
44 });
45 return name;
46}
47
48namespace detail {
49
50template<typename F, DdType First, DdType... Rest>
52 if (type == First) {
53 return f(std::integral_constant<DdType, First>{});
54 }
55 if constexpr (sizeof...(Rest) > 0) {
56 return dispatchDdType(type, std::forward<F>(f), DdTypeList<Rest...>{});
57 } else {
58 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::UnexpectedException, "Unexpected DD type.");
59 }
60}
61
62template<typename ValueType, typename F, DdType First, DdType... Rest>
64 if constexpr (BackendTraits<First>::template supportsValueType<ValueType>) {
65 if (type == First) {
66 return f(std::integral_constant<DdType, First>{});
67 }
68 }
69 if constexpr (sizeof...(Rest) > 0) {
70 return dispatchDdTypeSupporting<ValueType>(type, std::forward<F>(f), DdTypeList<Rest...>{});
71 } else {
72 STORM_LOG_THROW_UNCONDITIONALLY(storm::exceptions::UnexpectedException,
73 "Unexpected combination of DD library '" << ddLibraryName(type) << "' and value type.");
74 }
75}
76
77} // namespace detail
78
84template<typename F>
85auto dispatchDdType(DdType type, F&& f) {
86 return detail::dispatchDdType(type, std::forward<F>(f), RegisteredDdTypes{});
87}
88
93template<typename ValueType, typename F>
95 return detail::dispatchDdTypeSupporting<ValueType>(type, std::forward<F>(f), RegisteredDdTypes{});
96}
97
98} // namespace dd
99} // namespace storm
#define STORM_LOG_THROW_UNCONDITIONALLY(exception, message)
Definition macros.h:48
auto dispatchDdType(DdType type, F &&f, DdTypeList< First, Rest... >)
Definition DdBackends.h:51
auto dispatchDdTypeSupporting(DdType type, F &&f, DdTypeList< First, Rest... >)
Definition DdBackends.h:63
DdTypeList< DdType::CUDD, DdType::Sylvan > RegisteredDdTypes
Register Dd types.
Definition DdBackends.h:33
auto dispatchDdType(DdType type, F &&f)
Translates the runtime value type to the compile-time constant.
Definition DdBackends.h:85
std::string_view ddLibraryName(DdType type)
The name of the given backend.
Definition DdBackends.h:38
auto dispatchDdTypeSupporting(DdType type, F &&f)
Like dispatchDdType, but only considers backends that support the ValueType.
Definition DdBackends.h:94
The contract of a DD backend.
Registry of DD backends.
Definition DdBackends.h:20
static constexpr void forEach(F &&f)
Definition DdBackends.h:27
static constexpr DdType values[sizeof...(Types)]
Definition DdBackends.h:22