00001
00002
00003 #ifndef DUNE_ENUMSET_HH
00004 #define DUNE_ENUMSET_HH
00005
00006 #include <iostream>
00007 #include <dune/common/unused.hh>
00008
00009 namespace Dune
00010 {
00024 template<typename TA>
00025 class EmptySet
00026 {
00027 public:
00031 typedef TA Type;
00035 static bool contains(const Type& attribute);
00036 };
00037
00041 template<typename TA>
00042 class AllSet
00043 {
00044 public:
00048 typedef TA Type;
00052 static bool contains(const Type& attribute);
00053 };
00054
00058 template<typename TA, int item>
00059 class EnumItem
00060 {
00061 public:
00065 typedef TA Type;
00066
00071 static bool contains(const Type& attribute);
00072 };
00073
00077 template<typename TA,int from, int end>
00078 class EnumRange
00079 {
00080 public:
00084 typedef TA Type;
00085 static bool contains(const Type& item);
00086 };
00087
00093 template<typename S>
00094 class NegateSet
00095 {
00096 public:
00097 typedef typename S::Type Type;
00098
00099 static bool contains(const Type& item)
00100 {
00101 return !S::contains(item);
00102 }
00103 };
00104
00108 template<class TI1, class TI2, typename TA=typename TI1::Type>
00109 class Combine
00110 {
00111 public:
00112 static bool contains(const TA& item);
00113 };
00114
00115 template<typename TA>
00116 inline bool EmptySet<TA>::contains(const Type& attribute)
00117 {
00118 DUNE_UNUSED_PARAMETER(attribute);
00119 return false;
00120 }
00121
00122 template<typename TA>
00123 inline bool AllSet<TA>::contains(const Type& attribute)
00124 {
00125 DUNE_UNUSED_PARAMETER(attribute);
00126 return true;
00127 }
00128
00129 template<typename TA,int i>
00130 inline bool EnumItem<TA,i>::contains(const Type& item)
00131 {
00132 return item==i;
00133 }
00134
00135 template<typename TA,int i>
00136 inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
00137 {
00138 return os<<i;
00139 }
00140
00141 template<typename TA, int from, int to>
00142 inline bool EnumRange<TA,from,to>::contains(const Type& item)
00143 {
00144 return from<=item && item<=to;
00145 }
00146
00147 template<typename TA, int from, int to>
00148 inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
00149 {
00150 return os<<"["<<from<<" - "<<to<<"]";
00151 }
00152
00153 template<class TI1, class TI2, typename TA>
00154 inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
00155 {
00156 return TI1::contains(item) ||
00157 TI2::contains(item);
00158 }
00159
00160 template<class TI1, class TI2>
00161 inline Combine<TI1,TI2,typename TI1::Type> combine(const TI1& set1, const TI2& set2)
00162 {
00163 return Combine<TI1,TI2,typename TI1::Type>();
00164 }
00165
00166 template<class TI1, class TI2, class T>
00167 inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
00168 {
00169 return os << TI1()<<" "<<TI2();
00170 }
00172 }
00173
00174 #endif