Dune Core Modules (2.8.0)

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>
7
8namespace Dune
9{
23 template<typename TA>
25 {
26 public:
30 typedef TA Type;
34 static bool contains(const Type& attribute);
35 };
36
40 template<typename TA>
41 class AllSet
42 {
43 public:
47 typedef TA Type;
51 static bool contains(const Type& attribute);
52 };
53
57 template<typename TA, int item>
59 {
60 public:
64 typedef TA Type;
65
70 static bool contains(const Type& attribute);
71 };
72
76 template<typename TA,int from, int end>
77 class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
78 {
79 public:
83 typedef TA Type;
84 static bool contains(const Type& item);
85 };
86
92 template<typename S>
94 {
95 public:
96 typedef typename S::Type Type;
97
98 static bool contains(const Type& item)
99 {
100 return !S::contains(item);
101 }
102 };
103
107 template<class TI1, class TI2, typename TA=typename TI1::Type>
109 {
110 public:
111 static bool contains(const TA& item);
112 };
113
114 template<typename TA>
115 inline bool EmptySet<TA>::contains([[maybe_unused]] const Type& attribute)
116 {
117 return false;
118 }
119
120 template<typename TA>
121 inline bool AllSet<TA>::contains([[maybe_unused]] const Type& attribute)
122 {
123 return true;
124 }
125
126 template<typename TA,int i>
127 inline bool EnumItem<TA,i>::contains(const Type& item)
128 {
129 return item==i;
130 }
131
132 template<typename TA,int i>
133 inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
134 {
135 return os<<i;
136 }
137
138 template<typename TA, int from, int to>
139 inline bool EnumRange<TA,from,to>::contains(const Type& item)
140 {
141 return from<=item && item<=to;
142 }
143
144 template<typename TA, int from, int to>
145 inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
146 {
147 return os<<"["<<from<<" - "<<to<<"]";
148 }
149
150 template<class TI1, class TI2, typename TA>
151 inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
152 {
153 return TI1::contains(item) ||
154 TI2::contains(item);
155 }
156
157 template<class TI1, class TI2>
158 inline Combine<TI1,TI2,typename TI1::Type> combine([[maybe_unused]] const TI1& set1,
159 [[maybe_unused]] const TI2& set2)
160 {
161 return Combine<TI1,TI2,typename TI1::Type>();
162 }
163
164 template<class TI1, class TI2, class T>
165 inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
166 {
167 return os << TI1()<<" "<<TI2();
168 }
170}
171
172#endif
A set containing everything.
Definition: enumset.hh:42
TA Type
The POD type the set holds.
Definition: enumset.hh:47
A set combining two other sets.
Definition: enumset.hh:109
An empty set.
Definition: enumset.hh:25
TA Type
The POD type the set holds.
Definition: enumset.hh:30
A set consisting only of one item.
Definition: enumset.hh:59
TA Type
The type the set holds.
Definition: enumset.hh:64
A set representing a range including the borders.
Definition: enumset.hh:78
TA Type
The type the set holds.
Definition: enumset.hh:83
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:94
static bool contains(const Type &attribute)
Always returns true.
Definition: enumset.hh:121
static bool contains(const Type &attribute)
Always returns false.
Definition: enumset.hh:115
static bool contains(const Type &attribute)
Tests whether an item is in the set.
Definition: enumset.hh:127
Dune namespace.
Definition: alignedallocator.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)