Properties

The property system. More...

Collaboration diagram for Properties:

Macros

#define TTAG(TypeTagName)   Ewoms::Properties::TTag::TypeTagName
 Convert a type tag name to a type. More...
 
#define PTAG(PropTagName)   Ewoms::Properties::PTag::PropTagName
 Makes a type out of a property tag name. More...
 
#define NEW_TYPE_TAG(...)
 Define a new type tag. More...
 
#define SET_SPLICES(TypeTagName,...)
 Define splices for a given type tag. More...
 
#define INHERITS_FROM(...)   __VA_ARGS__
 Syntactic sugar for NEW_TYPE_TAG. More...
 
#define NEW_PROP_TAG(PTagName)
 Define a property tag. More...
 
#define SET_PROP(EffTypeTagName, PropTagName)
 Set a property for a specific type tag. More...
 
#define UNSET_PROP(EffTypeTagName, PropTagName)
 Explicitly unset a property for a type tag. More...
 
#define SET_INT_PROP(EffTypeTagName, PropTagName,...)
 Set a property to a simple constant integer value. More...
 
#define SET_BOOL_PROP(EffTypeTagName, PropTagName,...)
 Set a property to a simple constant boolean value. More...
 
#define SET_TYPE_PROP(EffTypeTagName, PropTagName,...)
 Set a property which defines a type. More...
 
#define SET_SCALAR_PROP(EffTypeTagName, PropTagName,...)
 Set a property to a simple constant scalar value. More...
 
#define SET_STRING_PROP(EffTypeTagName, PropTagName,...)
 Set a property to a simple constant string value. More...
 
#define SET_TAG_PROP(EffTypeTagName, PropTagName, ValueTypeTagName)
 Define a property containing a type tag. More...
 
#define GET_PROP(TypeTag, PropTagName)   ::Ewoms::Properties::GetProperty<TypeTag, PTAG(PropTagName)>::p
 Retrieve a property for a type tag. More...
 
#define GET_PROP_VALUE(TypeTag, PropTagName)   ::Ewoms::Properties::GetProperty<TypeTag, PTAG(PropTagName)>::p::value
 Access the value attribute of a property for a type tag. More...
 
#define GET_PROP_TYPE(TypeTag, PropTagName)   ::Ewoms::Properties::GetProperty<TypeTag, PTAG(PropTagName)>::p::type
 Access the type attribute of a property for a type tag. More...
 
#define PROP_DIAGNOSTIC(TypeTag, PropTagName)   ::Ewoms::Properties::getDiagnostic<TypeTag>(#PropTagName)
 Return a human readable diagnostic message how exactly a property was defined. More...
 

Detailed Description

The property system.

The purpose of the eWoms property system is to specify compile-time parameters. It can thus be used to specify types and things which cause the compiler to alter its decisions.

Semantically, the property system can be thought of being very similar to the standard C++ "traits" pattern. The advantages of the property system are that it includes build-in introspection capabilities and (more importantly) an easy to use inheritance mechanism.

Macro Definition Documentation

#define GET_PROP (   TypeTag,
  PropTagName 
)    ::Ewoms::Properties::GetProperty<TypeTag, PTAG(PropTagName)>::p

Retrieve a property for a type tag.

If you use GET_PROP within a template and want to refer to some type (including the property itself), GET_PROP must be preceeded by the 'typename' keyword.

Referenced by parseCommandLineOptions(), printUnused(), printUsage(), and printValues().

#define GET_PROP_TYPE (   TypeTag,
  PropTagName 
)    ::Ewoms::Properties::GetProperty<TypeTag, PTAG(PropTagName)>::p::type

Access the type attribute of a property for a type tag.

This is just for convenience and equivalent to GET_PROP(TypeTag, PropTag)::type. If the property doesn't have an attribute named type, this yields a compiler error. Also, if you use this macro within a template, it must be preceeded by the typename keyword.

Referenced by Ewoms::Properties::SET_PROP(), and start().

#define GET_PROP_VALUE (   TypeTag,
  PropTagName 
)    ::Ewoms::Properties::GetProperty<TypeTag, PTAG(PropTagName)>::p::value
#define INHERITS_FROM (   ...)    __VA_ARGS__

Syntactic sugar for NEW_TYPE_TAG.

See the documentation for NEW_TYPE_TAG.

#define NEW_PROP_TAG (   PTagName)
Value:
namespace PTag { \
struct PTagName; } extern int semicolonHack_

Define a property tag.

A property tag is the unique identifier for a property. It may only be declared once in your program. There is also no hierarchy of property tags as for type tags.

Examples:

1 NEW_PROP_TAG(blubbPropTag);
2 NEW_PROP_TAG(blabbPropTag);
#define NEW_TYPE_TAG (   ...)
Value:
namespace TTag { \
struct EWOMS_GET_HEAD_(__VA_ARGS__, blubb) \
: public TypeTag<__VA_ARGS__> \
{ }; \
TTAG_INFO_(__VA_ARGS__, void) \
} \
extern int semicolonHack_

