dune-common  2.7.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 #include <dune/common/unused.hh>
8 
9 namespace Dune
10 {
24  template<typename TA>
25  class EmptySet
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>
59  class EnumItem
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>
94  class NegateSet
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>
109  class Combine
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  {
163  DUNE_UNUSED_PARAMETER(set1);
164  DUNE_UNUSED_PARAMETER(set2);
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
Dune::EnumItem::Type
TA Type
The type the set holds.
Definition: enumset.hh:65
Dune::Combine::contains
static bool contains(const TA &item)
Definition: enumset.hh:154
Dune::NegateSet::Type
S::Type Type
Definition: enumset.hh:97
Dune::combine
Combine< TI1, TI2, typename TI1::Type > combine(const TI1 &set1, const TI2 &set2)
Definition: enumset.hh:161
Dune::NegateSet
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
Dune::AllSet
A set containing everything.
Definition: enumset.hh:42
DUNE_UNUSED_PARAMETER
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Dune::EmptySet::contains
static bool contains(const Type &attribute)
Always returns false.
Definition: enumset.hh:116
Dune::AllSet::contains
static bool contains(const Type &attribute)
Always returns true.
Definition: enumset.hh:123
Dune::operator<<
std::ostream & operator<<(std::ostream &s, const bigunsignedint< k > &x)
Definition: bigunsignedint.hh:273
Dune::EnumRange
A set representing a range including the borders.
Definition: enumset.hh:78
Dune::EnumItem::contains
static bool contains(const Type &attribute)
Tests whether an item is in the set.
Definition: enumset.hh:130
Dune::Combine
A set combining two other sets.
Definition: enumset.hh:109
Dune::EnumItem
A set consisting only of one item.
Definition: enumset.hh:59
unused.hh
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Dune::EmptySet
An empty set.
Definition: enumset.hh:25
Dune::EmptySet::Type
TA Type
The POD type the set holds.
Definition: enumset.hh:31
Dune::AllSet::Type
TA Type
The POD type the set holds.
Definition: enumset.hh:48
Dune::EnumRange::Type
TA Type
The type the set holds.
Definition: enumset.hh:84
Dune::NegateSet::contains
static bool contains(const Type &item)
Definition: enumset.hh:99
Dune::EnumRange::contains
static bool contains(const Type &item)
Definition: enumset.hh:142
Dune
Dune namespace.
Definition: alignedallocator.hh:13