3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
propertysystemmacros.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 * MERCHANTBILITY 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 *****************************************************************************/
39#ifndef DUMUX_PROPERTY_SYSTEM_MACROS_HH
40#define DUMUX_PROPERTY_SYSTEM_MACROS_HH
41#warning "Property macros are deprecated and will be removed after release 3.2. \
42If you are not using property macros you can disable this warning by \
43setting DUMUX_ENABLE_OLD_PROPERTY_MACROS to 0 (false) when configuring DuMux. \
44DUMUX_ENABLE_OLD_PROPERTY_MACROS defaults to 1 (true) until release 3.1. \
45After release 3.1 it will default to 0 (false) so you will have to manually \
46enable property macros in order to use them."
47
48#include <cstddef>
49
51
52namespace Dumux {
53namespace Properties {
54
55namespace TTag {}
56
60#define TTAG(TypeTagName) ::Dumux::Properties::TTag::TypeTagName
61
65//#define PTAG(PropTagName) PropTagName
66
70#define PTAG_(PropTagName) ::Dumux::Properties::PropTagName
71
72
73// in the old property system the order in inherit_from was the other way around
74// this flips the order of a tuple to restore old behaviour when using the macro.
75// when you are using non-macro version make sure to flip the order.
76template<class Tuple, class IndexSequence>
78
79template<class Tuple, size_t... I>
80struct ReverseTupleImpl<Tuple, std::index_sequence<I...>>
81{
82 using type = std::tuple<std::tuple_element_t<sizeof...(I) - 1 - I, Tuple>...>;
83};
84
85// revert tuple argument order
86template<class Tuple>
88
89// a temporary hack to make the macro still work, we set using InheritsFrom = void,
90// which gets picked up by the new property as non inheritance, this can be removed
91// once all macros are gone
92namespace Detail {
93template<class TypeTagTuple>
95
96template<class OneTypeTag>
97struct GetTypeTagInheritance<std::tuple<OneTypeTag>>
98{
99 using type = void;
100};
101
102template<class FirstTypeTag, class ...OtherTypeTags>
103struct GetTypeTagInheritance<std::tuple<FirstTypeTag, OtherTypeTags...>>
104{
105 // reverse order to restore old behaviour
106 using type = ReverseTuple<std::tuple<OtherTypeTags...>>;
107};
108} // end namespace Detail
109
130#define DUMUX_GET_HEAD_(Arg1, ...) Arg1
131
132#define NEW_TYPE_TAG(...) \
133 namespace TTag { \
134 struct DUMUX_GET_HEAD_(__VA_ARGS__) \
135 { using InheritsFrom = Detail::GetTypeTagInheritance<std::tuple<__VA_ARGS__>>::type; }; \
136 } extern int semicolonHack_
137
144#define INHERITS_FROM(...) __VA_ARGS__
145
161#define NEW_PROP_TAG(PTagName) \
162 template<class TypeTag, class MyTypeTag> \
163 struct PTagName { using type = UndefinedProperty; }; \
164 extern int semicolonHack_
165
196#define SET_PROP(EffTypeTagName, PropTagName) \
197 template <class TypeTag> \
198 struct PropTagName<TypeTag, TTAG(EffTypeTagName)>
199
206#define SET_INT_PROP(EffTypeTagName, PropTagName, /*Value*/...) \
207 template <class TypeTag> \
208 struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
209 { \
210 using type = int; \
211 static constexpr int value = __VA_ARGS__; \
212 }
213
220#define SET_BOOL_PROP(EffTypeTagName, PropTagName, /*Value*/...) \
221 template <class TypeTag> \
222 struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
223 { \
224 using type = bool; \
225 static constexpr bool value = __VA_ARGS__; \
226 }
227
234#define SET_TYPE_PROP(EffTypeTagName, PropTagName, /*Value*/...) \
235 template <class TypeTag> \
236 struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
237 { \
238 using type = __VA_ARGS__; \
239 }
240
249#define SET_SCALAR_PROP(EffTypeTagName, PropTagName, ...) \
250 template <class TypeTag> \
251 struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
252 { \
253 using Scalar = Dumux::GetPropType<TypeTag, Scalar>; \
254 public: \
255 using type = Scalar; \
256 static const Scalar value; \
257 }; \
258 template <class TypeTag> \
259 const typename PropTagName<TypeTag, TTAG(EffTypeTagName)>::type \
260 PropTagName<TypeTag, TTAG(EffTypeTagName)>::value(__VA_ARGS__)
261
269#define SET_STRING_PROP(EffTypeTagName, PropTagName, ...) \
270 template <class TypeTag> \
271 struct PropTagName<TypeTag, TTAG(EffTypeTagName)> \
272 { \
273 public: \
274 using type = std::string; \
275 static const std::string value; \
276 }; \
277 template <class TypeTag> \
278 const typename PropTagName<TypeTag, TTAG(EffTypeTagName)>::type \
279 PropTagName<TypeTag, TTAG(EffTypeTagName)>::value(__VA_ARGS__)
280
281
282// getters
283#define GET_PROP(TypeTag, PropTagName) ::Dumux::Properties::Detail::GetPropImpl<TypeTag, PTAG_(PropTagName)>::type
284#define GET_PROP_VALUE(TypeTag, PropTagName) ::Dumux::Properties::Detail::GetPropImpl<TypeTag, PTAG_(PropTagName)>::type::value
285#define GET_PROP_TYPE(TypeTag, PropTagName) ::Dumux::Properties::Detail::GetPropImpl<TypeTag, PTAG_(PropTagName)>::type::type
286
287} // namespace Properties
288} // namespace Dumux
289
290#endif // DUMUX_PROPERTY_SYSTEM_HH
The Dumux property system, traits with inheritance.
Definition: adapt.hh:29
typename ReverseTupleImpl< Tuple, std::make_index_sequence< std::tuple_size< Tuple >::value > >::type ReverseTuple
Definition: propertysystemmacros.hh:87
Definition: propertysystemmacros.hh:77
std::tuple< std::tuple_element_t< sizeof...(I) - 1 - I, Tuple >... > type
Definition: propertysystemmacros.hh:82
Definition: propertysystemmacros.hh:94
ReverseTuple< std::tuple< OtherTypeTags... > > type
Definition: propertysystemmacros.hh:106