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, int item>
00039   class EnumItem 
00040   {
00041   public:
00045     typedef TA Type;
00046     
00051     static bool contains(const Type& attribute);
00052   };
00053 
00057   template<typename T,int from, int end>
00058   class EnumRange //: public PODSet<EnumRange<T,from,end>,T>
00059   {
00060   public:
00064     typedef T Type;
00065     static bool contains(const T& item);
00066   };
00067 
00073   template<typename S>
00074   class NegateSet
00075   {
00076   public:
00077     typedef typename S::Type Type;
00078   
00079     static bool contains(const Type& item)
00080     {
00081       return !S::contains(item);
00082     }
00083   };
00084   
00088   template<class TI1, class TI2, typename TA=typename TI1::Type>
00089   class Combine 
00090   {
00091   public:
00092     static bool contains(const TA& item);
00093   };
00094   
00095   template<typename TA>
00096   inline bool EmptySet<TA>::contains(const TA& attribute)
00097   {
00098     return false;
00099   }
00100 
00101   template<typename TA,int i>
00102   inline bool EnumItem<TA,i>::contains(const TA& item)
00103   {
00104     return item==i;
00105   }
00106 
00107   template<typename TA,int i>
00108   inline std::ostream& operator<<(std::ostream& os, const EnumItem<TA,i>&)
00109   {
00110     return os<<i;
00111   }
00112 
00113   template<typename TA, int from, int to>
00114   inline bool EnumRange<TA,from,to>::contains(const TA& item)
00115   {
00116     return from<=item && item<=to;
00117   }
00118   
00119   template<typename TA, int from, int to>
00120   inline std::ostream& operator<<(std::ostream& os, const EnumRange<TA,from,to>&)
00121   {
00122     return os<<"["<<from<<" - "<<to<<"]";
00123   }
00124   
00125   template<class TI1, class TI2, typename TA>
00126   inline bool Combine<TI1,TI2,TA>::contains(const TA& item)
00127   {
00128     return TI1::contains(item) ||
00129       TI2::contains(item);
00130   }
00131     
00132   template<class TI1, class TI2>
00133   inline Combine<TI1,TI2,typename TI1::Type> combine(const TI1& set1, const TI2& set2)
00134   {
00135     return Combine<TI1,TI2,typename TI1::Type>();
00136   }  
00137 
00138   template<class TI1, class TI2, class T>
00139   inline std::ostream& operator<<(std::ostream& os, const Combine<TI1,TI2,T>&)
00140   {
00141     return os << TI1()<<" "<<TI2();
00142   }
00144 }
00145 
00146 #endif

Generated on 9 Apr 2008 with Doxygen (ver 1.5.2) [logfile].