dune-common  2.2.1
enumset.hh
Go to the documentation of this file.
1 #ifndef DUNE_ENUMSET_HH
2 #define DUNE_ENUMSET_HH
3 
4 #include<iostream>
5 
6 namespace Dune
7 {
21  template<typename TA>
22  class EmptySet
23  {
24  public:
28  typedef TA Type;
32  static bool contains(const Type& attribute);
33  };
34 
38  template<typename TA>
39  class AllSet
40  {
41  public:
45  typedef TA Type;
49  static bool contains(const Type& attribute);
50  };
51 
55  template<typename TA, int item>
56  class EnumItem
57  {
58  public:
62  typedef TA Type;
63 
68  static bool contains(const Type& attribute);
69  };
70 
74  template<typename TA,int from, int end>
75  class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
76  {
77  public:
81  typedef TA Type;
82  static bool contains(const Type& item);
83  };
84 
90  template<typename S>
91  class NegateSet
92  {
93  public:
94  typedef typename S::Type Type;
95 
96  static bool contains(const Type& item)
97  {
98  return !S::contains(item);
99  }
100  };
101 
105  template<class TI1, class TI2, typename TA=typename TI1::Type>
106  class Combine
107  {
108  public:
109  static bool contains(const TA& item);
110  };
111 
112  template<typename TA>
113  inline bool EmptySet<TA>::contains(const Type& attribute)
114  {
115  return false;
116  }
117 
118  template<typename TA>
119  inline bool AllSet<TA>::contains(const Type& attribute)
120  {
121  return true;
122  }
123 
124  template<typename TA,int i>
125  inline bool EnumItem<TA,i>::contains(const Type& item)
126  {
127  return item==i;
128  }
129 
130  template<typename TA,int i>
131  inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
132  {
133  return os<<i;
134  }
135 
136  template<typename TA, int from, int to>
137  inline bool EnumRange<TA,from,to>::contains(const Type& item)
138  {
139  return from<=item && item<=to;
140  }
141 
142  template<typename TA, int from, int to>
143  inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
144  {
145  return os<<"["<<from<<" - "<<to<<"]";
146  }
147 
148  template<class TI1, class TI2, typename TA>
149  inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
150  {
151  return TI1::contains(item) ||
152  TI2::contains(item);
153  }
154 
155  template<class TI1, class TI2>
156  inline Combine<TI1,TI2,typename TI1::Type> combine(const TI1& set1, const TI2& set2)
157  {
159  }
160 
161  template<class TI1, class TI2, class T>
162  inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
163  {
164  return os << TI1()<<" "<<TI2();
165  }
167 }
168 
169 #endif