3.2-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 {
33namespace Properties {
34
37
39namespace Detail {
40
42template<class P>
43constexpr auto isDefinedProperty(int)
44-> decltype(std::integral_constant<bool, !std::is_same<typename P::type, UndefinedProperty>::value>{})
45{ return {}; }
46
48template<class P>
49constexpr std::true_type isDefinedProperty(...) { return {}; }
50
54template<class T>
55constexpr auto hasParentTypeTag(int)
56-> decltype(std::declval<typename T::InheritsFrom>(), std::enable_if_t<!std::is_same<typename T::InheritsFrom, void>::value, int>{}, std::true_type{})
57{ return {}; }
58
60template<class T>
61constexpr std::false_type hasParentTypeTag(...) { 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 Detail
136} // end namespace Property
137
139template<class TypeTag, template<class,class> class Property>
141
142// See the comment above.
143#ifdef __clang__
144#pragma clang diagnostic push
145#pragma clang diagnostic ignored "-Wdeprecated-declarations"
146#endif
148template<class TypeTag, template<class,class> class Property>
150
152template<class TypeTag, template<class,class> class Property>
154#ifdef __clang__
155#pragma clang diagnostic pop
156#endif
157
158} // end namespace Dumux
159
160#endif
Definition: adapt.hh:29
constexpr auto getPropValue()
get the value data member of a property
Definition: propertysystem.hh:153
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property (equivalent to old macro GET_PROP(...))
Definition: propertysystem.hh:140
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
constexpr auto isDefinedProperty(int) -> decltype(std::integral_constant< bool, !std::is_same< typename P::type, UndefinedProperty >::value >{})
check if a property P is defined
Definition: propertysystem.hh:43
decltype(std::tuple_cat(std::declval< Tuples >()...)) ConCatTuples
helper alias to concatenate multiple tuples
Definition: propertysystem.hh:65
constexpr auto hasParentTypeTag(int) -> decltype(std::declval< typename T::InheritsFrom >(), std::enable_if_t<!std::is_same< typename T::InheritsFrom, void >::value, int >{}, std::true_type{})
Definition: propertysystem.hh:55
a tag to mark properties as undefined
Definition: propertysystem.hh:36
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