dune-common  2.3.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  {
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