Dune Core Modules (2.9.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// SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_ENUMSET_HH
6#define DUNE_ENUMSET_HH
7
8#include <iostream>
9
10namespace Dune
11{
25 template<typename TA>
27 {
28 public:
32 typedef TA Type;
36 static bool contains(const Type& attribute);
37 };
38
42 template<typename TA>
43 class AllSet
44 {
45 public:
49 typedef TA Type;
53 static bool contains(const Type& attribute);
54 };
55
59 template<typename TA, int item>
61 {
62 public:
66 typedef TA Type;
67
72 static bool contains(const Type& attribute);
73 };
74
78 template<typename TA,int from, int end>
79 class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
80 {
81 public:
85 typedef TA Type;
86 static bool contains(const Type& item);
87 };
88
94 template<typename S>
96 {
97 public:
98 typedef typename S::Type Type;
99
100 static bool contains(const Type& item)
101 {
102 return !S::contains(item);
103 }
104 };
105
109 template<class TI1, class TI2, typename TA=typename TI1::Type>
111 {
112 public:
113 static bool contains(const TA& item);
114 };
115
116 template<typename TA>
117 inline bool EmptySet<TA>::contains([[maybe_unused]] const Type& attribute)
118 {
119 return false;
120 }
121
122 template<typename TA>
123 inline bool AllSet<TA>::contains([[maybe_unused]] const Type& attribute)
124 {
125 return true;
126 }
127
128 template<typename TA,int i>
129 inline bool EnumItem<TA,i>::contains(const Type& item)
130 {
131 return item==i;
132 }
133
134 template<typename TA,int i>
135 inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
136 {
137 return os<<i;
138 }
139
140 template<typename TA, int from, int to>
141 inline bool EnumRange<TA,from,to>::contains(const Type& item)
142 {
143 return from<=item && item<=to;
144 }
145
146 template<typename TA, int from, int to>
147 inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
148 {
149 return os<<"["<<from<<" - "<<to<<"]";
150 }
151
152 template<class TI1, class TI2, typename TA>
153 inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
154 {
155 return TI1::contains(item) ||
156 TI2::contains(item);
157 }
158
159 template<class TI1, class TI2>
160 inline Combine<TI1,TI2,typename TI1::Type> combine([[maybe_unused]] const TI1& set1,
161 [[maybe_unused]] const TI2& set2)
162 {
163 return Combine<TI1,TI2,typename TI1::Type>();
164 }
165
166 template<class TI1, class TI2, class T>
167 inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
168 {
169 return os << TI1()<<" "<<TI2();
170 }
172}
173
174#endif
A set containing everything.
Definition: enumset.hh:44
TA Type
The POD type the set holds.
Definition: enumset.hh:49
A set combining two other sets.
Definition: enumset.hh:111
An empty set.
Definition: enumset.hh:27
TA Type
The POD type the set holds.
Definition: enumset.hh:32
A set consisting only of one item.
Definition: enumset.hh:61
TA Type
The type the set holds.
Definition: enumset.hh:66
A set representing a range including the borders.
Definition: enumset.hh:80
TA Type
The type the set holds.
Definition: enumset.hh:85
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:96
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:117
static bool contains(const Type &attribute)
Tests whether an item is in the set.
Definition: enumset.hh:129
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)