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 OPM_PROPERTY_SYSTEM_HH
27#define OPM_PROPERTY_SYSTEM_HH
28
29#include <dune/common/classname.hh>
30
31#include <cstring>
32#include <ostream>
33#include <tuple>
34#include <type_traits>
35
36namespace Opm {
37namespace Properties {
38
41
42template <class TypeTag, class MyTypeTag>
43struct Splices
44{
45 using type = std::tuple<>;
46};
47
49namespace Detail {
50
52template<class P>
53constexpr auto isDefinedProperty(int)
54-> decltype(std::integral_constant<bool, !std::is_same<typename P::type, UndefinedProperty>::value>{})
55{ return {}; }
56
58template<class P>
59constexpr std::true_type isDefinedProperty(...) { return {}; }
60
62template<class T>
63constexpr auto hasParentTypeTag(int)
64-> decltype(std::declval<typename T::InheritsFrom>(), std::true_type{})
65{ return {}; }
66
68template<class T>
69constexpr std::false_type hasParentTypeTag(...) { return {}; }
70
72template<class ...Tuples>
73using ConCatTuples = decltype(std::tuple_cat(std::declval<Tuples>()...));
74
76template<class TypeTag, template<class,class> class Property, class TTagList>
78
80template<class TypeTag, template<class,class> class Property, class TTagList, class Enable>
82
83template<class TypeTag, template<class,class> class Property, class LastTypeTag>
84struct GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, std::enable_if_t<hasParentTypeTag<LastTypeTag>(int{}), void>>
86
87template<class TypeTag, template<class,class> class Property, class LastTypeTag>
88struct GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, std::enable_if_t<!hasParentTypeTag<LastTypeTag>(int{}), void>>
90
91template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
92struct GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<hasParentTypeTag<FirstTypeTag>(int{}), void>>
93{ using type = typename GetDefined<TypeTag, Property, ConCatTuples<typename FirstTypeTag::InheritsFrom, std::tuple<Args...>>>::type; };
94
95template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
96struct GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<!hasParentTypeTag<FirstTypeTag>(int{}), void>>
97{ using type = typename GetDefined<TypeTag, Property, std::tuple<Args...>>::type; };
98
99template<class TypeTag, template<class,class> class Property, class LastTypeTag>
100struct GetDefined<TypeTag, Property, std::tuple<LastTypeTag>>
101{
102// For clang, the following alias triggers compiler warnings if instantiated
103// from something like `GetPropType<..., DeprecatedProperty>`, even if that is
104// contained in a diagnostic pragma construct that should prevent these warnings.
105// As a workaround, also add the pragmas around this line.
106// See the discussion in MR 1647 for more details.
107#ifdef __clang__
108#pragma clang diagnostic push
109#pragma clang diagnostic ignored "-Wdeprecated-declarations"
110#endif
111 using LastType = Property<TypeTag, LastTypeTag>;
112#ifdef __clang__
113#pragma clang diagnostic pop
114#endif
115 using type = std::conditional_t<isDefinedProperty<LastType>(int{}), LastType,
116 typename GetNextTypeTag<TypeTag, Property, std::tuple<LastTypeTag>, void>::type>;
117};
118
119template<class TypeTag, template<class,class> class Property, class FirstTypeTag, class ...Args>
120struct GetDefined<TypeTag, Property, std::tuple<FirstTypeTag, Args...>>
121{
122// See the comment above.
123#ifdef __clang__
124#pragma clang diagnostic push
125#pragma clang diagnostic ignored "-Wdeprecated-declarations"
126#endif
127 using FirstType = Property<TypeTag, FirstTypeTag>;
128#ifdef __clang__
129#pragma clang diagnostic pop
130#endif
131 using type = std::conditional_t<isDefinedProperty<FirstType>(int{}), FirstType,
132 typename GetNextTypeTag<TypeTag, Property, std::tuple<FirstTypeTag, Args...>, void>::type>;
133};
134
135
137template<class TypeTag, class TTagList>
139
141template<class TypeTag, class TTagList, class Enable>
143
144template<class TypeTag, class LastTypeTag>
145struct GetNextSpliceTypeTag<TypeTag, std::tuple<LastTypeTag>, std::enable_if_t<hasParentTypeTag<LastTypeTag>(int{}), void>>
147
148template<class TypeTag, class LastTypeTag>
149struct GetNextSpliceTypeTag<TypeTag, std::tuple<LastTypeTag>, std::enable_if_t<!hasParentTypeTag<LastTypeTag>(int{}), void>>
150{ using type = std::tuple<>; };
151
152template<class TypeTag, class FirstTypeTag, class ...Args>
153struct GetNextSpliceTypeTag<TypeTag, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<hasParentTypeTag<FirstTypeTag>(int{}), void>>
154{ using type = typename GetDefinedSplice<TypeTag, ConCatTuples<typename FirstTypeTag::InheritsFrom, std::tuple<Args...>>>::type; };
155
156template<class TypeTag, class FirstTypeTag, class ...Args>
157struct GetNextSpliceTypeTag<TypeTag, std::tuple<FirstTypeTag, Args...>, std::enable_if_t<!hasParentTypeTag<FirstTypeTag>(int{}), void>>
158{ using type = typename GetDefinedSplice<TypeTag, std::tuple<Args...>>::type; };
159
161template<class S>
162constexpr auto isDefinedSplice(int)
163-> decltype(std::integral_constant<bool, !std::is_same<typename S::type, std::tuple<>>::value>{})
164{ return {}; }
165
167template<class S>
168constexpr std::true_type isDefinedSplice(...) { return {}; }
169
170template<class TypeTag, class LastTypeTag>
171struct GetDefinedSplice<TypeTag, std::tuple<LastTypeTag>>
172{
174 using nexttuple = typename GetNextSpliceTypeTag<TypeTag,
176 std::tuple<LastTypeTag>,
177 typename LastSplice::type
178 >,
179 void>::type;
180
181 using type = std::conditional_t<isDefinedSplice<LastSplice>(int{}),
183 nexttuple>;
184};
185
186template<class TypeTag, class FirstTypeTag, class ...Args>
187struct GetDefinedSplice<TypeTag, std::tuple<FirstTypeTag, Args...>>
188{
190 using nexttuple = typename GetNextSpliceTypeTag<TypeTag,
192 std::tuple<FirstTypeTag, Args...>,
193 typename FirstSplice::type
194 >,
195 void>::type;
196
197 using type = std::conditional_t<isDefinedSplice<FirstSplice>(int{}),
199 nexttuple>;
200};
201
203template<class TypeTag, template<class,class> class Property>
205{
207 using type = typename Detail::GetDefined<TypeTag,
208 Property,
210 >::type;
211 static_assert(!std::is_same<type, UndefinedProperty>::value, "Property is undefined!");
212};
213
214template<class TypeTag, class SpliceTypeTag, template<class,class> class Property>
216{
218 static_assert(!std::is_same<type, std::tuple<>>::value, "Splice is undefined!");
219};
220
221template <typename, class = void>
222struct has_name : public std::false_type {};
223
224template <typename T>
225struct has_name<T, decltype((void)T::name, void())>
226: public std::true_type {};
227
228} // end namespace Detail
229} // end namespace Property
230
232template<class TypeTag, template<class,class> class Property>
234
235// See the comment above.
236#ifdef __clang__
237#pragma clang diagnostic push
238#pragma clang diagnostic ignored "-Wdeprecated-declarations"
239#endif
241template<class TypeTag, template<class,class> class Property>
243
244template<class TypeTag, class SpliceTypeTag, template<class,class> class Property>
246
248template<class TypeTag, template<class,class> class Property>
250
252template<class TypeTag, template<class,class> class Property>
254{
258 } else {
259 std::string paramName = Dune::className<type>();
260 paramName.replace(0, std::strlen("Opm::Properties::"), "");
261 const auto pos = paramName.find_first_of('<');
262 paramName.erase(pos);
263 return paramName;
264 }
265}
266
267#ifdef __clang__
268#pragma clang diagnostic pop
269#endif
270
271namespace Properties {
272template <class TypeTag>
273void printValues(std::ostream& os)
274{
275 os <<
276 "The eWoms property system was compiled with the macro\n"
277 "NO_PROPERTY_INTROSPECTION defined.\n"
278 "No diagnostic messages this time, sorry.\n";
279}
280}
281
282} // end namespace Opm
283
284#endif
constexpr auto hasParentTypeTag(int) -> decltype(std::declval< typename T::InheritsFrom >(), std::true_type{})
check if a TypeTag inherits from other TypeTags
Definition: propertysystem.hh:63
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:53
decltype(std::tuple_cat(std::declval< Tuples >()...)) ConCatTuples
helper alias to concatenate multiple tuples
Definition: propertysystem.hh:73
constexpr auto isDefinedSplice(int) -> decltype(std::integral_constant< bool, !std::is_same< typename S::type, std::tuple<> >::value >{})
check if a splice S is defined
Definition: propertysystem.hh:162
void printValues(std::ostream &os)
Definition: propertysystem.hh:273
Definition: blackoilboundaryratevector.hh:37
auto getPropName()
get the name data member of a property
Definition: propertysystem.hh:253
constexpr auto getPropValue()
get the value data member of a property
Definition: propertysystem.hh:249
typename Properties::Detail::GetSplicePropImpl< TypeTag, SpliceTypeTag, Property >::type::type GetSplicePropType
Definition: propertysystem.hh:245
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:242
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type GetProp
get the type of a property (equivalent to old macro GET_PROP(...))
Definition: propertysystem.hh:233
std::conditional_t< isDefinedProperty< LastType >(int{}), LastType, typename GetNextTypeTag< TypeTag, Property, std::tuple< LastTypeTag >, void >::type > type
Definition: propertysystem.hh:116
Property< TypeTag, LastTypeTag > LastType
Definition: propertysystem.hh:111
std::conditional_t< isDefinedProperty< FirstType >(int{}), FirstType, typename GetNextTypeTag< TypeTag, Property, std::tuple< FirstTypeTag, Args... >, void >::type > type
Definition: propertysystem.hh:132
Property< TypeTag, FirstTypeTag > FirstType
Definition: propertysystem.hh:127
helper struct to get the first property that is defined in the TypeTag hierarchy
Definition: propertysystem.hh:77
typename GetNextSpliceTypeTag< TypeTag, ConCatTuples< std::tuple< FirstTypeTag, Args... >, typename FirstSplice::type >, void >::type nexttuple
Definition: propertysystem.hh:195
std::conditional_t< isDefinedSplice< FirstSplice >(int{}), ConCatTuples< typename FirstSplice::type, nexttuple >, nexttuple > type
Definition: propertysystem.hh:199
std::conditional_t< isDefinedSplice< LastSplice >(int{}), ConCatTuples< nexttuple, typename LastSplice::type >, nexttuple > type
Definition: propertysystem.hh:183
typename GetNextSpliceTypeTag< TypeTag, ConCatTuples< std::tuple< LastTypeTag >, typename LastSplice::type >, void >::type nexttuple
Definition: propertysystem.hh:179
helper struct to get the first property that is defined in the TypeTag hierarchy
Definition: propertysystem.hh:138
typename GetDefinedSplice< TypeTag, ConCatTuples< typename FirstTypeTag::InheritsFrom, std::tuple< Args... > > >::type type
Definition: propertysystem.hh:154
typename GetDefinedSplice< TypeTag, typename LastTypeTag::InheritsFrom >::type type
Definition: propertysystem.hh:146
helper struct to iterate over the TypeTag hierarchy
Definition: propertysystem.hh:142
typename GetDefined< TypeTag, Property, typename LastTypeTag::InheritsFrom >::type type
Definition: propertysystem.hh:85
typename GetDefined< TypeTag, Property, ConCatTuples< typename FirstTypeTag::InheritsFrom, std::tuple< Args... > > >::type type
Definition: propertysystem.hh:93
helper struct to iterate over the TypeTag hierarchy
Definition: propertysystem.hh:81
helper struct to extract get the Property specilization given a TypeTag, asserts that the property is...
Definition: propertysystem.hh:205
typename Detail::GetDefinedSplice< TypeTag, std::tuple< TypeTag > >::type tuple
Definition: propertysystem.hh:206
typename Detail::GetDefined< TypeTag, Property, ConCatTuples< std::tuple< TypeTag >, tuple > >::type type
Definition: propertysystem.hh:210
Definition: propertysystem.hh:216
typename Detail::GetDefined< TypeTag, Property, std::tuple< TypeTag, SpliceTypeTag > >::type type
Definition: propertysystem.hh:217
Definition: propertysystem.hh:222
Definition: propertysystem.hh:44
std::tuple<> type
Definition: propertysystem.hh:45
a tag to mark properties as undefined
Definition: propertysystem.hh:40