Define a new type tag.

A type tag can inherit the properties defined on up to five parent type tags. Examples:

1 // The type tag doesn't inherit any properties from other type tags
2 NEW_TYPE_TAG(FooTypeTag);
3 
4 // BarTypeTag inherits all properties from FooTypeTag
5 NEW_TYPE_TAG(BarTypeTag, INHERITS_FROM(FooTypeTag));
6 
7 // FooBarTypeTag inherits the properties of FooTypeTag as well as
8 // those of BarTypeTag. Properties defined on BarTypeTag have
9 // preceedence over those defined for FooTypeTag:
10 NEW_TYPE_TAG(FooBarTypeTag, INHERITS_FROM(FooTypeTag, BarTypeTag));
#define PROP_DIAGNOSTIC (   TypeTag,
  PropTagName 
)    ::Ewoms::Properties::getDiagnostic<TypeTag>(#PropTagName)

Return a human readable diagnostic message how exactly a property was defined.

This is only enabled if the NO_PROPERTY_INTROSPECTION macro is not defined.

Example:

1 int main()
2 {
3  std::cout << PROP_DIAGNOSTIC(FooBarTypeTag, blabbPropTag) << "\n";
4 };
#define PTAG (   PropTagName)    Ewoms::Properties::PTag::PropTagName

Makes a type out of a property tag name.

Again property type names can be passed as template argument. This is rarely needed, though.

#define SET_BOOL_PROP (   EffTypeTagName,
  PropTagName,
  ... 
)
Value:
SET_PROP_(EffTypeTagName, \
/*kind=*/"bool ", \
PropTagName, \
/*value=*/__VA_ARGS__) \
{ \
typedef bool type; \
static const bool value = __VA_ARGS__; \
}

Set a property to a simple constant boolean value.

The constant can be accessed by the value attribute.

#define SET_INT_PROP (   EffTypeTagName,
  PropTagName,
  ... 
)
Value:
SET_PROP_(EffTypeTagName, \
/*kind=*/"int ", \
PropTagName, \
/*value=*/__VA_ARGS__) \
{ \
typedef int type; \
static const int value = __VA_ARGS__; \
}

Set a property to a simple constant integer value.

The constant can be accessed by the value attribute.

#define SET_PROP (   EffTypeTagName,
  PropTagName 
)
Value:
template <class TypeTag> \
struct Property<TypeTag, \
TTAG(EffTypeTagName), \
PTAG(PropTagName)>; \
PROP_INFO_(EffTypeTagName, \
/*kind=*/"opaque", \
PropTagName, \
/*value=*/"<opaque>") \
template <class TypeTag> \
struct Property<TypeTag, \
TTAG(EffTypeTagName), \
PTAG(PropTagName) >
#define TTAG(TypeTagName)
Convert a type tag name to a type.
Definition: propertysystem.hh:137
#define PTAG(PropTagName)
Makes a type out of a property tag name.
Definition: propertysystem.hh:146

Set a property for a specific type tag.

After this macro, you must to specify a complete body of a class template, including the trailing semicolon. If you need to retrieve another property within the class body, you can use TypeTag as the argument for the type tag for the GET_PROP macro.

Example:

1 SET_PROP(FooTypeTag, blubbPropTag)
2 {
3  static int value = 10;
4  static int calculate(int arg)
5  { calculateInternal_(arg); }
6 
7 private:
8  // retrieve the blabbProp property for the TypeTag the
9  // property is defined on. Note that blabbProb does not need to
10  // be defined on FooTypeTag, but can also be defined for some
11  // derived type tag.
12  typedef typename GET_PROP(TypeTag, blabbProp) blabb;
13 
14  static int calculateInternal_(int arg)
15  { return arg * blabb::value; };

};

#define SET_SCALAR_PROP (   EffTypeTagName,
  PropTagName,
  ... 
)
Value:
SET_PROP_(EffTypeTagName, \
/*kind=*/"scalar", \
PropTagName, \
/*value=*/__VA_ARGS__) \
{ \
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; \
public: \
typedef Scalar type; \
static const Scalar value; \
}; \
template <class TypeTag> \
const typename Property<TypeTag, TTAG(EffTypeTagName), PTAG(PropTagName)>::type \
Property<TypeTag, TTAG(EffTypeTagName), PTAG(PropTagName)>::value(__VA_ARGS__)
#define TTAG(TypeTagName)
Convert a type tag name to a type.
Definition: propertysystem.hh:137
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
#define PTAG(PropTagName)
Makes a type out of a property tag name.
Definition: propertysystem.hh:146

Set a property to a simple constant scalar value.

The constant can be accessed by the value attribute. In order to use this macro, the property tag Scalar needs to be defined for the type tag.

