3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
propertysystem.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
26#ifndef DUMUX_PROPERTY_SYSTEM_HH
27#define DUMUX_PROPERTY_SYSTEM_HH
28
29#include <tuple>
30#include <type_traits>
31
32namespace Dumux::Properties {
33
36
37} // end namespace Dumux::Properties
38
41
43template<class P>
44constexpr auto isDefinedProperty(int)
45-> decltype(std::integral_constant<bool, !std::is_same_v<typename P::type, UndefinedProperty>>{})
46{ return {}; }
47
49template<class P>
50constexpr std::true_type isDefinedProperty(...) { return {}; }
51
53template<class T>
54constexpr auto hasParentTypeTag(int)
55-> decltype(std::declval<typename T::InheritsFrom>(), std::true_type{})
56{ return {}; }
57
59template<class T>
60constexpr std::false_type hasParentTypeTag(...)
61{ return {}; }
62
64template<class ...Tuples>
65using ConCatTuples = decltype(std::tuple_cat(std::declval<Tuples>()...));
66
68template<class TypeTag, template<class,class> class Property, class TTagList>
70
72template<class TypeTag, template<class,class> class Property, class TTagList, class Enable>
74
75template<class TypeTag, template<class,class> class Property, class LastTypeTag>
76struct GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, std::enable_if_t<hasParentTypeTag<LastTypeTag>(int{}), void>>
78
79template<class TypeTag, template<class,class> class Property, class LastTypeTag>
80struct GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, std::enable_if_t<!hasParentTypeTag<LastTypeTag>(int{}), void>>
82
83template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
84struct GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<hasParentTypeTag<FirstTypeTag>(int{}), void>>
85{ using type = typename GetDefined<TypeTag, Property, ConCatTuples<typename FirstTypeTag::InheritsFrom, std::tuple<Args...>>>::type; };
86
87template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
88struct GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<!hasParentTypeTag<FirstTypeTag>(int{}), void>>
89{ using type = typename GetDefined<TypeTag, Property, std::tuple<Args...>>::type; };
90
91template<class TypeTag, template<class,class> class Property, class LastTypeTag>
92struct GetDefined<TypeTag, Property, std::tuple<LastTypeTag>>
93{
94// For clang, the following alias triggers compiler warnings if instantiated
95// from something like `GetPropType<..., DeprecatedProperty>`, even if that is
96// contained in a diagnostic pragma construct that should prevent these warnings.
97// As a workaround, also add the pragmas around this line.
98// See the discussion in MR 1647 for more details.
99#ifdef __clang__
100#pragma clang diagnostic push
101#pragma clang diagnostic ignored "-Wdeprecated-declarations"
102#endif
103 using LastType = Property<TypeTag, LastTypeTag>;
104#ifdef __clang__
105#pragma clang diagnostic pop
106#endif
107 using type = std::conditional_t<isDefinedProperty<LastType>(int{}), LastType,
108 typename GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, void>::type>;
109};
110
111template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
112struct GetDefined<TypeTag, Property, std::tuple<FirstTypeTag, Args...>>
113{
114// See the comment above.
115#ifdef __clang__
116#pragma clang diagnostic push
117#pragma clang diagnostic ignored "-Wdeprecated-declarations"
118#endif
119 using FirstType = Property<TypeTag, FirstTypeTag>;
120#ifdef __clang__
121#pragma clang diagnostic pop
122#endif
123 using type = std::conditional_t<isDefinedProperty<FirstType>(int{}), FirstType,
124 typename GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, void>::type>;
125};
126
128template<class TypeTag, template<class,class> class Property>
130{
132 static_assert(!std::is_same<type, UndefinedProperty>::value, "Property is undefined!");
133};
134
135} // end namespace Dumux::Properties::Detail
136
137namespace Dumux {
138
140template<class TypeTag, template<class,class> class Property>
142
143// See the comment above.
144#ifdef __clang__
145#pragma clang diagnostic push
146#pragma clang diagnostic ignored "-Wdeprecated-declarations"
147#endif
149template<class TypeTag, template<class,class> class Property>
151
153template<class TypeTag, template<class,class> class Property>
155#ifdef __clang__
156#pragma clang diagnostic pop
157#endif
158
159} // end namespace Dumux
160
161#endif
Definition: adapt.hh:29
constexpr auto getPropValue()
get the value data member of a property
Definition: propertysystem.hh:154
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property
Definition: propertysystem.hh:141
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:150
Definition: common/properties.hh:37
implementation details for template meta programming
Definition: propertysystem.hh:40
decltype(std::tuple_cat(std::declval< Tuples >()...)) ConCatTuples
helper alias to concatenate multiple tuples
Definition: propertysystem.hh:65
constexpr auto isDefinedProperty(int) -> decltype(std::integral_constant< bool, !std::is_same_v< typename P::type, UndefinedProperty > >{})
check if a property P is defined
Definition: propertysystem.hh:44
constexpr auto hasParentTypeTag(int) -> decltype(std::declval< typename T::InheritsFrom >(), std::true_type{})
check if a TypeTag inherits from other TypeTags
Definition: propertysystem.hh:54
a tag to mark properties as undefined
Definition: propertysystem.hh:35
helper struct to get the first property that is defined in the TypeTag hierarchy
Definition: propertysystem.hh:69
helper struct to iteratre over the TypeTag hierarchy
Definition: propertysystem.hh:73
typename GetDefined< TypeTag, Property, typename LastTypeTag::InheritsFrom >::type type
Definition: propertysystem.hh:77
typename GetDefined< TypeTag, Property, ConCatTuples< typename FirstTypeTag::InheritsFrom, std::tuple< Args... > > >::type type
Definition: propertysystem.hh:85
std::conditional_t< isDefinedProperty< LastType >(int{}), LastType, typename GetNextTypeTag< TypeTag, Property, std::tuple< LastTypeTag >, void >::type > type
Definition: propertysystem.hh:108
Property< TypeTag, LastTypeTag > LastType
Definition: propertysystem.hh:103
std::conditional_t< isDefinedProperty< FirstType >(int{}), FirstType, typename GetNextTypeTag< TypeTag, Property, std::tuple< FirstTypeTag, Args... >, void >::type > type
Definition: propertysystem.hh:124
Property< TypeTag, FirstTypeTag > FirstType
Definition: propertysystem.hh:119
helper struct to extract get the Property specilization given a TypeTag, asserts that the property is...
Definition: propertysystem.hh:130
typename Detail::GetDefined< TypeTag, Property, std::tuple< TypeTag > >::type type
Definition: propertysystem.hh:131