dune-common  2.2.0
enumset.hh
Go to the documentation of this file.
00001 #ifndef DUNE_ENUMSET_HH
00002 #define DUNE_ENUMSET_HH
00003 
00004 #include<iostream>
00005 
00006 namespace Dune
00007 {
00021   template<typename TA>
00022   class EmptySet
00023   {
00024   public:
00028     typedef TA Type;
00032     static bool contains(const Type& attribute);
00033   };
00034 
00038   template<typename TA>
00039   class AllSet
00040   {
00041   public:
00045     typedef TA Type;
00049     static bool contains(const Type& attribute);
00050   };
00051 
00055   template<typename TA, int item>
00056   class EnumItem 
00057   {
00058   public:
00062     typedef TA Type;
00063     
00068     static bool contains(const Type& attribute);
00069   };
00070 
00074   template<typename TA,int from, int end>
00075   class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
00076   {
00077   public:
00081     typedef TA Type;
00082     static bool contains(const Type& item);
00083   };
00084 
00090   template<typename S>
00091   class NegateSet
00092   {
00093   public:
00094     typedef typename S::Type Type;
00095   
00096     static bool contains(const Type& item)
00097     {
00098       return !S::contains(item);
00099     }
00100   };
00101   
00105   template<class TI1, class TI2, typename TA=typename TI1::Type>
00106   class Combine 
00107   {
00108   public:
00109     static bool contains(const TA& item);
00110   };
00111   
00112   template<typename TA>
00113   inline bool EmptySet<TA>::contains(const Type& attribute)
00114   {
00115     return false;
00116   }
00117 
00118   template<typename TA>
00119   inline bool AllSet<TA>::contains(const Type& attribute)
00120   {
00121     return true;
00122   }
00123 
00124   template<typename TA,int i>
00125   inline bool EnumItem<TA,i>::contains(const Type& item)
00126   {
00127     return item==i;
00128   }
00129 
00130   template<typename TA,int i>
00131   inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
00132   {
00133     return os<<i;
00134   }
00135 
00136   template<typename TA, int from, int to>
00137   inline bool EnumRange<TA,from,to>::contains(const Type& item)
00138   {
00139     return from<=item && item<=to;
00140   }
00141   
00142   template<typename TA, int from, int to>
00143   inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
00144   {
00145     return os<<"["<<from<<" - "<<to<<"]";
00146   }
00147   
00148   template<class TI1, class TI2, typename TA>
00149   inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
00150   {
00151     return TI1::contains(item) ||
00152       TI2::contains(item);
00153   }
00154     
00155   template<class TI1, class TI2>
00156   inline Combine<TI1,TI2,typename TI1::Type> combine(const TI1& set1, const TI2& set2)
00157   {
00158     return Combine<TI1,TI2,typename TI1::Type>();
00159   }  
00160 
00161   template<class TI1, class TI2, class T>
00162   inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
00163   {
00164     return os << TI1()<<" "<<TI2();
00165   }
00167 }
00168 
00169 #endif