#define SET_SPLICES (   TypeTagName,
  ... 
)
Value:
namespace PTag { \
template<> \
struct Splices<TTAG(TypeTagName)> \
{ \
typedef RevertedTuple<__VA_ARGS__>::type tuple; \
}; \
SPLICE_INFO_(TTAG(TypeTagName), __VA_ARGS__) \
} \
extern int semicolonHack_
#define TTAG(TypeTagName)
Convert a type tag name to a type.
Definition: propertysystem.hh:137

Define splices for a given type tag.

Splices can be seen as children which can be overridden lower in the hierarchy. It can thus be seen as a "deferred inheritance" mechanism. Example:

1 // First, define type tags for two different linear solvers:
2 // BiCGStab and SuperLU. The first needs the "MaxIterations"
3 // property, the second defines the "UsePivoting" property.
4 NEW_TYPE_TAG(BiCGStabSolver);
5 NEW_PROP_TAG(MaxIterations);
6 SET_INT_PROP(BiCGStabSolver, MaxIterations, 100);
7 
8 NEW_TYPE_TAG(SuperLUSolver);
9 NEW_PROP_TAG(UsePivoting);
10 SET_BOOL_PROP(SuperLUSolver, UsePivoting, true);
11 
12 // The model type tag defines the splice 'LinearSolver' and sets it
13 // to the 'BiCGStabSolver' type tag.
14 NEW_TYPE_TAG(ModelTypeTag);
15 NEW_PROP_TAG(LinearSolver);
16 SET_SPLICES(ModelTypeTag, LinearSolver);
17 SET_TAG_PROP(ModelTypeTag, LinearSolver, BiCGStabSolver);
18 
19 // The problem type tag is derived from the model type tag, but uses
20 // the SuperLU solver. Since this is done using a splice, all properties
21 // defined for the "SuperLUSolver" are inherited and the ones for the
22 // BiCGStabSolver type tag are undefined
23 NEW_TYPE_TAG(ProblemTypeTag, INHERITS_FROM(ModelTypeTag));
24 SET_TAG_PROP(ProblemTypeTag, LinearSolver, SuperLUSolver);
#define SET_STRING_PROP (   EffTypeTagName,
  PropTagName,
  ... 
)
Value:
SET_PROP_(EffTypeTagName, \
/*kind=*/"string", \
PropTagName, \
/*value=*/__VA_ARGS__) \
{ \
public: \
typedef std::string type; \
static const std::string value; \
}; \
template <class TypeTag> \
const typename Property<TypeTag, TTAG(EffTypeTagName), PTAG(PropTagName)>::type \
Property<TypeTag, TTAG(EffTypeTagName), PTAG(PropTagName)>::value(__VA_ARGS__)

Set a property to a simple constant string value.

The constant can be accessed by the value attribute and is of type std::string.

#define SET_TAG_PROP (   EffTypeTagName,
  PropTagName,
  ValueTypeTagName 
)
Value:
SET_PROP_(EffTypeTagName, \
/*kind=*/"tag ", \
PropTagName, \
/*value=*/TTAG(ValueTypeTagName)) \
{ \
typedef TTAG(ValueTypeTagName) type; \
}
#define TTAG(TypeTagName)
Convert a type tag name to a type.
Definition: propertysystem.hh:137

Define a property containing a type tag.

This is convenient for splices.

#define SET_TYPE_PROP (   EffTypeTagName,
  PropTagName,
  ... 
)
Value:
SET_PROP_(EffTypeTagName, \
/*kind=*/"type ", \
PropTagName, \
/*value=*/__VA_ARGS__) \
{ \
typedef __VA_ARGS__ type; \
}

Set a property which defines a type.

The type can be accessed by the type attribute.

#define TTAG (   TypeTagName)    Ewoms::Properties::TTag::TypeTagName

Convert a type tag name to a type.

The main advantage of the type of a TypeTag is that it can be passed as a template argument.

#define UNSET_PROP (   EffTypeTagName,
  PropTagName 
)
Value:
template <> \
struct PropertyUnset<TTAG(EffTypeTagName), \
PTAG(PropTagName) >; \
PROP_INFO_(EffTypeTagName, \
/*kind=*/"withdraw", \
PropTagName, \
/*value=*/<none>) \
template <> \
struct PropertyUnset<TTAG(EffTypeTagName), \
PTAG(PropTagName) > \
: public PropertyExplicitlyUnset \
{}
#define TTAG(TypeTagName)
Convert a type tag name to a type.
Definition: propertysystem.hh:137
#define PTAG(PropTagName)
Makes a type out of a property tag name.
Definition: propertysystem.hh:146

Explicitly unset a property for a type tag.

This means that the property will not be inherited from the type tag's parents.

Example:

1 // make the blabbPropTag property undefined for the BarTypeTag.
2 UNSET_PROP(BarTypeTag, blabbPropTag);