DUNE PDELab (2.7)

enumset.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_ENUMSET_HH
4#define DUNE_ENUMSET_HH
5
6#include <iostream>
8
9namespace Dune
10{
24 template<typename TA>
26 {
27 public:
31 typedef TA Type;
35 static bool contains(const Type& attribute);
36 };
37
41 template<typename TA>
42 class AllSet
43 {
44 public:
48 typedef TA Type;
52 static bool contains(const Type& attribute);
53 };
54
58 template<typename TA, int item>
60 {
61 public:
65 typedef TA Type;
66
71 static bool contains(const Type& attribute);
72 };
73
77 template<typename TA,int from, int end>
78 class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
79 {
80 public:
84 typedef TA Type;
85 static bool contains(const Type& item);
86 };
87
93 template<typename S>
95 {
96 public:
97 typedef typename S::Type Type;
98
99 static bool contains(const Type& item)
100 {
101 return !S::contains(item);
102 }
103 };
104
108 template<class TI1, class TI2, typename TA=typename TI1::Type>
110 {
111 public:
112 static bool contains(const TA& item);
113 };
114
115 template<typename TA>
116 inline bool EmptySet<TA>::contains(const Type& attribute)
117 {
118 DUNE_UNUSED_PARAMETER(attribute);
119 return false;
120 }
121
122 template<typename TA>
123 inline bool AllSet<TA>::contains(const Type& attribute)
124 {
125 DUNE_UNUSED_PARAMETER(attribute);
126 return true;
127 }
128
129 template<typename TA,int i>
130 inline bool EnumItem<TA,i>::contains(const Type& item)
131 {
132 return item==i;
133 }
134
135 template<typename TA,int i>
136 inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
137 {
138 return os<<i;
139 }
140
141 template<typename TA, int from, int to>
142 inline bool EnumRange<TA,from,to>::contains(const Type& item)
143 {
144 return from<=item && item<=to;
145 }
146
147 template<typename TA, int from, int to>
148 inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
149 {
150 return os<<"["<<from<<" - "<<to<<"]";
151 }
152
153 template<class TI1, class TI2, typename TA>
154 inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
155 {
156 return TI1::contains(item) ||
157 TI2::contains(item);
158 }
159
160 template<class TI1, class TI2>
161 inline Combine<TI1,TI2,typename TI1::Type> combine(const TI1& set1, const TI2& set2)
162 {
165 return Combine<TI1,TI2,typename TI1::Type>();
166 }
167
168 template<class TI1, class TI2, class T>
169 inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
170 {
171 return os << TI1()<<" "<<TI2();
172 }
174}
175
176#endif
A set containing everything.
Definition: enumset.hh:43
TA Type
The POD type the set holds.
Definition: enumset.hh:48
A set combining two other sets.
Definition: enumset.hh:110
An empty set.
Definition: enumset.hh:26
TA Type
The POD type the set holds.
Definition: enumset.hh:31
A set consisting only of one item.
Definition: enumset.hh:60
TA Type
The type the set holds.
Definition: enumset.hh:65
A set representing a range including the borders.
Definition: enumset.hh:79
TA Type
The type the set holds.
Definition: enumset.hh:84
The negation of a set. An item is contained in the set if and only if it is not contained in the nega...
Definition: enumset.hh:95
static bool contains(const Type &attribute)
Always returns true.
Definition: enumset.hh:123
static bool contains(const Type &attribute)
Always returns false.
Definition: enumset.hh:116
static bool contains(const Type &attribute)
Tests whether an item is in the set.
Definition: enumset.hh:130
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Dune namespace.
Definition: alignedallocator.hh:14
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)